forked from pschmitt/docker-zabbix-agent2-custom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-entrypoint.patch
49 lines (46 loc) · 1.27 KB
/
docker-entrypoint.patch
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
--- patch/docker-entrypoint.sh.orig 2020-07-02 11:32:46.321465533 +0200
+++ patch/docker-entrypoint.sh 2020-07-02 11:45:04.501223795 +0200
@@ -182,6 +182,38 @@
prepare_agent() {
echo "** Preparing Zabbix agent"
prepare_zbx_agent_config
+ include_static_zabbix_conf
+ join_custom_group
+}
+
+join_custom_group() {
+ # Create custom group and add zabbix user to it
+ if [[ -n "$GROUP" ]] || [[ -n "$GID" ]]
+ then
+ local extra_args=()
+ local group="${GROUP:-custom_group}"
+
+ if [[ -n "$GID" ]]
+ then
+ extra_args+=(-g "$GID")
+ fi
+
+ addgroup "${extra_args[@]}" "$group"
+ addgroup zabbix "$group"
+
+ unset GROUP GID
+ fi
+}
+
+include_static_zabbix_conf() {
+ local config=/etc/zabbix/zabbix_agent2.conf
+ local static_dir=/etc/zabbix/zabbix_agentd.d_static/
+
+ # Insert Include statement at the end
+ awk 'FNR==NR{ if (/Include=/) p=NR; next} 1; FNR==p{ print "Include='"${static_dir}"'" }' \
+ "$config" "$config" \
+ > "${config}.new"
+ mv "${config}.new" "$config"
}
#################################################
@@ -194,6 +226,6 @@
prepare_agent
fi
-exec "$@"
+exec su -s /bin/bash zabbix -c "$*"
#################################################