2018-02-18 21:45:33 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2020-04-26 20:54:12 +02:00
|
|
|
set -o pipefail
|
2018-02-18 21:45:33 +01:00
|
|
|
|
|
|
|
set +e
|
|
|
|
|
|
|
|
# Script trace mode
|
|
|
|
if [ "${DEBUG_MODE}" == "true" ]; then
|
|
|
|
set -o xtrace
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Default Zabbix installation name
|
|
|
|
# Used only by Zabbix web-interface
|
2020-04-26 20:54:12 +02:00
|
|
|
: ${ZBX_SERVER_NAME:="Zabbix docker"}
|
2018-02-18 21:45:33 +01:00
|
|
|
# Default Zabbix server host
|
2020-04-26 20:54:12 +02:00
|
|
|
: ${ZBX_SERVER_HOST:="zabbix-server"}
|
2018-02-18 21:45:33 +01:00
|
|
|
# Default Zabbix server port number
|
2020-04-26 20:54:12 +02:00
|
|
|
: ${ZBX_SERVER_PORT:="10051"}
|
2018-02-18 21:45:33 +01:00
|
|
|
|
|
|
|
# Default timezone for web interface
|
2020-04-26 20:54:12 +02:00
|
|
|
: ${PHP_TZ:="Europe/Riga"}
|
2018-02-18 21:45:33 +01:00
|
|
|
|
2019-04-12 12:22:41 +02:00
|
|
|
#Enable PostgreSQL timescaleDB feature:
|
|
|
|
ENABLE_TIMESCALEDB=${ENABLE_TIMESCALEDB:-"false"}
|
|
|
|
|
2018-02-18 21:45:33 +01:00
|
|
|
# Default directories
|
|
|
|
# Configuration files directory
|
|
|
|
ZABBIX_ETC_DIR="/etc/zabbix"
|
|
|
|
# Web interface www-root directory
|
2020-04-26 20:54:12 +02:00
|
|
|
ZABBIX_WWW_ROOT="/usr/share/zabbix"
|
2018-02-18 21:45:33 +01: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"
|
|
|
|
}
|
|
|
|
|
2018-02-18 21:45:33 +01:00
|
|
|
# Check prerequisites for PostgreSQL database
|
2020-04-26 20:54:12 +02:00
|
|
|
check_variables() {
|
2019-07-13 23:50:22 +02:00
|
|
|
file_env POSTGRES_USER
|
|
|
|
file_env POSTGRES_PASSWORD
|
|
|
|
|
2020-04-26 20:54:12 +02:00
|
|
|
: ${DB_SERVER_HOST:="postgres-server"}
|
|
|
|
: ${DB_SERVER_PORT:="5432"}
|
|
|
|
: ${CREATE_ZBX_DB_USER:="false"}
|
2018-02-18 21:45:33 +01:00
|
|
|
|
|
|
|
DB_SERVER_ROOT_USER=${POSTGRES_USER:-"postgres"}
|
|
|
|
DB_SERVER_ROOT_PASS=${POSTGRES_PASSWORD:-""}
|
|
|
|
|
|
|
|
DB_SERVER_ZBX_USER=${POSTGRES_USER:-"zabbix"}
|
|
|
|
DB_SERVER_ZBX_PASS=${POSTGRES_PASSWORD:-"zabbix"}
|
|
|
|
|
2020-04-26 20:54:12 +02:00
|
|
|
: ${DB_SERVER_SCHEMA:="public"}
|
2018-02-18 21:45:33 +01:00
|
|
|
|
2020-04-26 20:54:12 +02:00
|
|
|
DB_SERVER_DBNAME=${POSTGRES_DB:-"zabbix"}
|
2018-02-18 21:45:33 +01:00
|
|
|
}
|
|
|
|
|
2020-04-26 20:54:12 +02:00
|
|
|
check_db_connect() {
|
2018-02-18 21:45:33 +01: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}"
|
2019-10-31 23:17:26 +01:00
|
|
|
if [ "${DEBUG_MODE}" == "true" ]; then
|
|
|
|
if [ "${USE_DB_ROOT_USER}" == "true" ]; then
|
|
|
|
echo "* DB_SERVER_ROOT_USER: ${DB_SERVER_ROOT_USER}"
|
|
|
|
echo "* DB_SERVER_ROOT_PASS: ${DB_SERVER_ROOT_PASS}"
|
|
|
|
fi
|
|
|
|
echo "* DB_SERVER_ZBX_USER: ${DB_SERVER_ZBX_USER}"
|
|
|
|
echo "* DB_SERVER_ZBX_PASS: ${DB_SERVER_ZBX_PASS}"
|
|
|
|
fi
|
|
|
|
echo "********************"
|
|
|
|
|
|
|
|
if [ "${USE_DB_ROOT_USER}" != "true" ]; then
|
2018-02-18 21:45:33 +01:00
|
|
|
DB_SERVER_ROOT_USER=${DB_SERVER_ZBX_USER}
|
|
|
|
DB_SERVER_ROOT_PASS=${DB_SERVER_ZBX_PASS}
|
|
|
|
fi
|
2019-10-31 23:17:26 +01:00
|
|
|
|
2018-02-18 21:45:33 +01:00
|
|
|
if [ -n "${DB_SERVER_ZBX_PASS}" ]; then
|
|
|
|
export PGPASSWORD="${DB_SERVER_ZBX_PASS}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
WAIT_TIMEOUT=5
|
2020-04-28 16:21:46 +02:00
|
|
|
|
2018-06-28 08:48:31 +02:00
|
|
|
if [ -n "${DB_SERVER_SCHEMA}" ]; then
|
|
|
|
PGOPTIONS="--search_path=${DB_SERVER_SCHEMA}"
|
|
|
|
export PGOPTIONS
|
|
|
|
fi
|
2018-02-18 21:45:33 +01:00
|
|
|
|
2020-04-28 16:21:46 +02:00
|
|
|
if [ -n "${ZBX_DBTLSCONNECT}" ]; then
|
2020-07-30 05:02:51 +02:00
|
|
|
export PGSSLMODE=${ZBX_DBTLSCONNECT//_/-}
|
|
|
|
export PGSSLROOTCERT=${ZBX_DBTLSCAFILE}
|
|
|
|
export PGSSLCERT=${ZBX_DBTLSCERTFILE}
|
|
|
|
export PGSSLKEY=${ZBX_DBTLSKEYFILE}
|
2020-04-28 16:21:46 +02:00
|
|
|
fi
|
|
|
|
|
2020-07-30 05:02:51 +02:00
|
|
|
while [ ! "$(psql --host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT} --username ${DB_SERVER_ROOT_USER} --dbname ${DB_SERVER_DBNAME} --list --quiet 2>/dev/null)" ]; do
|
2018-02-18 21:45:33 +01: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
|
2018-02-18 21:45:33 +01:00
|
|
|
}
|
|
|
|
|
2020-04-26 20:54:12 +02:00
|
|
|
prepare_web_server() {
|
|
|
|
APACHE_SITES_DIR=/etc/httpd/conf.d
|
2018-02-18 21:45:33 +01:00
|
|
|
|
|
|
|
echo "** Adding Zabbix virtual host (HTTP)"
|
|
|
|
if [ -f "$ZABBIX_ETC_DIR/apache.conf" ]; then
|
|
|
|
ln -s "$ZABBIX_ETC_DIR/apache.conf" "$APACHE_SITES_DIR/zabbix.conf"
|
|
|
|
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
|
|
|
|
ln -s "$ZABBIX_ETC_DIR/apache_ssl.conf" "$APACHE_SITES_DIR/zabbix_ssl.conf"
|
|
|
|
else
|
|
|
|
echo "**** Impossible to enable HTTPS virtual host"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "**** Impossible to enable SSL support for Apache2. Certificates are missed."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
prepare_zbx_web_config() {
|
|
|
|
echo "** Preparing Zabbix frontend configuration file"
|
|
|
|
|
2020-04-27 21:46:25 +02:00
|
|
|
PHP_CONFIG_FILE="/etc/php-fpm.d/zabbix.conf"
|
2018-02-18 21:45:33 +01:00
|
|
|
|
2020-07-23 17:35:09 +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
|
|
|
|
|
2020-09-11 11:01:22 +02:00
|
|
|
export ZBX_DENY_GUI_ACCESS=${ZBX_DENY_GUI_ACCESS:-"false"}
|
|
|
|
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"}
|
|
|
|
export PHP_TZ=${PHP_TZ:-"Europe/Riga"}
|
|
|
|
|
|
|
|
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}
|
|
|
|
export ZBX_SERVER_PORT=${ZBX_SERVER_PORT:-"10051"}
|
|
|
|
export ZBX_SERVER_NAME=${ZBX_SERVER_NAME}
|
2020-06-28 17:54:33 +02:00
|
|
|
|
2020-09-11 09:39:21 +02:00
|
|
|
export ZBX_DB_ENCRYPTION=${ZBX_DB_ENCRYPTION:-"false"}
|
|
|
|
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}
|
|
|
|
export ZBX_DB_VERIFY_HOST=${ZBX_DB_VERIFY_HOST-"false"}
|
|
|
|
|
|
|
|
export DB_DOUBLE_IEEE754=${DB_DOUBLE_IEEE754:-"true"}
|
|
|
|
|
|
|
|
export ZBX_HISTORYSTORAGEURL=${ZBX_HISTORYSTORAGEURL}
|
|
|
|
export ZBX_HISTORYSTORAGETYPES=${ZBX_HISTORYSTORAGETYPES:-"[]"}
|
|
|
|
|
|
|
|
export ZBX_SSO_SETTINGS=${ZBX_SSO_SETTINGS:-""}
|
2018-02-18 21:45:33 +01:00
|
|
|
|
2020-05-01 18:33:55 +02:00
|
|
|
if [ -n "${ZBX_SESSION_NAME}" ]; then
|
|
|
|
cp "$ZBX_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" > "$ZBX_WWW_ROOT/include/defines.inc.php"
|
|
|
|
rm -f "/tmp/defines.inc.php_tmp"
|
|
|
|
fi
|
2020-06-28 19:40:16 +02:00
|
|
|
|
2020-06-28 17:54:33 +02:00
|
|
|
if [ "${ENABLE_WEB_ACCESS_LOG:-"true"}" == "false" ]; then
|
|
|
|
sed -ri \
|
|
|
|
-e 's!^(\s*CustomLog)\s+\S+!\1 /dev/null!g' \
|
|
|
|
"/etc/httpd/conf/httpd.conf"
|
|
|
|
fi
|
2018-02-18 21:45:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#################################################
|
|
|
|
|
2020-06-23 16:01:42 +02:00
|
|
|
echo "** Deploying Zabbix web-interface (Apache) with PostgreSQL database"
|
2018-02-18 21:45:33 +01:00
|
|
|
|
2020-05-13 23:12:56 +02:00
|
|
|
check_variables
|
|
|
|
check_db_connect
|
|
|
|
prepare_web_server
|
|
|
|
prepare_zbx_web_config
|
2018-02-18 21:45:33 +01:00
|
|
|
|
|
|
|
echo "########################################################"
|
|
|
|
|
2018-02-22 21:07:15 +01:00
|
|
|
if [ "$1" != "" ]; then
|
|
|
|
echo "** Executing '$@'"
|
|
|
|
exec "$@"
|
2020-04-27 21:46:25 +02:00
|
|
|
elif [ -f "/usr/bin/supervisord" ]; then
|
|
|
|
echo "** Executing supervisord"
|
|
|
|
exec /usr/bin/supervisord -c /etc/supervisor/supervisord.conf
|
2018-02-22 21:07:15 +01:00
|
|
|
else
|
|
|
|
echo "Unknown instructions. Exiting..."
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-02-18 21:45:33 +01:00
|
|
|
|
|
|
|
#################################################
|