[openvas-manager] migrate from sysv init scripts to systemd

rebus rebus at fedoraproject.org
Tue Apr 10 02:04:07 UTC 2012


commit 5e856b82604c55430385887b95dd7f06ff746c18
Author: Michal Ambroz <rebus at seznam.cz>
Date:   Tue Apr 10 04:03:40 2012 +0200

    migrate from sysv init scripts to systemd

 openvas-manager.spec |   82 +++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 75 insertions(+), 7 deletions(-)
---
diff --git a/openvas-manager.spec b/openvas-manager.spec
index d6e08ef..84de6e5 100644
--- a/openvas-manager.spec
+++ b/openvas-manager.spec
@@ -1,7 +1,7 @@
 Name:		openvas-manager
 Summary:	Manager Module for the Open Vulnerability Assessment System (OpenVAS)
 Version:	2.0.4
-Release:	2%{?dist}
+Release:	3%{?dist}
 URL:		http://www.openvas.org
 License:	GPLv2+
 Group:		System Environment/Libraries
@@ -10,6 +10,7 @@ Source0:	http://wald.intevation.org/frs/download.php/871/%{name}-%{version}.tar.
 Source1:	openvas-manager.initd
 Source2:	openvas-manager.logrotate
 Source3:	openvas-manager.sysconfig
+Source4:	openvas-manager.service
 
 #Patch to avoid compile-time errors about variable set but not used
 Patch0:		openvas-manager-notused.patch
@@ -33,9 +34,14 @@ BuildRequires:	xmltoman
 Requires:	logrotate
 Requires:	/usr/bin/xsltproc
 
-Requires(post):		chkconfig
-Requires(preun):	chkconfig
-Requires(preun):	initscripts
+
+Requires(post):		systemd-units
+Requires(preun):	systemd-units
+Requires(postun):	systemd-units
+# This is actually needed for the %triggerun script but Requires(triggerun)
+# is not valid.  We can use %post because this particular %triggerun script
+# should fire just after this package is installed.
+Requires(post):		systemd-sysv
 
 
 %description
@@ -49,6 +55,21 @@ a SQL database (sqlite-based) where all configuration and scan result data is
 centrally stored.
 
 
+
+%package sysvinit
+Summary:		SysV style init script for %{name}
+Group:			Documentation
+Requires:		%{name} = %{version}-%{release}
+Requires(post):		chkconfig
+Requires(preun):	chkconfig
+Requires(preun):	initscripts
+
+%description sysvinit
+SysV style init script for %{name}.
+It needs to be installed only if systemd is not used as the system init process.
+
+
+
 %prep
 %setup -q
 #%patch0 -p1 -b .notused
@@ -78,6 +99,10 @@ mkdir -p %{buildroot}/%{_var}/lib/openvas/mgr
 # Install startup script
 install -Dp -m 755 %{SOURCE1} %{buildroot}/%{_initddir}/%{name}
 
+# Install systemd
+install -Dp -m 644 %{SOURCE4} %{buildroot}/%{_unitdir}/%{name}.service
+
+
 # install log rotation stuff
 install -m 644 -Dp %{SOURCE2} \
 	%{buildroot}/%{_sysconfdir}/logrotate.d/%{name}
@@ -93,21 +118,54 @@ find %{buildroot}%{_datadir}/openvas/openvasmd -name generate | xargs chmod 755
 [ "%{buildroot}" = "/" ] || rm -rf %{buildroot}
 
 
+
 %post
+if [ $1 -eq 1 ] ; then
+    # Initial installation
+    /bin/systemctl daemon-reload >/dev/null 2>&1 || :
+fi
+
+%preun
+if [ $1 -eq 0 ] ; then
+    # Package removal, not upgrade
+    /bin/systemctl --no-reload disable openvas-manager.service > /dev/null 2>&1 || :
+    /bin/systemctl stop openvas-manager.service > /dev/null 2>&1 || :
+fi
+
+%postun
+/bin/systemctl daemon-reload >/dev/null 2>&1 || :
+if [ $1 -ge 1 ] ; then
+    # Package upgrade, not uninstall
+    /bin/systemctl try-restart openvas-manager >/dev/null 2>&1 || :
+fi
+
+%triggerun -- openvas-manager < 2.0.4-3
+# Save the current service runlevel info
+# User must manually run systemd-sysv-convert --apply openvas-manager
+# to migrate them to systemd targets
+/usr/bin/systemd-sysv-convert --save openvas-manager >/dev/null 2>&1 ||:
+
+# Run these because the SysV package being removed won't do them
+/sbin/chkconfig --del openvas-manager >/dev/null 2>&1 || :
+/bin/systemctl try-restart openvas-manager.service >/dev/null 2>&1 || :
+
+
+
+%post sysvinit
 # This adds the proper /etc/rc*.d links for the script
 if [ "$1" -eq 1 ] ; then
 	/sbin/chkconfig --add openvas-manager
 fi
 
 
-%preun
+%preun sysvinit
 if [ "$1" -eq 0 ] ; then
 	/sbin/service openvas-manager stop >/dev/null 2>&1
 	/sbin/chkconfig --del openvas-manager
 fi
 
 
-%postun
+%postun sysvinit
 # only for upgrades not erasure
 if [ "$1" -eq 1 ] ; then
 	/sbin/service openvas-manager condrestart  >/dev/null 2>&1
@@ -128,13 +186,23 @@ fi
 %dir %{_datadir}/openvas
 %config(noreplace) %{_sysconfdir}/openvas/openvasmd_log.conf
 %config(noreplace) %{_sysconfdir}/sysconfig/%{name}
-%{_initrddir}/%{name}
+%{_unitdir}/%{name}.service
 %{_sbindir}/openvasmd
 %{_mandir}/man8/openvasmd.8*
 %{_datadir}/openvas/openvasmd
 %ghost %{_var}/log/openvas/openvasmd.log
 
+
+
+%files sysvinit
+%defattr(-,root,root)
+%{_initrddir}/%{name}
+
+
 %changelog
+* Mon Apr 10 2012 Michal Ambroz <rebus at, seznam.cz> - 2.0.4-3
+- migrate init scripts from sysvinit to systemd
+
 * Mon Jan 23 2012 Michal Ambroz <rebus at, seznam.cz> - 2.0.4-2
 - fix checking for the existence of the certificates in initscript
 


More information about the scm-commits mailing list