From: Daniel F. Dickinson Date: Fri, 17 Jul 2026 00:21:41 +0000 (-0400) Subject: zabbix: tweak server initscript and bring agentd to parity X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=ec5497292452db0cfb0205fca16c6460607b5433;p=openwrt-packages.git zabbix: tweak server initscript and bring agentd to parity * 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 --- diff --git a/admin/zabbix/Makefile b/admin/zabbix/Makefile index dcc5373e5..d4bedaf40 100644 --- a/admin/zabbix/Makefile +++ b/admin/zabbix/Makefile @@ -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 index 000000000..9f38a26c7 --- /dev/null +++ b/admin/zabbix/files/zabbix_agentd.config @@ -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 index 000000000..601eb5daa --- /dev/null +++ b/admin/zabbix/files/zabbix_agentd.defaults @@ -0,0 +1,3 @@ +#!/bin/sh + +chown zabbix-agent:zabbix-agent /etc/zabbix_agentd.conf diff --git a/admin/zabbix/files/zabbix_agentd.init b/admin/zabbix/files/zabbix_agentd.init index 04bef3730..eb2b0d830 100755 --- a/admin/zabbix/files/zabbix_agentd.init +++ b/admin/zabbix/files/zabbix_agentd.init @@ -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 } - diff --git a/admin/zabbix/files/zabbix_server.config b/admin/zabbix/files/zabbix_server.config index 45e3f3062..c6fceba4d 100644 --- a/admin/zabbix/files/zabbix_server.config +++ b/admin/zabbix/files/zabbix_server.config @@ -1,3 +1,4 @@ config zabbix_server 'general' option enabled 0 + # option never_root 1 diff --git a/admin/zabbix/files/zabbix_server.init b/admin/zabbix/files/zabbix_server.init index bcbdb41cd..a24546976 100755 --- a/admin/zabbix/files/zabbix_server.init +++ b/admin/zabbix/files/zabbix_server.init @@ -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