From ecf728f74c6981c13a08c2f726e0673c5a53fae5 Mon Sep 17 00:00:00 2001 From: Marcin Krol Date: Thu, 20 Jul 2023 17:07:07 +0200 Subject: [PATCH] - fork in background during startup --- zabbix_agent2.init | 16 ++++++++++++++-- zabbix_agent2.sysconfig | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 zabbix_agent2.sysconfig diff --git a/zabbix_agent2.init b/zabbix_agent2.init index f4885d1..0802fb1 100644 --- a/zabbix_agent2.init +++ b/zabbix_agent2.init @@ -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 index 0000000..0a1c992 --- /dev/null +++ b/zabbix_agent2.sysconfig @@ -0,0 +1 @@ +ZABBIX_USER="zabbix" -- 2.46.0