This commit is contained in:
2023-04-16 21:38:32 +08:00
parent a0849e40ef
commit 0b6c876a0f
59 changed files with 1026 additions and 189 deletions

View File

@@ -12,6 +12,8 @@
# - /var/log/nginx #
# - /var/log/php7 #
# - /var/log/zabbix #
# ENV #
# - GLOBAL_DIERECTIVES #
##################################################
set -euo pipefail
@@ -26,6 +28,7 @@ BINLOG_DIR='/var/lib/mysql-bin'
INIT_FLAG=${INIT_FLAG:-}
SOCK_FILE='/run/mysqld/mysqld.sock'
PID_FILE='/run/mysqld/mysqld.pid'
GLOBAL_DIRECTIVES="${GLOBAL_DIRECTIVES:-user nginx;worker_processes auto;}"
function Print {
local file=/dev/null
@@ -49,14 +52,14 @@ function Quit {
}
function RestoreConf {
! ls /etc/nginx/conf.d/*.conf 2>/dev/null | grep -Eq '(zabbix|zbx)' \
&& Print Restore /etc/nginx/conf.d/zabbix.conf ... \
&& cp /usr/share/zabbix/nginx.conf /etc/nginx/conf.d/zabbix.conf
! ls /etc/nginx/http.d/*.conf 2>/dev/null | grep -Eq '(zabbix|zbx)' \
&& Print Restoring /etc/nginx/http.d/zabbix.conf ... \
&& cp /usr/share/zabbix/nginx.conf /etc/nginx/http.d/zabbix.conf
[ ! -e /etc/zabbix/zabbix_proxy.conf ] \
&& Print Restore /etc/zabbix/zabbix_proxy.conf ... \
&& Print Restoring /etc/zabbix/zabbix_proxy.conf ... \
&& cp /usr/share/zabbix/zabbix_proxy.conf /etc/zabbix/zabbix_proxy.conf
[ ! -e /etc/zabbix/zabbix_server.conf ] \
&& Print Restore /etc/zabbix/zabbix_server.conf ... \
&& Print Restoring /etc/zabbix/zabbix_server.conf ... \
&& cp /usr/share/zabbix/zabbix_server.conf /etc/zabbix/zabbix_server.conf
return 0
}
@@ -77,23 +80,23 @@ function SideCar {
&& [ "$md5" != "$last_md5" ] \
&& last_md5=$md5 \
&& nginx -tq \
&& Print Reload nginx conf ... \
&& Print Reloading nginx conf ... \
&& nginx -s reload
done
}
function InitDB {
rm -f $SOCK_FILE $PID_FILE
chown -R mysql.mysql $LOG_DIR $BINLOG_DIR $DATA_DIR
chown -R mysql:mysql $LOG_DIR $BINLOG_DIR $DATA_DIR
if [ ! -d "$DATA_DIR/mysql" ]; then
Print Install database ...
Print Installing database ...
mysql_install_db --user=mysql > /dev/null
INIT_FLAG=1
fi
}
function StartProc {
Print Start mysql ...
Print Starting mysql ...
mysqld -u mysql &
PIDS="$PIDS $!"
while sleep 1; do
@@ -102,20 +105,24 @@ function StartProc {
done
echo
if [ -n "$INIT_FLAG" ]; then
Print Secure database ...
Print Securing database ...
mysql_secure_installation <<< "$(echo -e '\nn\nn\n\n\n\n\n')" > /dev/null
Print Create zabbix db and user ...
Print Creating zabbix db and user ...
mysql -e "CREATE DATABASE zabbix DEFAULT CHARSET UTF8 COLLATE UTF8_BIN"
mysql -e "CREATE USER zabbix@localhost"
mysql -e "GRANT ALL ON zabbix.* TO zabbix@localhost"
Print Import zabbix schema.sql ...
Print Importing zabbix schema.sql ...
mysql -Dzabbix < /usr/share/zabbix/database/mysql/schema.sql
Print Import zabbix images.sql ...
Print Importing zabbix images.sql ...
mysql -Dzabbix < /usr/share/zabbix/database/mysql/images.sql
Print Import zabbix data.sql ...
Print Importing zabbix history_pk_prepare.sql ...
mysql -Dzabbix < /usr/share/zabbix/database/mysql/history_pk_prepare.sql
Print Importing zabbix double.sql ...
mysql -Dzabbix < /usr/share/zabbix/database/mysql/double.sql
Print Importing zabbix data.sql ...
mysql -Dzabbix < /usr/share/zabbix/database/mysql/data.sql
if sql_files="$(ls $DATA_DIR/init_sql/*.sql 2>/dev/null)"; then
Print Import the sql files ...
Print Importing the sql files ...
for sql_file in $sql_files; do
Print Importing $sql_file ...
mysql < $sql_file
@@ -127,21 +134,23 @@ function StartProc {
RestoreConf
Print Start php ...
php-fpm7 -F -y /etc/php7/php-fpm.conf &
Print Starting php ...
php-fpm81 -F -y /etc/php81/php-fpm.conf &
PIDS="$PIDS $!"
Print Start zabbix ...
Print Starting zabbix ...
zabbix_server -f &
PIDS="$PIDS $!"
Print Start nginx ...
nginx -g 'daemon off;pid /run/nginx/nginx.pid;' &
Print Starting nginx ...
nginx -g "$GLOBAL_DIRECTIVES" &
PIDS="$PIDS $!"
Print Start nginx sidecar ...
Print Starting nginx sidecar ...
SideCar &
PIDS="$PIDS $!"
Print All components started.
}
function Main {