-
Notifications
You must be signed in to change notification settings - Fork 7
/
entrypoint.sh
executable file
·61 lines (54 loc) · 1.7 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
set -e
# start and configure mysql
echo "==> Starting MySQL..."
# touch required on overlay2: https://github.com/docker/for-linux/issues/72#issuecomment-319904698
find /var/lib/mysql -type f -exec touch {} \;
/etc/init.d/mysql start
echo "==> Creating Zabbix database..."
eval $(grep ^DBPassword /etc/zabbix/zabbix_server.conf)
mysql -v <<SQL
CREATE DATABASE zabbix CHARACTER SET UTF8 COLLATE UTF8_BIN;
CREATE USER zabbix@localhost IDENTIFIED BY '${DBPassword}';
GRANT ALL PRIVILEGES ON zabbix.* TO zabbix@localhost;
FLUSH PRIVILEGES;
SQL
sed -i -e "s/DBPassword/${DBPassword}/g" \
/etc/zabbix/web/zabbix.conf.php
echo "==> Initializing Zabbix database..."
if [[ -f "/usr/share/dbconfig-common/data/zabbix-server-mysql/install/mysql" ]]; then
mysql -D zabbix < /usr/share/dbconfig-common/data/zabbix-server-mysql/install/mysql
else
cd /usr/share/doc/zabbix-server-mysql/
if [[ -f 'create.sql.gz' ]]; then
zcat create.sql.gz | mysql -D zabbix
else
mysql -D zabbix < schema.sql
mysql -D zabbix < images.sql
mysql -D zabbix < data.sql
fi
fi
# enable zabbix server monitoring
mysql -D zabbix -e 'UPDATE hosts SET status=0 WHERE status=1;'
# autoload any modules loaded into /usr/lib/zabbix/modules/
echo "==> Configuring Zabbix agent modules..."
shopt -s nullglob
for module in /usr/lib/zabbix/modules/*.so; do
echo "LoadModule=${module##*/}" >> /etc/zabbix/zabbix_agentd.conf
done
# start zabbix service
echo "==> Starting Services..."
/etc/init.d/zabbix-server start
/etc/init.d/zabbix-agent start
/etc/init.d/apache2 start
if [ "$#" -ne 0 ]; then
# execute user commands
$@
else
# tail logs
echo "==> Tailing logs..."
tail -f \
/var/log/zabbix/*.log \
/var/log/mysql.* \
/var/log/apache2/error.log
fi