Skip to content

Commit

Permalink
Convert RPM specfile from sysvinit to systemd
Browse files Browse the repository at this point in the history
This commit coverts the RPM specfile from sysvinit to systemd.
The requisite Requires & BuildRequires tags for systemd are added.
References to chkconfig and the sysvinit script are replaced with
corresponding helper macros to handle systemd scriptlet operations.
The sysvinit script and sysconfig file are replaced with the systemd
unit file and tmpfiles.d configuration file.

Furthermore, the %ghost tag is removed from the /var/run/munge
directory.  This tag was added back in commit 0f89429, at which
point the sysvinit script created this directory when the service
was started.  By removing the %ghost tag, this directory will be
created when the rpm is installed.  Since /var/run is (likely)
mounted as tmpfs, this directory will disappear on the next reboot,
at which point it will be re-created by tmpfiles.d.

The RuntimeDirectory and RuntimeDirectoryMode options in the service
file were added in systemd 211.  This is a clean and straightforward
manner in which to create private runtime directories below /run.
However, tmpfiles.d is being used instead since CentOS 7 ships with
systemd 208.

References:
- https://fedoraproject.org/wiki/Packaging:Systemd
- https://fedoraproject.org/wiki/Packaging:ScriptletSnippets
- https://fedoraproject.org/wiki/Packaging:Tmpfiles.d

Tested on:
- CentOS 7
- Fedora 20-23

Signed-off-by: Chris Dunlap <[email protected]>
Closes #33
Closes #43
Issue #27
Issue #36
Issue #39
  • Loading branch information
dun committed Dec 22, 2015
1 parent b0f993f commit d034b3a
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions munge.spec
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ Requires: %{name}-libs = %{version}-%{release}
BuildRequires: bzip2-devel
BuildRequires: openssl-devel
BuildRequires: zlib-devel
BuildRequires: systemd
BuildRoot: %{_tmppath}/%{name}-%{version}

Source0: %{name}-%{version}.tar.bz2

Requires(pre): shadow-utils
Requires(post): systemd
Requires(preun): systemd
Requires(postun): systemd

%package devel
Summary: Headers and libraries for developing applications using MUNGE
Expand Down Expand Up @@ -67,6 +71,8 @@ touch "$RPM_BUILD_ROOT"/%{_sysconfdir}/munge/munge.key
touch "$RPM_BUILD_ROOT"/%{_localstatedir}/lib/munge/munge.seed
touch "$RPM_BUILD_ROOT"/%{_localstatedir}/log/munge/munged.log
touch "$RPM_BUILD_ROOT"/%{_localstatedir}/run/munge/munged.pid
rm -f "$RPM_BUILD_ROOT"/%{_sysconfdir}/sysconfig/munge
rm -f "$RPM_BUILD_ROOT"/%{_initddir}/munge

%clean
rm -rf "$RPM_BUILD_ROOT"
Expand Down Expand Up @@ -98,21 +104,16 @@ if [ -f /var/lock/subsys/munged ]; then
/bin/mv /var/lock/subsys/munged /var/lock/subsys/munge
fi
##
if [ -x /sbin/chkconfig ]; then /sbin/chkconfig --add munge; fi
%systemd_post munge.service

%post libs
/sbin/ldconfig %{_libdir}

%preun
if [ $1 -eq 0 ]; then
%{_sysconfdir}/init.d/munge stop >/dev/null 2>&1 || :
if [ -x /sbin/chkconfig ]; then /sbin/chkconfig --del munge; fi
fi
%systemd_preun munge.service

%postun
if [ $1 -ge 1 ]; then
%{_sysconfdir}/init.d/munge try-restart >/dev/null 2>&1 || :
fi
%systemd_postun_with_restart munge.service

%postun libs
/sbin/ldconfig %{_libdir}
Expand All @@ -132,17 +133,17 @@ fi
%doc doc/*
%dir %attr(0700,munge,munge) %{_sysconfdir}/munge
%attr(0600,munge,munge) %config(noreplace) %ghost %{_sysconfdir}/munge/munge.key
%config(noreplace) %{_sysconfdir}/sysconfig/munge
%{?_initddir:%{_initddir}}%{!?_initddir:%{_initrddir}}/munge
%dir %attr(0711,munge,munge) %{_localstatedir}/lib/munge
%attr(0600,munge,munge) %ghost %{_localstatedir}/lib/munge/munge.seed
%dir %attr(0700,munge,munge) %{_localstatedir}/log/munge
%attr(0640,munge,munge) %ghost %{_localstatedir}/log/munge/munged.log
%dir %attr(0755,munge,munge) %ghost %{_localstatedir}/run/munge
%dir %attr(0755,munge,munge) %{_localstatedir}/run/munge
%attr(0644,munge,munge) %ghost %{_localstatedir}/run/munge/munged.pid
%{_bindir}/*
%{_sbindir}/*
%{_mandir}/*[^3]/*
%{_tmpfilesdir}/munge.conf
%{_unitdir}/munge.service

%files devel
%defattr(-,root,root,0755)
Expand Down

0 comments on commit d034b3a

Please sign in to comment.