[nsca] Add systemd support

Xavier Bachelot xavierb at fedoraproject.org
Wed Sep 19 20:47:45 UTC 2012


commit c470cea24d4c3b8a67ea8f26e6b88113fd48f0d8
Author: Xavier Bachelot <xavier at bachelot.org>
Date:   Wed Sep 19 22:46:55 2012 +0200

    Add systemd support

 nsca.service |   11 +++++++++++
 nsca.spec    |   47 ++++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 51 insertions(+), 7 deletions(-)
---
diff --git a/nsca.service b/nsca.service
new file mode 100644
index 0000000..47d59da
--- /dev/null
+++ b/nsca.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Nagios Service Check Acceptor
+After=syslog.target network.target auditd.service
+
+[Service]
+EnvironmentFile=-/etc/sysconfig/nsca
+ExecStart=/usr/sbin/nsca $OPTIONS -c /etc/nagios/nsca.cfg
+ExecReload=/bin/kill -HUP $MAINPID
+
+[Install]
+WantedBy=multi-user.target
diff --git a/nsca.spec b/nsca.spec
index 22400b3..124cc78 100644
--- a/nsca.spec
+++ b/nsca.spec
@@ -1,13 +1,20 @@
+%if 0%{?fedora} > 17 || 0%{?rhel} > 6
+%global systemd_support 1
+%else
+%global systemd_support 0
+%endif
+
 Summary:        Nagios Service Check Acceptor
 Name:           nsca
 Version:        2.9.1
-Release:        3%{?dist}
+Release:        4%{?dist}
 License:        GPLv2+
 Group:          Applications/System
 URL:            http://www.nagios.org/
 Source0:        http://downloads.sourceforge.net/nagios/nsca-%{version}.tar.gz
 Source1:        nsca-initscript
 Source2:        nsca-sysconfig
+Source3:        nsca.service
 BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 
 Patch0:         nsca-2.9-initscript.patch
@@ -16,10 +23,17 @@ Patch1:         nsca-2.9-confpath.patch
 Patch2:         nsca-2.9-fix_open_missing_arg.patch
 
 BuildRequires:  libmcrypt-devel
-Requires:       nagios
+%if %{systemd_support}
+BuildRequires: systemd-units
+Requires(post): systemd-units
+Requires(preun): systemd-units
+Requires(postun): systemd-units
+%else
 Requires(preun): /sbin/service, /sbin/chkconfig
 Requires(post): /sbin/chkconfig
 Requires(postun): /sbin/service
+%endif
+Requires:       nagios
 
 
 %description
@@ -63,25 +77,37 @@ install -Dp -m 0755 src/nsca %{buildroot}%{_sbindir}/nsca
 install -Dp -m 0755 src/send_nsca %{buildroot}%{_sbindir}/send_nsca
 install -Dp -m 0644 sample-config/nsca.cfg %{buildroot}%{_sysconfdir}/nagios/nsca.cfg
 install -Dp -m 0644 sample-config/send_nsca.cfg %{buildroot}%{_sysconfdir}/nagios/send_nsca.cfg
-install -Dp -m 0755 %{SOURCE1} %{buildroot}%{_initrddir}/nsca
 install -Dp -m 0644 %{SOURCE2} %{buildroot}%{_sysconfdir}/sysconfig/nsca
+%if %{systemd_support}
+install -Dp -m 0644 %{SOURCE3} %{buildroot}%{_unitdir}/nsca.service
+%else
+install -Dp -m 0755 %{SOURCE1} %{buildroot}%{_initrddir}/nsca
+%endif
+
+%if %{systemd_support}
+%post
+%systemd_post nsca.service
 
+%preun
+%systemd_preun nsca.service
 
+%postun
+%systemd_postun_with_restart nsca.service 
+%else
 %post
 /sbin/chkconfig --add nsca || :
 
-
 %preun
 if [ $1 -eq 0 ]; then
         /sbin/service nsca stop &>/dev/null
         /sbin/chkconfig --del nsca || :
 fi
 
-
 %postun
 if [ "$1" -ge "1" ]; then
         /sbin/service nsca condrestart &>/dev/null || :
 fi
+%endif
 
 
 %clean
@@ -93,8 +119,12 @@ rm -rf %{buildroot}
 %doc Changelog LEGAL README SECURITY
 %attr(0600,root,root) %config(noreplace) %{_sysconfdir}/nagios/nsca.cfg
 %config(noreplace) %{_sysconfdir}/sysconfig/nsca
-%{_initrddir}/nsca
 %{_sbindir}/nsca
+%if %{systemd_support}
+%{_unitdir}/nsca.service
+%else
+%{_initrddir}/nsca
+%endif
 
 
 %files client
@@ -106,7 +136,10 @@ rm -rf %{buildroot}
 
 
 %changelog
-* Mon Sep 01 2012 Xavier Bachelot <xavier at bachelot.org> - 2.9.1-3
+* Tue Sep 04 2012 Xavier Bachelot <xavier at bachelot.org> - 2.9.1-4
+- Add systemd support.
+
+* Mon Sep 03 2012 Xavier Bachelot <xavier at bachelot.org> - 2.9.1-3
 - Add a sysconfig file.
 - Rewrite initscript.
 


More information about the scm-commits mailing list