[packages/zabbix] Add initscript for zabbix_agent2

glen glen at pld-linux.org
Wed Aug 25 14:11:55 CEST 2021


commit 1afc63f3b775e6ffc80b999e43d6ee4d76ea9b1b
Author: Elan Ruusamäe <glen at pld-linux.org>
Date:   Wed Aug 25 14:52:25 2021 +0300

    Add initscript for zabbix_agent2

 zabbix.spec        | 20 +++++++++--
 zabbix_agent2.init | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 115 insertions(+), 3 deletions(-)
---
diff --git a/zabbix.spec b/zabbix.spec
index eeb746d..4e73ab2 100644
--- a/zabbix.spec
+++ b/zabbix.spec
@@ -30,6 +30,8 @@ Group:		Networking/Utilities
 # https://www.zabbix.com/download_sources
 Source0:	https://cdn.zabbix.com/zabbix/sources/stable/5.4/%{name}-%{version}.tar.gz
 # Source0-md5:	5dccb536c164e45c7d5c1a5a9d64be43
+Source100:	go-vendor.tar.xz
+# Source100-md5:	61f2ee9647280765b622a5e1e8cdfbba
 Source1:	%{name}-apache.conf
 Source2:	%{name}_server.service
 Source3:	%{name}_agentd.service
@@ -37,13 +39,12 @@ Source4:	%{name}_proxy.service
 Source5:	%{name}_java.service
 Source6:	%{name}.tmpfiles
 Source7:	%{name}_agentd.init
+Source8:	%{name}_agent2.init
 %if 0
 cd src/go/
 go mod vendor
 tar -caf ~/go-vendor.tar.xz -C ../../ src/go/vendor
 %endif
-Source8:	go-vendor.tar.xz
-# Source8-md5:	61f2ee9647280765b622a5e1e8cdfbba
 Patch0:		config.patch
 Patch1:		sqlite3_dbname.patch
 Patch2:		always_compile_ipc.patch
@@ -145,6 +146,8 @@ Summary:	Zabbix Agent 2
 Group:		Networking/Utilities
 URL:		https://www.zabbix.com/documentation/current/manual/concepts/agent2
 Requires:	%{name}-common = %{version}-%{release}
+Requires(post,preun):	/sbin/chkconfig
+Requires:	rc-scripts
 
 %description agent2
 Zabbix agent 2 is a new generation of Zabbix agent and may be used in
@@ -335,7 +338,7 @@ Requires:	systemd-units >= 38
 This package provides the Zabbix Java Gateway.
 
 %prep
-%setup -q -a8
+%setup -q -a100
 %patch0 -p1
 %patch1 -p1
 %patch2 -p1
@@ -437,6 +440,7 @@ cp -p %{SOURCE1} $RPM_BUILD_ROOT%{_webapps}/%{_webapp}/httpd.conf
 install	%{SOURCE2} $RPM_BUILD_ROOT%{systemdunitdir}/zabbix_server.service
 install	%{SOURCE3} $RPM_BUILD_ROOT%{systemdunitdir}/zabbix_agentd.service
 install	%{SOURCE7} $RPM_BUILD_ROOT/etc/rc.d/init.d/zabbix_agentd
+install	%{SOURCE8} $RPM_BUILD_ROOT/etc/rc.d/init.d/zabbix_agent2
 install	%{SOURCE4} $RPM_BUILD_ROOT%{systemdunitdir}/zabbix_proxy.service
 install	%{SOURCE5} $RPM_BUILD_ROOT%{systemdunitdir}/zabbix_java.service
 
@@ -552,6 +556,16 @@ fi
 %postun agentd
 %systemd_reload
 
+%post agent2
+/sbin/chkconfig --add zabbix_agent2
+%service zabbix_agent2 restart
+
+%preun agent2
+if [ "$1" = "0" ]; then
+	%service -q zabbix_agent2 stop
+	/sbin/chkconfig --del zabbix_agent2
+fi
+
 %post proxy-mysql
 ln -sf zabbix_proxy-mysql %{_sbindir}/zabbix_proxy || :
 
diff --git a/zabbix_agent2.init b/zabbix_agent2.init
new file mode 100755
index 0000000..eb83ccf
--- /dev/null
+++ b/zabbix_agent2.init
@@ -0,0 +1,98 @@
+#!/bin/sh
+#
+# Starts the zabbix_agent2 daemon
+#
+# chkconfig:	345 95 5
+#
+# description:	zabbix_agent2 long service description
+#
+# processname:	zabbix_agent2
+# processname: zabbix_agent2
+# Source function library
+. /etc/rc.d/init.d/functions
+
+# Get network config
+. /etc/sysconfig/network
+
+# Check that networking is up.
+if is_yes "${NETWORKING}"; then
+	if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
+		msg_network_down "Zabbix Agent2"
+		exit 1
+	fi
+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"
+
+start() {
+	# Check if the service is already running?
+	if [ -f /var/lock/subsys/zabbix_agent2 ]; then
+		msg_already_running "Zabbix Agent2"
+		return
+	fi
+
+	msg_starting "Zabbix Agent2"
+	daemon --fork --user $ZABBIX_USER /usr/sbin/zabbix_agent2
+	RETVAL=$?
+	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/zabbix_agent2
+}
+
+stop() {
+	if [ ! -f /var/lock/subsys/zabbix_agent2 ]; then
+		msg_not_running "Zabbix Agent2"
+		return
+	fi
+
+	# Stop daemons.
+	msg_stopping "Zabbix Agent2"
+	killproc --pidfile $pidfile zabbix_agent2 -TERM
+	rm -f /var/lock/subsys/zabbix_agent2
+}
+
+condrestart() {
+	if [ ! -f /var/lock/subsys/zabbix_agent2 ]; then
+		msg_not_running "Zabbix Agent2"
+		RETVAL=$1
+		return
+	fi
+
+	stop
+	start
+}
+
+RETVAL=0
+# See how we were called.
+case "$1" in
+  start)
+	start
+	;;
+  stop)
+	stop
+	;;
+  restart)
+	stop
+	start
+	;;
+  try-restart)
+	condrestart 0
+	;;
+  force-reload)
+	condrestart 7
+	;;
+  status)
+	status --pidfile $pidfile zabbix_agent2
+	RETVAL=$?
+	;;
+  *)
+	msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
+	exit 3
+esac
+
+exit $RETVAL
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/zabbix.git/commitdiff/1afc63f3b775e6ffc80b999e43d6ee4d76ea9b1b



More information about the pld-cvs-commit mailing list