zabbix: add initscript for server

Adds an initscript for zabbix_server, and related helper files

+ uses a zabbix_server uci conf to enable/disable startup
+ updates the default zabbix_server.conf to work with initscript
+ add a sysctl.d conf to set max-files more appropriate for zabbix_server

Signed-off-by: Daniel F. Dickinson <dfdpublic@wildtechgarden.ca>
This commit is contained in:
Daniel F. Dickinson
2025-12-09 00:21:18 -05:00
committed by George Sapkin
parent 1ff6a92251
commit ffdb7209a4
6 changed files with 120 additions and 1 deletions

View File

@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=zabbix
PKG_VERSION:=7.0.21
PKG_RELEASE:=3
PKG_RELEASE:=4
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://cdn.zabbix.com/zabbix/sources/stable/$(basename $(PKG_VERSION))/ \
@@ -336,6 +336,8 @@ Package/zabbix-agentd-gnutls/conffiles = $(Package/zabbix-agentd/conffiles)
define Package/zabbix-server/conffiles
/etc/zabbix_server.conf
/etc/config/zabbix_server
/etc/sysctl.d/90-zabbix-discovery-workers.conf
endef
Package/zabbix-server-openssl/conffiles = $(Package/zabbix-server/conffiles)
Package/zabbix-server-gnutls/conffiles = $(Package/zabbix-server/conffiles)
@@ -424,10 +426,26 @@ Package/zabbix-get-gnutls/install = $(Package/zabbix-get/install)
define Package/zabbix-server/install
$(call Package/zabbix/install/sbin,$(1),server)
$(call Package/zabbix/install/etc,$(1),server)
$(call Package/zabbix/install/init.d,$(1),server)
$(INSTALL_DIR) $(1)/etc/sysctl.d
$(INSTALL_CONF) ./files/zabbix-discovery-workers.conf.sysctl $(1)/etc/sysctl.d/90-zabbix-discovery-workers.conf
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_CONF) ./files/zabbix_server.config $(1)/etc/config/zabbix_server
$(INSTALL_DIR) $(1)/etc/uci-defaults
$(INSTALL_BIN) ./files/zabbix_server.defaults $(1)/etc/uci-defaults/90_zabbix_server
endef
Package/zabbix-server-openssl/install = $(Package/zabbix-server/install)
Package/zabbix-server-gnutls/install = $(Package/zabbix-server/install)
define Package/zabbix-server/postinst
#!/bin/sh
[ -n "$${IPKG_INSTROOT}" ] || (. /etc/uci-defaults/90_zabbix_server) && rm -f /etc/uci-defaults/90_zabbix_server
exit 0
endef
Package/zabbix-server-openssl/postinst = $(Package/zabbix-server/postinst)
Package/zabbix-server-gnutls/postinst = $(Package/zabbix-server/postinst)
define Package/zabbix-server-frontend/install
$(INSTALL_DIR) $(1)/www/zabbix
$(CP) $(PKG_BUILD_DIR)/ui/* $(1)/www/zabbix

View File

@@ -0,0 +1 @@
fs.file-max=100000

View File

@@ -0,0 +1,3 @@
config zabbix_server 'general'
option enabled 0

View File

@@ -0,0 +1,3 @@
#!/bin/sh
chown zabbix:zabbix /etc/zabbix_server.conf

View File

@@ -0,0 +1,42 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2008-2025 OpenWrt.org
# shellcheck disable=SC2034
START=59
# shellcheck disable=SC2034
USE_PROCD=1
NAME=zabbix_server
PROG=/usr/sbin/${NAME}
CONFIG=/etc/zabbix_server.conf
start_service() {
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
# shellcheck disable=SC2154
if [ "$enabled" -eq 0 ]; then
logger "service not enabled in /etc/config/$NAME"
return 1
fi
mkdir -p /var/run/zabbix
chown zabbix:zabbix /var/run/zabbix
procd_open_instance
procd_set_param command ${PROG} -c ${CONFIG} -f
procd_set_param user zabbix
procd_set_param limits nofile="16384 100000"
procd_set_param file ${CONFIG}
procd_set_param respawn
procd_set_param stdout 1
procd_set_param stderr 1
procd_close_instance
}

View File

@@ -0,0 +1,52 @@
From 9675bd17ae35744696c90b423b0c19905349c8a1 Mon Sep 17 00:00:00 2001
From: "Daniel F. Dickinson" <dfdpublic@wildtechgarden.ca>
Date: Wed, 17 Dec 2025 06:39:16 -0500
Subject: [PATCH] Make zabbix_server config suitable for OpenWrt
1. Log to (default ephemeral) syslog, not a file (and don't rotate)
2. Update PidFile path so correct permissions can be set for access by
Zabbix server running without privileges.
Signed-off-by: Daniel F. Dickinson <dfdpublic@wildtechgarden.ca>
---
conf/zabbix_server.conf | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
--- a/conf/zabbix_server.conf
+++ b/conf/zabbix_server.conf
@@ -27,6 +27,7 @@
# Mandatory: no
# Default:
# LogType=file
+LogType=system
### Option: LogFile
# Log file name for LogType 'file' parameter.
@@ -35,7 +36,7 @@
# Default:
# LogFile=
-LogFile=/tmp/zabbix_server.log
+# LogFile=/tmp/zabbix_server.log
### Option: LogFileSize
# Maximum size of log file in MB.
@@ -45,6 +46,7 @@ LogFile=/tmp/zabbix_server.log
# Range: 0-1024
# Default:
# LogFileSize=1
+LogFileSize=0
### Option: DebugLevel
# Specifies debug level:
@@ -67,6 +69,10 @@ LogFile=/tmp/zabbix_server.log
# Default:
# PidFile=/tmp/zabbix_server.pid
+# Although procd does not require a pid file, zabbix uses the pidfile to
+# shut down correctly on receipt of a TERM or INT signal.
+PidFile=/var/run/zabbix/zabbix_server.pid
+
### Option: SocketDir
# IPC socket directory.
# Directory to store IPC sockets used by internal Zabbix services.