* 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>
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
$(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
--- /dev/null
+
+config zabbix_agentd 'general'
+ option enabled 0
+ # option never_root 1
--- /dev/null
+#!/bin/sh
+
+chown zabbix-agent:zabbix-agent /etc/zabbix_agentd.conf
#!/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
}
-
config zabbix_server 'general'
option enabled 0
+ # option never_root 1
#!/bin/sh /etc/rc.common
# Copyright (C) 2008-2025 OpenWrt.org
+# shellcheck shell=busybox
+
# shellcheck disable=SC2034
START=59
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
# 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