2016-08-03 10:09:49 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2020-04-28 18:39:39 +02:00
|
|
|
set -o pipefail
|
2018-02-18 21:42:44 +01:00
|
|
|
|
2016-08-03 10:09:49 +02:00
|
|
|
set +e
|
2016-08-04 07:09:11 +02:00
|
|
|
|
2016-08-11 12:55:45 +02:00
|
|
|
# Script trace mode
|
2021-04-12 03:43:41 +02:00
|
|
|
if [ "${DEBUG_MODE,,}" == "true" ]; then
|
2016-08-04 07:09:11 +02:00
|
|
|
set -o xtrace
|
|
|
|
fi
|
2016-08-03 10:09:49 +02:00
|
|
|
|
|
|
|
# Default Zabbix installation name
|
|
|
|
# Used only by Zabbix web-interface
|
2020-04-28 18:39:39 +02:00
|
|
|
: ${ZBX_SERVER_NAME:="Zabbix docker"}
|
2016-08-03 10:09:49 +02:00
|
|
|
# Default Zabbix server port number
|
2020-04-28 18:39:39 +02:00
|
|
|
: ${ZBX_SERVER_PORT:="10051"}
|
2016-08-03 10:09:49 +02:00
|
|
|
|
2016-08-11 12:55:45 +02:00
|
|
|
# Default timezone for web interface
|
2020-04-28 18:39:39 +02:00
|
|
|
: ${PHP_TZ:="Europe/Riga"}
|
2016-08-03 10:09:49 +02:00
|
|
|
|
|
|
|
# Default directories
|
2016-08-11 12:55:45 +02:00
|
|
|
# Configuration files directory
|
2016-08-03 10:09:49 +02:00
|
|
|
ZABBIX_ETC_DIR="/etc/zabbix"
|
2016-08-11 12:55:45 +02:00
|
|
|
# Web interface www-root directory
|
2020-04-28 18:39:39 +02:00
|
|
|
ZABBIX_WWW_ROOT="/usr/share/zabbix"
|
2016-08-03 10:09:49 +02:00
|
|
|
|
2019-07-13 23:50:22 +02:00
|
|
|
# usage: file_env VAR [DEFAULT]
|
|
|
|
# as example: file_env 'MYSQL_PASSWORD' 'zabbix'
|
|
|
|
# (will allow for "$MYSQL_PASSWORD_FILE" to fill in the value of "$MYSQL_PASSWORD" from a file)
|
|
|
|
# unsets the VAR_FILE afterwards and just leaving VAR
|
|
|
|
file_env() {
|
|
|
|
local var="$1"
|
|
|
|
local fileVar="${var}_FILE"
|
|
|
|
local defaultValue="${2:-}"
|
|
|
|
|
|
|
|
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
|
|
|
|
echo "**** Both variables $var and $fileVar are set (but are exclusive)"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
local val="$defaultValue"
|
|
|
|
|
|
|
|
if [ "${!var:-}" ]; then
|
|
|
|
val="${!var}"
|
|
|
|
echo "** Using ${var} variable from ENV"
|
|
|
|
elif [ "${!fileVar:-}" ]; then
|
|
|
|
if [ ! -f "${!fileVar}" ]; then
|
|
|
|
echo "**** Secret file \"${!fileVar}\" is not found"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
val="$(< "${!fileVar}")"
|
|
|
|
echo "** Using ${var} variable from secret file"
|
|
|
|
fi
|
|
|
|
export "$var"="$val"
|
|
|
|
unset "$fileVar"
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:55:45 +02:00
|
|
|
# Check prerequisites for MySQL database
|
2020-04-28 18:39:39 +02:00
|
|
|
check_variables() {
|
|
|
|
: ${DB_SERVER_HOST:="mysql-server"}
|
|
|
|
: ${DB_SERVER_PORT:="3306"}
|
2022-02-26 20:16:20 +01:00
|
|
|
|
2019-07-13 23:50:22 +02:00
|
|
|
file_env MYSQL_USER
|
|
|
|
file_env MYSQL_PASSWORD
|
|
|
|
|
2016-08-03 10:09:49 +02:00
|
|
|
DB_SERVER_ZBX_USER=${MYSQL_USER:-"zabbix"}
|
|
|
|
DB_SERVER_ZBX_PASS=${MYSQL_PASSWORD:-"zabbix"}
|
|
|
|
|
2020-04-28 18:39:39 +02:00
|
|
|
DB_SERVER_DBNAME=${MYSQL_DATABASE:-"zabbix"}
|
2016-08-03 10:09:49 +02:00
|
|
|
}
|
|
|
|
|
2020-08-27 18:58:54 +02:00
|
|
|
db_tls_params() {
|
|
|
|
local result=""
|
|
|
|
|
2021-04-13 14:16:43 +02:00
|
|
|
if [ "${ZBX_DB_ENCRYPTION,,}" == "true" ]; then
|
2020-08-27 18:58:54 +02:00
|
|
|
result="--ssl-mode=required"
|
|
|
|
|
|
|
|
if [ -n "${ZBX_DB_CA_FILE}" ]; then
|
|
|
|
result="${result} --ssl-ca=${ZBX_DB_CA_FILE}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "${ZBX_DB_KEY_FILE}" ]; then
|
|
|
|
result="${result} --ssl-key=${ZBX_DB_KEY_FILE}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "${ZBX_DB_CERT_FILE}" ]; then
|
|
|
|
result="${result} --ssl-cert=${ZBX_DB_CERT_FILE}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo $result
|
|
|
|
}
|
|
|
|
|
2020-04-28 18:39:39 +02:00
|
|
|
check_db_connect() {
|
2016-08-03 10:09:49 +02:00
|
|
|
echo "********************"
|
|
|
|
echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}"
|
|
|
|
echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}"
|
|
|
|
echo "* DB_SERVER_DBNAME: ${DB_SERVER_DBNAME}"
|
2021-04-12 03:43:41 +02:00
|
|
|
if [ "${DEBUG_MODE,,}" == "true" ]; then
|
2019-10-31 23:17:26 +01:00
|
|
|
echo "* DB_SERVER_ZBX_USER: ${DB_SERVER_ZBX_USER}"
|
|
|
|
echo "* DB_SERVER_ZBX_PASS: ${DB_SERVER_ZBX_PASS}"
|
2016-08-03 10:09:49 +02:00
|
|
|
fi
|
|
|
|
echo "********************"
|
|
|
|
|
|
|
|
WAIT_TIMEOUT=5
|
|
|
|
|
2020-08-27 18:58:54 +02:00
|
|
|
ssl_opts="$(db_tls_params)"
|
2020-08-25 13:38:13 +02:00
|
|
|
|
2022-02-26 20:16:20 +01:00
|
|
|
export MYSQL_PWD="${DB_SERVER_ZBX_PASS}"
|
2020-09-08 21:40:14 +02:00
|
|
|
|
2022-02-26 20:16:20 +01:00
|
|
|
while [ ! "$(mysqladmin ping -h ${DB_SERVER_HOST} -P ${DB_SERVER_PORT} -u ${DB_SERVER_ZBX_USER} \
|
2020-09-08 23:41:01 +02:00
|
|
|
--silent --connect_timeout=10 $ssl_opts)" ]; do
|
2016-08-03 10:09:49 +02:00
|
|
|
echo "**** MySQL server is not available. Waiting $WAIT_TIMEOUT seconds..."
|
|
|
|
sleep $WAIT_TIMEOUT
|
|
|
|
done
|
2020-09-08 21:40:14 +02:00
|
|
|
|
|
|
|
unset MYSQL_PWD
|
2016-08-03 10:09:49 +02:00
|
|
|
}
|
|
|
|
|
2020-04-28 18:39:39 +02:00
|
|
|
prepare_web_server() {
|
2020-04-28 20:22:44 +02:00
|
|
|
APACHE_SITES_DIR="/etc/apache2/sites-enabled"
|
2016-08-03 10:09:49 +02:00
|
|
|
|
|
|
|
echo "** Adding Zabbix virtual host (HTTP)"
|
|
|
|
if [ -f "$ZABBIX_ETC_DIR/apache.conf" ]; then
|
2021-06-07 14:41:33 +02:00
|
|
|
ln -sfT "$ZABBIX_ETC_DIR/apache.conf" "$APACHE_SITES_DIR/zabbix.conf"
|
2016-08-03 10:09:49 +02:00
|
|
|
else
|
|
|
|
echo "**** Impossible to enable HTTP virtual host"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f "/etc/ssl/apache2/ssl.crt" ] && [ -f "/etc/ssl/apache2/ssl.key" ]; then
|
|
|
|
echo "** Adding Zabbix virtual host (HTTPS)"
|
|
|
|
if [ -f "$ZABBIX_ETC_DIR/apache_ssl.conf" ]; then
|
2021-06-07 14:41:33 +02:00
|
|
|
ln -sfT "$ZABBIX_ETC_DIR/apache_ssl.conf" "$APACHE_SITES_DIR/zabbix_ssl.conf"
|
2016-08-03 10:09:49 +02:00
|
|
|
else
|
|
|
|
echo "**** Impossible to enable HTTPS virtual host"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "**** Impossible to enable SSL support for Apache2. Certificates are missed."
|
|
|
|
fi
|
2018-03-29 15:28:10 +02:00
|
|
|
}
|
|
|
|
|
2016-08-03 10:09:49 +02:00
|
|
|
prepare_zbx_web_config() {
|
|
|
|
echo "** Preparing Zabbix frontend configuration file"
|
|
|
|
|
2021-04-13 13:09:40 +02:00
|
|
|
: ${ZBX_DENY_GUI_ACCESS:="false"}
|
|
|
|
export ZBX_DENY_GUI_ACCESS=${ZBX_DENY_GUI_ACCESS,,}
|
2020-09-11 11:01:22 +02:00
|
|
|
export ZBX_GUI_ACCESS_IP_RANGE=${ZBX_GUI_ACCESS_IP_RANGE:-"['127.0.0.1']"}
|
|
|
|
export ZBX_GUI_WARNING_MSG=${ZBX_GUI_WARNING_MSG:-"Zabbix is under maintenance."}
|
|
|
|
|
2020-09-10 14:05:17 +02:00
|
|
|
export ZBX_MAXEXECUTIONTIME=${ZBX_MAXEXECUTIONTIME:-"600"}
|
|
|
|
export ZBX_MEMORYLIMIT=${ZBX_MEMORYLIMIT:-"128M"}
|
|
|
|
export ZBX_POSTMAXSIZE=${ZBX_POSTMAXSIZE:-"16M"}
|
|
|
|
export ZBX_UPLOADMAXFILESIZE=${ZBX_UPLOADMAXFILESIZE:-"2M"}
|
|
|
|
export ZBX_MAXINPUTTIME=${ZBX_MAXINPUTTIME:-"300"}
|
2020-10-08 15:29:10 +02:00
|
|
|
export PHP_TZ=${PHP_TZ}
|
2020-09-10 14:05:17 +02:00
|
|
|
|
|
|
|
export DB_SERVER_TYPE="MYSQL"
|
|
|
|
export DB_SERVER_HOST=${DB_SERVER_HOST}
|
|
|
|
export DB_SERVER_PORT=${DB_SERVER_PORT}
|
|
|
|
export DB_SERVER_DBNAME=${DB_SERVER_DBNAME}
|
|
|
|
export DB_SERVER_SCHEMA=${DB_SERVER_SCHEMA}
|
|
|
|
export DB_SERVER_USER=${DB_SERVER_ZBX_USER}
|
|
|
|
export DB_SERVER_PASS=${DB_SERVER_ZBX_PASS}
|
|
|
|
export ZBX_SERVER_HOST=${ZBX_SERVER_HOST}
|
2021-11-17 01:45:24 +01:00
|
|
|
export ZBX_SERVER_PORT=${ZBX_SERVER_PORT}
|
2020-09-10 14:05:17 +02:00
|
|
|
export ZBX_SERVER_NAME=${ZBX_SERVER_NAME}
|
2020-06-28 17:54:33 +02:00
|
|
|
|
2021-04-13 13:34:31 +02:00
|
|
|
: ${ZBX_DB_ENCRYPTION:="false"}
|
|
|
|
export ZBX_DB_ENCRYPTION=${ZBX_DB_ENCRYPTION,,}
|
2020-09-11 09:39:21 +02:00
|
|
|
export ZBX_DB_KEY_FILE=${ZBX_DB_KEY_FILE}
|
|
|
|
export ZBX_DB_CERT_FILE=${ZBX_DB_CERT_FILE}
|
|
|
|
export ZBX_DB_CA_FILE=${ZBX_DB_CA_FILE}
|
2021-04-13 14:16:43 +02:00
|
|
|
: ${ZBX_DB_VERIFY_HOST:="false"}
|
2021-04-13 13:34:31 +02:00
|
|
|
export ZBX_DB_VERIFY_HOST=${ZBX_DB_VERIFY_HOST,,}
|
2020-09-11 09:39:21 +02:00
|
|
|
|
2020-10-08 11:05:12 +02:00
|
|
|
export ZBX_VAULTURL=${ZBX_VAULTURL}
|
|
|
|
export ZBX_VAULTDBPATH=${ZBX_VAULTDBPATH}
|
|
|
|
export VAULT_TOKEN=${VAULT_TOKEN}
|
|
|
|
|
2021-04-13 13:34:31 +02:00
|
|
|
: ${DB_DOUBLE_IEEE754:="true"}
|
|
|
|
export DB_DOUBLE_IEEE754=${DB_DOUBLE_IEEE754,,}
|
2020-09-11 09:39:21 +02:00
|
|
|
|
|
|
|
export ZBX_HISTORYSTORAGEURL=${ZBX_HISTORYSTORAGEURL}
|
|
|
|
export ZBX_HISTORYSTORAGETYPES=${ZBX_HISTORYSTORAGETYPES:-"[]"}
|
|
|
|
|
|
|
|
export ZBX_SSO_SETTINGS=${ZBX_SSO_SETTINGS:-""}
|
2016-08-03 10:09:49 +02:00
|
|
|
|
2020-05-01 18:33:55 +02:00
|
|
|
if [ -n "${ZBX_SESSION_NAME}" ]; then
|
2021-02-17 14:37:07 +01:00
|
|
|
cp "$ZABBIX_WWW_ROOT/include/defines.inc.php" "/tmp/defines.inc.php_tmp"
|
|
|
|
sed "/ZBX_SESSION_NAME/s/'[^']*'/'${ZBX_SESSION_NAME}'/2" "/tmp/defines.inc.php_tmp" > "$ZABBIX_WWW_ROOT/include/defines.inc.php"
|
2020-05-01 18:33:55 +02:00
|
|
|
rm -f "/tmp/defines.inc.php_tmp"
|
|
|
|
fi
|
2020-06-28 19:40:16 +02:00
|
|
|
|
2021-04-13 13:09:40 +02:00
|
|
|
: ${ENABLE_WEB_ACCESS_LOG:="true"}
|
2021-04-12 03:43:41 +02:00
|
|
|
|
|
|
|
if [ "${ENABLE_WEB_ACCESS_LOG,,}" == "false" ]; then
|
2020-06-28 17:54:33 +02:00
|
|
|
sed -ri \
|
|
|
|
-e 's!^(\s*CustomLog)\s+\S+!\1 /dev/null!g' \
|
|
|
|
"/etc/apache2/apache2.conf"
|
|
|
|
sed -ri \
|
|
|
|
-e 's!^(\s*CustomLog)\s+\S+!\1 /dev/null!g' \
|
|
|
|
"/etc/apache2/conf-available/other-vhosts-access-log.conf"
|
|
|
|
fi
|
2016-08-03 10:09:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#################################################
|
|
|
|
|
2020-04-28 18:39:39 +02:00
|
|
|
echo "** Deploying Zabbix web-interface (Apache) with MySQL database"
|
2016-08-03 10:09:49 +02:00
|
|
|
|
2020-05-13 23:12:56 +02:00
|
|
|
check_variables
|
|
|
|
check_db_connect
|
|
|
|
prepare_web_server
|
|
|
|
prepare_zbx_web_config
|
2016-08-03 10:09:49 +02:00
|
|
|
|
|
|
|
echo "########################################################"
|
|
|
|
|
2018-02-22 21:07:15 +01:00
|
|
|
if [ "$1" != "" ]; then
|
|
|
|
echo "** Executing '$@'"
|
|
|
|
exec "$@"
|
2020-04-28 18:39:39 +02:00
|
|
|
elif [ -f "/usr/sbin/httpd" ]; then
|
|
|
|
echo "** Executing HTTPD"
|
|
|
|
exec /usr/sbin/httpd -D FOREGROUND
|
2018-02-22 21:07:15 +01:00
|
|
|
else
|
|
|
|
echo "Unknown instructions. Exiting..."
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-08-03 10:09:49 +02:00
|
|
|
|
|
|
|
#################################################
|