2016-08-03 10:09:49 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2020-04-25 21:34:09 +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
|
2021-02-17 13:31:44 +01:00
|
|
|
: ${ZBX_SERVER_NAME:="Zabbix docker"}
|
2016-08-03 10:09:49 +02:00
|
|
|
# Default Zabbix server port number
|
2021-02-17 13:31:44 +01: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
|
2021-02-17 13:31:44 +01:00
|
|
|
: ${PHP_TZ:="Europe/Riga"}
|
2019-04-12 12:22:41 +02:00
|
|
|
|
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
|
2021-02-17 13:31:44 +01:00
|
|
|
ZABBIX_WWW_ROOT="/usr/share/zabbix"
|
2024-02-06 09:54:37 +01:00
|
|
|
# Nginx main configuration file
|
|
|
|
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
|
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 PostgreSQL database
|
2020-04-25 21:34:09 +02:00
|
|
|
check_variables() {
|
2019-07-13 23:50:22 +02:00
|
|
|
file_env POSTGRES_USER
|
|
|
|
file_env POSTGRES_PASSWORD
|
|
|
|
|
2020-04-25 21:34:09 +02:00
|
|
|
: ${DB_SERVER_HOST:="postgres-server"}
|
|
|
|
: ${DB_SERVER_PORT:="5432"}
|
2016-08-03 10:09:49 +02:00
|
|
|
|
|
|
|
DB_SERVER_ZBX_USER=${POSTGRES_USER:-"zabbix"}
|
|
|
|
DB_SERVER_ZBX_PASS=${POSTGRES_PASSWORD:-"zabbix"}
|
|
|
|
|
2020-04-25 21:34:09 +02:00
|
|
|
: ${DB_SERVER_SCHEMA:="public"}
|
2019-04-11 18:41:44 +02:00
|
|
|
|
2020-04-25 21:34:09 +02:00
|
|
|
DB_SERVER_DBNAME=${POSTGRES_DB:-"zabbix"}
|
2021-08-05 17:59:45 +02:00
|
|
|
|
|
|
|
: ${POSTGRES_USE_IMPLICIT_SEARCH_PATH:="false"}
|
2016-08-03 10:09:49 +02:00
|
|
|
}
|
|
|
|
|
2020-04-25 21:34:09 +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}"
|
2018-06-28 08:48:31 +02:00
|
|
|
echo "* DB_SERVER_SCHEMA: ${DB_SERVER_SCHEMA}"
|
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}"
|
|
|
|
fi
|
|
|
|
echo "********************"
|
|
|
|
|
2016-08-03 10:09:49 +02:00
|
|
|
if [ -n "${DB_SERVER_ZBX_PASS}" ]; then
|
|
|
|
export PGPASSWORD="${DB_SERVER_ZBX_PASS}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
WAIT_TIMEOUT=5
|
2021-08-05 17:59:45 +02:00
|
|
|
|
|
|
|
if [ "${POSTGRES_USE_IMPLICIT_SEARCH_PATH,,}" == "false" ] && [ -n "${DB_SERVER_SCHEMA}" ]; then
|
2018-06-28 08:48:31 +02:00
|
|
|
PGOPTIONS="--search_path=${DB_SERVER_SCHEMA}"
|
|
|
|
export PGOPTIONS
|
|
|
|
fi
|
2016-08-03 10:09:49 +02:00
|
|
|
|
2020-06-23 13:50:27 +02:00
|
|
|
if [ -n "${ZBX_DBTLSCONNECT}" ]; then
|
2022-05-25 00:49:10 +02:00
|
|
|
PGSSLMODE=${ZBX_DBTLSCONNECT//_/-}
|
|
|
|
export PGSSLMODE=${PGSSLMODE//required/require}
|
2020-07-30 05:02:51 +02:00
|
|
|
export PGSSLROOTCERT=${ZBX_DBTLSCAFILE}
|
|
|
|
export PGSSLCERT=${ZBX_DBTLSCERTFILE}
|
|
|
|
export PGSSLKEY=${ZBX_DBTLSKEYFILE}
|
2020-06-23 13:50:27 +02:00
|
|
|
fi
|
|
|
|
|
2022-02-26 20:16:20 +01:00
|
|
|
while [ ! "$(psql --host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT} --username ${DB_SERVER_ZBX_USER} --dbname ${DB_SERVER_DBNAME} --list --quiet 2>/dev/null)" ]; do
|
2016-08-03 10:09:49 +02:00
|
|
|
echo "**** PostgreSQL server is not available. Waiting $WAIT_TIMEOUT seconds..."
|
|
|
|
sleep $WAIT_TIMEOUT
|
|
|
|
done
|
|
|
|
|
|
|
|
unset PGPASSWORD
|
2018-06-28 08:48:31 +02:00
|
|
|
unset PGOPTIONS
|
2020-07-30 05:02:51 +02:00
|
|
|
unset PGSSLMODE
|
|
|
|
unset PGSSLROOTCERT
|
|
|
|
unset PGSSLCERT
|
|
|
|
unset PGSSLKEY
|
2016-08-03 10:09:49 +02:00
|
|
|
}
|
|
|
|
|
2020-04-25 21:34:09 +02:00
|
|
|
prepare_web_server() {
|
2021-07-01 10:25:15 +02:00
|
|
|
NGINX_CONFD_DIR="/etc/nginx/http.d"
|
2016-08-03 10:09:49 +02:00
|
|
|
NGINX_SSL_CONFIG="/etc/ssl/nginx"
|
|
|
|
|
2022-07-20 20:53:46 +02:00
|
|
|
if [ ! -f "/proc/net/if_inet6" ]; then
|
|
|
|
sed -i '/listen \[::\]/d' "$ZABBIX_ETC_DIR/nginx.conf"
|
|
|
|
sed -i '/listen \[::\]/d' "$ZABBIX_ETC_DIR/nginx_ssl.conf"
|
|
|
|
fi
|
|
|
|
|
2016-08-03 10:09:49 +02:00
|
|
|
echo "** Adding Zabbix virtual host (HTTP)"
|
|
|
|
if [ -f "$ZABBIX_ETC_DIR/nginx.conf" ]; then
|
2021-06-07 14:41:33 +02:00
|
|
|
ln -sfT "$ZABBIX_ETC_DIR/nginx.conf" "$NGINX_CONFD_DIR/nginx.conf"
|
2016-08-03 10:09:49 +02:00
|
|
|
else
|
|
|
|
echo "**** Impossible to enable HTTP virtual host"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f "$NGINX_SSL_CONFIG/ssl.crt" ] && [ -f "$NGINX_SSL_CONFIG/ssl.key" ] && [ -f "$NGINX_SSL_CONFIG/dhparam.pem" ]; then
|
|
|
|
echo "** Enable SSL support for Nginx"
|
|
|
|
if [ -f "$ZABBIX_ETC_DIR/nginx_ssl.conf" ]; then
|
2021-06-07 14:41:33 +02:00
|
|
|
ln -sfT "$ZABBIX_ETC_DIR/nginx_ssl.conf" "$NGINX_CONFD_DIR/nginx_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 Nginx. 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"
|
|
|
|
|
2024-01-19 05:37:11 +01:00
|
|
|
PHP_CONFIG_FILE="/etc/php83/php-fpm.d/zabbix.conf"
|
2016-08-03 10:09:49 +02:00
|
|
|
|
2022-02-26 22:28:25 +01:00
|
|
|
export PHP_FPM_PM=${PHP_FPM_PM:-"dynamic"}
|
|
|
|
export PHP_FPM_PM_MAX_CHILDREN=${PHP_FPM_PM_MAX_CHILDREN:-"50"}
|
|
|
|
export PHP_FPM_PM_START_SERVERS=${PHP_FPM_PM_START_SERVERS:-"5"}
|
|
|
|
export PHP_FPM_PM_MIN_SPARE_SERVERS=${PHP_FPM_PM_MIN_SPARE_SERVERS:-"5"}
|
|
|
|
export PHP_FPM_PM_MAX_SPARE_SERVERS=${PHP_FPM_PM_MAX_SPARE_SERVERS:-"35"}
|
|
|
|
export PHP_FPM_PM_MAX_REQUESTS=${PHP_FPM_PM_MAX_REQUESTS:-"0"}
|
|
|
|
|
2020-05-28 16:16:06 +02:00
|
|
|
if [ "$(id -u)" == '0' ]; then
|
|
|
|
echo "user = zabbix" >> "$PHP_CONFIG_FILE"
|
|
|
|
echo "group = zabbix" >> "$PHP_CONFIG_FILE"
|
|
|
|
echo "listen.owner = nginx" >> "$PHP_CONFIG_FILE"
|
|
|
|
echo "listen.group = nginx" >> "$PHP_CONFIG_FILE"
|
|
|
|
fi
|
|
|
|
|
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="POSTGRESQL"
|
|
|
|
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 13:34:31 +02:00
|
|
|
: ${ZBX_DB_VERIFY_HOST:="false"}
|
|
|
|
export ZBX_DB_VERIFY_HOST=${ZBX_DB_VERIFY_HOST,,}
|
2020-09-11 09:39:21 +02:00
|
|
|
|
2023-01-22 09:11:51 +01:00
|
|
|
export ZBX_VAULT=${ZBX_VAULT}
|
2020-10-08 11:05:12 +02:00
|
|
|
export ZBX_VAULTURL=${ZBX_VAULTURL}
|
|
|
|
export ZBX_VAULTDBPATH=${ZBX_VAULTDBPATH}
|
|
|
|
export VAULT_TOKEN=${VAULT_TOKEN}
|
2023-01-22 09:11:51 +01:00
|
|
|
export ZBX_VAULTCERTFILE=${ZBX_VAULTCERTFILE}
|
|
|
|
export ZBX_VAULTKEYFILE=${ZBX_VAULTKEYFILE}
|
2020-10-08 11:05:12 +02:00
|
|
|
|
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:-"[]"}
|
2016-08-03 10:09:49 +02:00
|
|
|
|
2021-06-16 21:01:51 +02:00
|
|
|
export ZBX_SSO_SETTINGS=${ZBX_SSO_SETTINGS:-""}
|
2023-01-22 09:17:38 +01:00
|
|
|
export ZBX_SSO_SP_KEY=${ZBX_SSO_SP_KEY}
|
|
|
|
export ZBX_SSO_SP_CERT=${ZBX_SSO_SP_CERT}
|
|
|
|
export ZBX_SSO_IDP_CERT=${ZBX_SSO_IDP_CERT}
|
2021-06-16 21:01:51 +02:00
|
|
|
|
2024-04-27 14:21:44 +02:00
|
|
|
: ${ZBX_ALLOW_HTTP_AUTH:="true"}
|
|
|
|
export ZBX_ALLOW_HTTP_AUTH=${ZBX_ALLOW_HTTP_AUTH}
|
|
|
|
|
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
|
|
|
|
2020-10-14 14:49:48 +02:00
|
|
|
FCGI_READ_TIMEOUT=$(expr ${ZBX_MAXEXECUTIONTIME} + 1)
|
|
|
|
sed -i \
|
|
|
|
-e "s/{FCGI_READ_TIMEOUT}/${FCGI_READ_TIMEOUT}/g" \
|
|
|
|
"$ZABBIX_ETC_DIR/nginx.conf"
|
|
|
|
|
2024-01-20 12:40:13 +01:00
|
|
|
: ${HTTP_INDEX_FILE:="index.php"}
|
|
|
|
sed -i \
|
|
|
|
-e "s/{HTTP_INDEX_FILE}/${HTTP_INDEX_FILE}/g" \
|
|
|
|
"$ZABBIX_ETC_DIR/nginx.conf"
|
|
|
|
|
2020-10-14 14:49:48 +02:00
|
|
|
if [ -f "$ZABBIX_ETC_DIR/nginx_ssl.conf" ]; then
|
|
|
|
sed -i \
|
|
|
|
-e "s/{FCGI_READ_TIMEOUT}/${FCGI_READ_TIMEOUT}/g" \
|
|
|
|
"$ZABBIX_ETC_DIR/nginx_ssl.conf"
|
2024-01-20 12:40:13 +01:00
|
|
|
|
|
|
|
sed -i \
|
|
|
|
-e "s/{HTTP_INDEX_FILE}/${HTTP_INDEX_FILE}/g" \
|
|
|
|
"$ZABBIX_ETC_DIR/nginx_ssl.conf"
|
2020-10-14 14:49:48 +02:00
|
|
|
fi
|
|
|
|
|
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*access_log).+\;!\1 off\;!g' \
|
2024-02-06 09:54:37 +01:00
|
|
|
"$NGINX_CONF_FILE"
|
2020-06-28 17:54:33 +02:00
|
|
|
sed -ri \
|
|
|
|
-e 's!^(\s*access_log).+\;!\1 off\;!g' \
|
2024-02-06 09:54:37 +01:00
|
|
|
"$ZABBIX_ETC_DIR/nginx.conf"
|
2020-06-28 17:54:33 +02:00
|
|
|
sed -ri \
|
|
|
|
-e 's!^(\s*access_log).+\;!\1 off\;!g' \
|
2024-02-06 09:54:37 +01:00
|
|
|
"$ZABBIX_ETC_DIR/nginx_ssl.conf"
|
2020-06-28 17:54:33 +02:00
|
|
|
fi
|
2024-02-06 09:54:37 +01:00
|
|
|
|
|
|
|
: ${EXPOSE_WEB_SERVER_INFO:="on"}
|
|
|
|
|
|
|
|
[[ "${EXPOSE_WEB_SERVER_INFO}" != "off" ]] && EXPOSE_WEB_SERVER_INFO="on"
|
|
|
|
|
|
|
|
export EXPOSE_WEB_SERVER_INFO=${EXPOSE_WEB_SERVER_INFO}
|
|
|
|
sed -i \
|
|
|
|
-e "s/{EXPOSE_WEB_SERVER_INFO}/${EXPOSE_WEB_SERVER_INFO}/g" \
|
|
|
|
"$NGINX_CONF_FILE"
|
2016-08-03 10:09:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#################################################
|
|
|
|
|
2020-04-25 21:34:09 +02:00
|
|
|
echo "** Deploying Zabbix web-interface (Nginx) with PostgreSQL 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 "$@"
|
|
|
|
elif [ -f "/usr/bin/supervisord" ]; then
|
|
|
|
echo "** Executing supervisord"
|
|
|
|
exec /usr/bin/supervisord -c /etc/supervisor/supervisord.conf
|
|
|
|
else
|
|
|
|
echo "Unknown instructions. Exiting..."
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-08-03 10:09:49 +02:00
|
|
|
|
|
|
|
#################################################
|