From 7f3c04d77fcf57ab4d1a7a414b8559a2eaa2dc48 Mon Sep 17 00:00:00 2001 From: Silvan Calarco Date: Sat, 6 Jan 2024 07:30:52 +0100 Subject: [PATCH] systemd support [release 2.15-3mamba;Sun Dec 27 2015] --- nagios-nrpe.spec | 62 ++++++++++++++++++++++++++++-------------- nrpe-2.15-rundir.patch | 12 ++++++++ nrpe.service | 13 +++++++++ nrpe.socket | 9 ++++++ nrpe.tmpfiles | 1 + nrpe@.service | 8 ++++++ 6 files changed, 84 insertions(+), 21 deletions(-) create mode 100644 nrpe-2.15-rundir.patch create mode 100644 nrpe.service create mode 100644 nrpe.socket create mode 100644 nrpe.tmpfiles create mode 100644 nrpe@.service diff --git a/nagios-nrpe.spec b/nagios-nrpe.spec index d46fc20..f007914 100644 --- a/nagios-nrpe.spec +++ b/nagios-nrpe.spec @@ -4,7 +4,7 @@ Name: nagios-nrpe Version: 2.15 -Release: 2mamba +Release: 3mamba Summary: Nagios Remote Plugin Executor (NRPE) Group: Network/Monitoring Vendor: openmamba @@ -14,11 +14,16 @@ URL: http://www.nagios.org Source0: http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-%{version}/nrpe-%{version}.tar.gz Source1: nagios-nrpe.sysconfig Source2: nagios-commands-nrpe.cfg +Source3: nrpe.service +Source4: nrpe.socket +Source5: nrpe.tmpfiles +Source6: nrpe@.service Patch0: %{name}-2.13-initscript_add_reload.patch Patch1: %{name}-2.13-initscript_extra_options.patch Patch2: %{name}-2.13-include_nrpe_d_directory.patch Patch3: %{name}-2.13-initscript_return_codes.patch Patch4: %{name}-2.13-relocate_pid_file.patch +Patch5: nrpe-2.15-rundir.patch License: GPL ## AUTOBUILDREQ-BEGIN BuildRequires: glibc-devel @@ -28,6 +33,7 @@ BuildRequires: libopenssl-devel Requires: initscripts Provides: nrpe = %{?epoch:%epoch:}%{version}-%{release} Requires: nagios-plugins +%systemd_requires BuildRoot: %{_tmppath}/%{name}-%{version}-root %description @@ -50,6 +56,7 @@ The plugin then uses the output and return code from the plugin execution on the %patch2 -p1 %patch3 -p1 %patch4 -p1 +%patch5 -p1 %build CFLAGS="$RPM_OPT_FLAGS" CXXFLAGS="$RPM_OPT_FLAGS" \ @@ -70,17 +77,27 @@ CFLAGS="$RPM_OPT_FLAGS" CXXFLAGS="$RPM_OPT_FLAGS" \ %install [ "%{buildroot}" != / ] && rm -rf "%{buildroot}" -install -D -p -m 0755 init-script %{buildroot}/%{_initrddir}/nrpe +#install -D -p -m 0755 init-script %{buildroot}/%{_initrddir}/nrpe install -D -p -m 0644 sample-config/nrpe.cfg %{buildroot}/%{_sysconfdir}/nagios/nrpe.cfg install -D -p -m 0755 src/nrpe %{buildroot}%{_sbindir}/nrpe install -D -p -m 0755 src/check_nrpe %{buildroot}%{_libdir}/nagios/plugins/check_nrpe install -D -p -m 0644 %{S:1} %{buildroot}/%{_sysconfdir}/sysconfig/nrpe install -d %{buildroot}%{_sysconfdir}/nrpe.d -install -d %{buildroot}%{_localstatedir}/run/nrpe install -D -m0644 %{SOURCE2} %{buildroot}%{_sysconfdir}/nagios/conf.d/commands-nrpe.cfg +install -D -m0644 %{SOURCE3} %{buildroot}%{_unitdir}/nrpe.service +install -D -m0644 %{SOURCE4} %{buildroot}%{_unitdir}/nrpe.socket +install -D -m0644 %{SOURCE5} %{buildroot}%{_tmpfilesdir}/nrpe.conf +install -D -m0644 %{SOURCE6} %{buildroot}%{_unitdir}/nrpe@.service + +install -d %{buildroot}%{_sysconfdir}/sudoers.d +cat > %{buildroot}%{_sysconfdir}/sudoers.d/nrpe << _EOF +nrpe ALL=(root) NOPASSWD:%{_prefix}/lib/nagios/plugins/check_ide_smart +nrpe ALL=(root) NOPASSWD:%{_prefix}/lib/nagios/plugins/check_disk +_EOF + %clean [ "%{buildroot}" != / ] && rm -rf "%{buildroot}" @@ -91,33 +108,33 @@ getent passwd %{nrpeuser} >/dev/null || \ -r -g %{nrpegroup} -s /sbin/nologin %{nrpeuser} 2>/dev/null exit 0 -%preun -if [ $1 = 0 ]; then - /sbin/service nrpe stop >/dev/null 2>&1 - /sbin/chkconfig --del nrpe -fi -exit 0 - %post -/sbin/chkconfig --add nrpe -exit 0 - -%postun -if [ "$1" -ge "1" ]; then - /sbin/service nrpe condrestart >/dev/null 2>&1 +if [ $1 -ge 1 ]; then + systemctl -q daemon-reload + %tmpfiles_create nrpe.conf fi -exit 0 +: + +%preun +if [ $1 -eq 0 ]; then + systemctl -q daemon-reload +fi +: %files %defattr(-,root,root) -%{_sbindir}/nrpe -%{_initrddir}/nrpe +%{_sysconfdir}/sudoers.d/nrpe %config(noreplace) %{_sysconfdir}/nagios/nrpe.cfg %config(noreplace) %{_sysconfdir}/sysconfig/nrpe +%{_sbindir}/nrpe %dir %{_sysconfdir}/nagios %dir %{_sysconfdir}/nrpe.d -%dir %attr(775, %{nrpeuser}, %{nrpegroup}) %{_localstatedir}/run/nrpe -%doc LEGAL README README.SSL SECURITY docs/NRPE.pdf +%{_unitdir}/nrpe.service +%{_unitdir}/nrpe.socket +%{_unitdir}/nrpe@.service +%{_tmpfilesdir}/nrpe.conf +%doc LEGAL +#%doc README README.SSL SECURITY docs/NRPE.pdf %files -n nagios-plugins-nrpe %defattr(-,root,root,-) @@ -125,6 +142,9 @@ exit 0 %{_libdir}/nagios/plugins/check_nrpe %changelog +* Sun Dec 27 2015 Silvan Calarco 2.15-3mamba +- systemd support + * Wed May 07 2014 Silvan Calarco 2.15-2mamba - require nagios-plugins - install a default nrpe command configuration for nagios diff --git a/nrpe-2.15-rundir.patch b/nrpe-2.15-rundir.patch new file mode 100644 index 0000000..1ba11b6 --- /dev/null +++ b/nrpe-2.15-rundir.patch @@ -0,0 +1,12 @@ +diff -Nru nrpe-2.15.orig/sample-config/nrpe.cfg.in nrpe-2.15/sample-config/nrpe.cfg.in +--- nrpe-2.15.orig/sample-config/nrpe.cfg.in 2015-12-27 12:52:52.736007937 +0100 ++++ nrpe-2.15/sample-config/nrpe.cfg.in 2015-12-27 12:54:57.440985520 +0100 +@@ -23,7 +23,7 @@ + # number. The file is only written if the NRPE daemon is started by the root + # user and is running in standalone mode. + +-pid_file=/var/run/nrpe/nrpe.pid ++pid_file=/run/nrpe/nrpe.pid + + + diff --git a/nrpe.service b/nrpe.service new file mode 100644 index 0000000..d153428 --- /dev/null +++ b/nrpe.service @@ -0,0 +1,13 @@ +[Unit] +Description=Daemon to answer plugin requests from Nagios on remote hosts +After=network.target +Requires=network.target + +[Service] +Type=forking +User=nrpe +Group=nrpe +ExecStart=/usr/sbin/nrpe -c /etc/nagios/nrpe.cfg -d + +[Install] +WantedBy=multi-user.target diff --git a/nrpe.socket b/nrpe.socket new file mode 100644 index 0000000..d077a89 --- /dev/null +++ b/nrpe.socket @@ -0,0 +1,9 @@ +[Unit] +Description=NRPE Socket for Per-Connection Servers + +[Socket] +ListenStream=5666 +Accept=yes + +[Install] +WantedBy=sockets.target diff --git a/nrpe.tmpfiles b/nrpe.tmpfiles new file mode 100644 index 0000000..c6c857e --- /dev/null +++ b/nrpe.tmpfiles @@ -0,0 +1 @@ +d /run/nrpe 0755 nrpe nrpe - diff --git a/nrpe@.service b/nrpe@.service new file mode 100644 index 0000000..7e37a8e --- /dev/null +++ b/nrpe@.service @@ -0,0 +1,8 @@ +[Unit] +Description=NRPE Per-Connection Server + +[Service] +ExecStart=-/usr/sbin/nrpe -c /etc/nagios/nrpe.cfg --inetd +User=nrpe +Group=nrpe +StandardInput=socket