]> git.99rst.org Git - openwrt-packages.git/commitdiff
zabbix: tweak server initscript and bring agentd to parity
authorDaniel F. Dickinson <redacted>
Fri, 17 Jul 2026 00:21:41 +0000 (20:21 -0400)
committerHannu Nyman <redacted>
Fri, 31 Jul 2026 09:50:45 +0000 (12:50 +0300)
* Genericize zabbix_server initscript.
* Add shellcheck overrides where needed.
* Add a 'never_root' config option (default true) that determines
  whether server starts as an unprivileged user or starts as root and
  drops to an unprivileged user (unless config is changed so it always
  runs as root).
* Bring zabbix_agentd initscript to parity with zabbix_server for the
  initscript and configuration.
* Tweak Makefile to reduce repetition

Signed-off-by: Daniel F. Dickinson <redacted>
admin/zabbix/Makefile
admin/zabbix/files/zabbix_agentd.config [new file with mode: 0644]
admin/zabbix/files/zabbix_agentd.defaults [new file with mode: 0644]
admin/zabbix/files/zabbix_agentd.init
admin/zabbix/files/zabbix_server.config
admin/zabbix/files/zabbix_server.init

index dcc5373e502c813a4dd2755c35c35e7a4d5929f3..d4bedaf404d264ddaaaacadba7bda481c5bd8bf9 100644 (file)
@@ -495,6 +495,13 @@ endef
 define Package/zabbix-agentd/conffiles
 /etc/zabbix_agentd.conf
 /etc/zabbix_agentd.conf.d/
+/etc/config/zabbix_agentd
+endef
+
+define Package/zabbix-agentd/postinst
+#!/bin/sh
+[ -n "$${IPKG_INSTROOT}" ] || (. /etc/uci-defaults/90_zabbix_agentd) && rm -f /etc/uci-defaults/90_zabbix_agentd
+exit 0
 endef
 
 define Package/zabbix-agentd/install
@@ -503,19 +510,17 @@ define Package/zabbix-agentd/install
        $(call Package/zabbix/install/sbin,$(1),agentd)
        $(call Package/zabbix/install/etc,$(1),agentd)
        $(call Package/zabbix/install/init.d,$(1),agentd)
+       $(INSTALL_DIR) $(1)/etc/config
+       $(INSTALL_CONF) ./files/zabbix_agentd.config $(1)/etc/config/zabbix_agentd
+       $(INSTALL_DIR) $(1)/etc/uci-defaults
+       $(INSTALL_BIN) ./files/zabbix_agentd.defaults $(1)/etc/uci-defaults/90_zabbix_agentd
 endef
 
-define Package/zabbix-agentd-basic/conffiles
-/etc/zabbix_agentd.conf
-/etc/zabbix_agentd.conf.d/
-endef
+Package/zabbix-agentd-basic/conffiles=$(call Package/zabbix-agentd/conffiles)
+Package/zabbix-agentd-basic/postinst=$(call Package/zabbix-agentd/postinst)
 
 define Package/zabbix-agentd-basic/install
-       $(INSTALL_DIR) $(1)/etc/zabbix_agentd.conf.d
-       $(INSTALL_DIR) $(1)/usr/share/zabbix_agentd.openwrt-params.d
-       $(call Package/zabbix/install/sbin,$(1),agentd)
-       $(call Package/zabbix/install/etc,$(1),agentd)
-       $(call Package/zabbix/install/init.d,$(1),agentd)
+       $(call Package/zabbix-agentd/install,$(1))
 endef
 
 define Package/zabbix-proxy/conffiles
diff --git a/admin/zabbix/files/zabbix_agentd.config b/admin/zabbix/files/zabbix_agentd.config
new file mode 100644 (file)
index 0000000..9f38a26
--- /dev/null
@@ -0,0 +1,4 @@
+
+config zabbix_agentd 'general'
+    option enabled 0
+    # option never_root 1
diff --git a/admin/zabbix/files/zabbix_agentd.defaults b/admin/zabbix/files/zabbix_agentd.defaults
new file mode 100644 (file)
index 0000000..601eb5d
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+chown zabbix-agent:zabbix-agent /etc/zabbix_agentd.conf
index 04bef3730d3a6185a14862c05cc70d34c540222f..eb2b0d830bda31d0fa7f6c462fc9399ee2cb8279 100755 (executable)
@@ -1,26 +1,52 @@
 #!/bin/sh /etc/rc.common
 # Copyright (C) 2008-2011 OpenWrt.org
 
+# shellcheck shell=busybox
+
+# shellcheck disable=SC2034
 START=60
 
+# shellcheck disable=SC2034
 USE_PROCD=1
-PROG=/usr/sbin/zabbix_agentd
-CONFIG=/etc/zabbix_agentd.conf
+NAME=zabbix_agentd
+PROG=/usr/sbin/${NAME}
+CONFIG=/etc/${NAME}.conf
+UCI_CONFIG=/etc/config/${NAME}
+USER=zabbix-agent
 
 start_service() {
+       local enabled never_root
+
        # Sometimes the agentd config was installed in /etc/zabbix/zabbix_agentd.conf
        [ -f /etc/zabbix/zabbix_agentd.conf ] && mv /etc/zabbix/zabbix_agentd.conf ${CONFIG}
 
-       [ -f ${CONFIG} ] || return 1
+       if [ ! -f "${CONFIG}" ]; then
+               logger "Configuration file not found: '${CONFIG}'"
+               return 1
+       fi
+
+       # Get enabled config option
+       config_load "$NAME"
+       config_get_bool enabled general enabled 0
+       config_get_bool never_root general never_root 1
 
-       mkdir -p /var/run/zabbix-agent
-       chown zabbix-agent:zabbix-agent /var/run/zabbix-agent
+       # shellcheck disable=SC2154
+       if [ "$enabled" -eq 0 ]; then
+               logger "service not enabled in $UCI_CONFIG"
+               return 1
+       fi
+
+       mkdir -p "/var/run/$USER"
+       chown $USER:$USER "/var/run/$USER"
 
        procd_open_instance
        procd_set_param command ${PROG} -c ${CONFIG} -f
+       if [ "$never_root" -eq 1 ]; then
+               procd_set_param user ${USER}
+       fi
+       procd_set_param file ${CONFIG}
        procd_set_param respawn
        procd_set_param stdout 1
        procd_set_param stderr 1
        procd_close_instance
 }
-
index 45e3f3062b0abaa20a88a89d9bf1e6a27021fc1c..c6fceba4d0a3894de605f2b53eeed19f196c8fd8 100644 (file)
@@ -1,3 +1,4 @@
 
 config zabbix_server 'general'
     option enabled 0
+    # option never_root 1
index bcbdb41cd7d7e9be5be18aee8e8df80a6353f142..a2454697663fdb407fcb1678396893ca52e8434f 100755 (executable)
@@ -1,6 +1,8 @@
 #!/bin/sh /etc/rc.common
 # Copyright (C) 2008-2025 OpenWrt.org
 
+# shellcheck shell=busybox
+
 # shellcheck disable=SC2034
 START=59
 
@@ -9,9 +11,13 @@ USE_PROCD=1
 
 NAME=zabbix_server
 PROG=/usr/sbin/${NAME}
-CONFIG=/etc/zabbix_server.conf
+CONFIG=/etc/${NAME}.conf
+UCI_CONFIG=/etc/config/${NAME}
+USER=zabbix-server
 
 start_service() {
+       local enabled never_root
+
        if [ ! -f "${CONFIG}" ]; then
                logger "Configuration file not found: '${CONFIG}'"
                return 1
@@ -20,19 +26,22 @@ start_service() {
        # Get enabled config option
        config_load "$NAME"
        config_get_bool enabled general enabled 0
+       config_get_bool never_root general never_root 1
 
        # shellcheck disable=SC2154
        if [ "$enabled" -eq 0 ]; then
-               logger "service not enabled in /etc/config/$NAME"
+               logger "service not enabled in $UCI_CONFIG"
                return 1
        fi
 
-       mkdir -p /var/run/zabbix-server
-       chown zabbix-server:zabbix-server /var/run/zabbix-server
+       mkdir -p "/var/run/$USER"
+       chown $USER:$USER "/var/run/$USER"
 
        procd_open_instance
        procd_set_param command ${PROG} -c ${CONFIG} -f
-       procd_set_param user zabbix-server
+       if [ "$never_root" -eq 1 ]; then
+               procd_set_param user ${USER}
+       fi
        procd_set_param limits nofile="16384 100000"
        procd_set_param file ${CONFIG}
        procd_set_param respawn
git clone https://git.99rst.org/PROJECT