]> TLD Linux GIT Repositories - packages/zabbix.git/commitdiff
- fork in background during startup
authorMarcin Krol <hawk@tld-linux.org>
Thu, 20 Jul 2023 15:07:07 +0000 (17:07 +0200)
committerMarcin Krol <hawk@tld-linux.org>
Thu, 20 Jul 2023 15:07:07 +0000 (17:07 +0200)
zabbix_agent2.init
zabbix_agent2.sysconfig [new file with mode: 0644]

index f4885d1cfd12f4dd1599d2259046d0a70672e294..0802fb17c4943f3cbe385403e47081d0621c4814 100644 (file)
@@ -24,10 +24,22 @@ else
        exit 0
 fi
 
+ZABBIX_USER="zabbix"
+
 # Get service config - may override defaults
 [ -f /etc/sysconfig/zabbix_agent2 ] && . /etc/sysconfig/zabbix_agent2
 
-pidfile="/var/run/zabbix/zabbix_agent2.pid"
+# Try to get configured PidFile or set default
+get_pid() {
+       local config="$1"
+       local pidfile
+       test -f "$config" && pidfile=$(awk -F= '/^ *PidFile/ {print $2}' "$config")
+       # Fallback to zabbix_agent2 default pidfile
+       test -n "$pidfile" || pidfile=/tmp/zabbix_agent2.pid
+       echo "$pidfile"
+}
+
+pidfile=$(get_pid /etc/zabbix/zabbix_agent2.conf)
 
 start() {
        # Check if the service is already running?
@@ -37,7 +49,7 @@ start() {
        fi
 
        msg_starting "Zabbix Agent 2"
-       daemon /usr/sbin/zabbix_agent2
+       daemon --fork --user $ZABBIX_USER /usr/sbin/zabbix_agent2
        RETVAL=$?
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/zabbix_agent2
 }
diff --git a/zabbix_agent2.sysconfig b/zabbix_agent2.sysconfig
new file mode 100644 (file)
index 0000000..0a1c992
--- /dev/null
@@ -0,0 +1 @@
+ZABBIX_USER="zabbix"