linux: Update Packaging to build OpenAFS services for Fedora's systemd
authorEdward Z. Yang <ezyang@mit.edu>
Tue, 18 Oct 2011 03:16:15 +0000 (23:16 -0400)
committerDerrick Brashear <shadow@dementix.org>
Thu, 27 Oct 2011 23:54:46 +0000 (16:54 -0700)
Fedora 15 now uses systemd (see http://fedoraproject.org/wiki/Systemd)
for the OS init system. While it currently has backwards
compatibility with older SysV-style init scripts, future versions of
Fedora may no longer support it, and OS startup tends to be faster
with the systemd service units. Also, systemd runs all the service's
processes within a linux kernel cgroup.
(see http://www.kernel.org/doc/Documentation/cgroups/cgroups.txt)

This change includes an openafs-client.service and
openafs-server.service unit files for the client and server packages
respectively.

Client
- Loading the openafs module was moved into
/etc/sysconfig/modules/openafs-client.modules. This causes the OS to
load the module on boot. This is the preferred way for modules to be
loaded with Fedora. (See
http://docs.fedoraproject.org/en-US/Fedora/15/html/Deployment_Guide/sec-Persistent_Module_Loading.html
for more details)
- The CellServDB file is generated with sed rather than cat.
This change was made because Systemd doesn't execute as a shell
script, but rather executes processes directly. Rather than invoking
a shell to concatenate the CellServDB.* files, they're written to the
CellServDB file using a sed oneliner.
- Do all of the proper kernel module loading and unloading.

Server
- Since systemd uses cgroups, when the service is shut down, all
processes in the openafs-server.service cgroup will be terminated.

The other changes are standard as per:
    http://fedoraproject.org/wiki/Packaging:ScriptletSnippets#Systemd

Original version by Jonathan Billings <jsbillin@umich.edu>.

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>

Change-Id: Ifb41790ffe107b319097b9750273aecfe82c3349
Reviewed-on: http://gerrit.openafs.org/5637
Reviewed-by: Derrick Brashear <shadow@dementix.org>
Reviewed-by: Alex Chernyakhovsky <achernya@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>

src/packaging/RedHat/openafs-client.modules [new file with mode: 0644]
src/packaging/RedHat/openafs-client.service [new file with mode: 0644]
src/packaging/RedHat/openafs-server.service [new file with mode: 0644]
src/packaging/RedHat/openafs.spec.in

diff --git a/src/packaging/RedHat/openafs-client.modules b/src/packaging/RedHat/openafs-client.modules
new file mode 100644 (file)
index 0000000..055d117
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+# Load the OpenAFS kernel module at boot
+exec /sbin/modprobe openafs
diff --git a/src/packaging/RedHat/openafs-client.service b/src/packaging/RedHat/openafs-client.service
new file mode 100644 (file)
index 0000000..bc95057
--- /dev/null
@@ -0,0 +1,18 @@
+[Unit]
+Description=OpenAFS Client Service
+After=syslog.target network.target
+
+[Service]
+Type=forking
+EnvironmentFile=/etc/sysconfig/openafs
+ExecStartPre=/bin/sed -n 'w/usr/vice/etc/CellServDB' /usr/vice/etc/CellServDB.local /usr/vice/etc/CellServDB.dist
+ExecStartPre=/bin/chmod 0644 /usr/vice/etc/CellServDB
+ExecStartPre=/sbin/modprobe openafs
+ExecStart=/usr/vice/etc/afsd $AFSD_ARGS
+ExecStop=/bin/umount /afs
+ExecStop=/usr/vice/etc/afsd -shutdown
+ExecStop=/sbin/rmmod openafs
+KillMode=none
+
+[Install]
+WantedBy=multi-user.target
diff --git a/src/packaging/RedHat/openafs-server.service b/src/packaging/RedHat/openafs-server.service
new file mode 100644 (file)
index 0000000..2d34bb0
--- /dev/null
@@ -0,0 +1,11 @@
+[Unit]
+Description=OpenAFS Server Service
+After=syslog.target network.target
+
+[Service]
+EnvironmentFile=-/etc/sysconfig/openafs
+ExecStart=/usr/afs/bin/bosserver $BOSSERVER_ARGS
+ExecStop=/usr/bin/bos shutdown localhost -wait -localauth
+
+[Install]
+WantedBy=multi-user.target
index ed4ac23..f09d5d5 100644 (file)
@@ -224,7 +224,7 @@ URL: http://www.openafs.org
 BuildRoot: %{_tmppath}/%{name}-%{version}-root
 Packager: OpenAFS Gatekeepers <openafs-gatekeepers@openafs.org>
 Group: Networking/Filesystems
-BuildRequires: %{?kdepend:%{kdepend}, } pam-devel, ncurses-devel, flex, bison
+BuildRequires: %{?kdepend:%{kdepend}, } pam-devel, ncurses-devel, flex, bison, systemd-units
 BuildRequires: perl-devel perl-ExtUtils-Embed
 %if %{krb5support}
 BuildRequires: krb5-devel
@@ -311,6 +311,13 @@ To a kernel module for your running kernel, just run:
 
 %package client
 Requires: binutils, openafs = %{version}
+%if 0%{?fedora} >= 15
+Requires: systemd-units
+BuildRequires: systemd-units
+Requires(post): systemd-units, systemd-sysv
+Requires(preun): systemd-units
+Requires(postun): systemd-units
+%endif
 
 %if %{fedorakmod}
 Requires: %{name}-kmod >= %{version}
@@ -335,6 +342,13 @@ AFS.
 Requires: openafs = %{version}
 Summary: OpenAFS Filesystem Server
 Group: Networking/Filesystems
+%if 0%{?fedora} >= 15
+Requires: systemd-units
+BuildRequires: systemd-units
+Requires(post): systemd-units, systemd-sysv
+Requires(preun): systemd-units
+Requires(postun): systemd-units
+%endif
 
 %description server
 The AFS distributed filesystem.  AFS is a distributed filesystem
@@ -977,7 +991,12 @@ esac
 mkdir -p $RPM_BUILD_ROOT%{_sbindir}
 mkdir -p $RPM_BUILD_ROOT%{_libdir}
 mkdir -p $RPM_BUILD_ROOT/etc/sysconfig
+%if 0%{?fedora} < 15
 mkdir -p $RPM_BUILD_ROOT%{initdir}
+%else
+mkdir -p $RPM_BUILD_ROOT%{_unitdir}
+mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/modules
+%endif
 mkdir -p $RPM_BUILD_ROOT/etc/openafs
 mkdir -p $RPM_BUILD_ROOT%{pamdir}
 mkdir -p $RPM_BUILD_ROOT%{_prefix}/afs/etc
@@ -1007,8 +1026,14 @@ ln -f $RPM_BUILD_ROOT%{_bindir}/kpasswd $RPM_BUILD_ROOT%{_bindir}/kapasswd
 
 # Copy root.client config files
 install -m 755 src/packaging/RedHat/openafs.sysconfig $RPM_BUILD_ROOT/etc/sysconfig/openafs
+%if 0%{?fedora} < 15
 install -m 755 src/packaging/RedHat/openafs-client.init $RPM_BUILD_ROOT%{initdir}/openafs-client
 install -m 755 src/packaging/RedHat/openafs-server.init $RPM_BUILD_ROOT%{initdir}/openafs-server
+%else
+install -m 755 src/packaging/RedHat/openafs-client.service $RPM_BUILD_ROOT%{_unitdir}/openafs-client.service
+install -m 755 src/packaging/RedHat/openafs-client.modules $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/modules/openafs-client.modules
+install -m 755 src/packaging/RedHat/openafs-server.service $RPM_BUILD_ROOT%{_unitdir}/openafs-server.service
+%endif
 
 # Copy PAM modules
 install -m 755 ${sysname}/dest/lib/pam* $RPM_BUILD_ROOT%{pamdir}
@@ -1283,7 +1308,14 @@ if [ -e %{_prefix}/afsws ]; then
 fi
 
 %post client
+%if 0%{?fedora} < 15
 chkconfig --add openafs-client
+%else
+if [ $1 -eq 1 ] ; then 
+    # Initial installation 
+    /bin/systemctl daemon-reload >/dev/null 2>&1 || :
+fi
+%endif
 if [ ! -d /afs ]; then
        mkdir /afs
        chown root.root /afs
@@ -1300,10 +1332,17 @@ fi
 
 %post server
 #on an upgrade, don't enable if we were disabled
+%if 0%{?fedora} < 15
 if [ $1 = 1 ] ; then
   chkconfig --add openafs-server
 fi
 %{initdir}/openafs-server condrestart
+%else
+if [ $1 -eq 1 ] ; then 
+    # Initial installation 
+    /bin/systemctl daemon-reload >/dev/null 2>&1 || :
+fi
+%endif
 
 %if %{build_authlibs}
 %post authlibs
@@ -1319,16 +1358,45 @@ if [ $1 = 0 ] ; then
 fi
 
 %preun client
+%if 0%{?fedora} < 15
 if [ $1 = 0 ] ; then
         %{initdir}/openafs-client stop
         chkconfig --del openafs-client
 fi
+%else
+if [ $1 -eq 0 ] ; then
+       # Package removal, not upgrade
+       /bin/systemctl --no-reload disable openafs-client.service > /dev/null 2>&1 || :
+       /bin/systemctl stop openafs-client.service > /dev/null 2>&1 || :
+fi
+%endif
 
 %preun server
+%if 0%{?fedora} < 15
 if [ $1 = 0 ] ; then
         %{initdir}/openafs-server stop
         chkconfig --del openafs-server
 fi
+%else
+if [ $1 -eq 0 ] ; then
+       /bin/systemctl --no-reload disable openafs-server.service > /dev/null 2>&1 || :
+       /bin/systemctl stop openafs-server.service > /dev/null 2>&1 || :
+fi
+%endif
+
+%postun client
+/bin/systemctl daemon-reload >/dev/null 2>&1 || :
+if [ $1 -ge 1 ] ; then
+    # Package upgrade, not uninstall
+    /bin/systemctl try-restart openafs-client.service >/dev/null 2>&1 || :
+fi
+
+%postun server
+/bin/systemctl daemon-reload >/dev/null 2>&1 || :
+if [ $1 -ge 1 ] ; then
+    # Package upgrade, not uninstall
+    /bin/systemctl try-restart openafs-server.service >/dev/null 2>&1 || :
+fi
 
 %if %{build_dkmspkg}
 %post -n dkms-%{name}
@@ -1386,6 +1454,32 @@ dkms remove -m %{name} -v %{dkms_version} --rpm_safe_upgrade --all ||:
 %endif
 %endif
 
+%triggerun -- openafs-client < 1.6.0-1
+# Save the current service runlevel info
+# User must manually run systemd-sysv-convert --apply httpd
+# to migrate them to systemd targets
+/usr/bin/systemd-sysv-convert --save openafs-client >/dev/null 2>&1 ||:
+
+# If the package is allowed to autostart:
+/bin/systemctl --no-reload enable openafs-client.service >/dev/null 2>&1 ||:
+
+# Run these because the SysV package being removed won't do them
+/sbin/chkconfig --del openafs-client >/dev/null 2>&1 || :
+/bin/systemctl try-restart openafs-client.service >/dev/null 2>&1 || : 
+
+%triggerun -- openafs-server < 1.6.0-1
+# Save the current service runlevel info
+# User must manually run systemd-sysv-convert --apply httpd
+# to migrate them to systemd targets
+/usr/bin/systemd-sysv-convert --save openafs-server >/dev/null 2>&1 ||:
+
+# If the package is allowed to autostart:
+/bin/systemctl --no-reload enable openafs-server.service >/dev/null 2>&1 ||:
+
+# Run these because the SysV package being removed won't do them
+/sbin/chkconfig --del openafs-server >/dev/null 2>&1 || :
+/bin/systemctl try-restart openafs-server.service >/dev/null 2>&1 || : 
+
 ##############################################################################
 ###
 ### file lists
@@ -1426,7 +1520,12 @@ dkms remove -m %{name} -v %{dkms_version} --rpm_safe_upgrade --all ||:
 %{pamdir}/pam_afs.krb.so
 %{pamdir}/pam_afs.so.1
 %{pamdir}/pam_afs.so
+%if 0%{?fedora} < 15
 %{initdir}/openafs-client
+%else
+%{_unitdir}/openafs-client.service
+%{_sysconfdir}/sysconfig/modules/openafs-client.modules
+%endif
 %{_mandir}/man1/cmdebug.*
 %{_mandir}/man1/copyauth.*
 %{_mandir}/man1/up.*
@@ -1474,7 +1573,11 @@ dkms remove -m %{name} -v %{dkms_version} --rpm_safe_upgrade --all ||:
 %{_sbindir}/vldb_check
 %{_sbindir}/vldb_convert
 %{_sbindir}/voldump
+%if 0%{?fedora} < 15
 %{initdir}/openafs-server
+%else
+%{_unitdir}/openafs-server.service
+%endif
 %{_mandir}/man5/AuthLog.*
 %{_mandir}/man5/BackupLog.*
 %{_mandir}/man5/BosConfig.*