diff --git a/src/packaging/RedHat/openafs-client-systemd-helper.sh b/src/packaging/RedHat/openafs-client-systemd-helper.sh index 00f6e7cbc3..32221ef716 100755 --- a/src/packaging/RedHat/openafs-client-systemd-helper.sh +++ b/src/packaging/RedHat/openafs-client-systemd-helper.sh @@ -8,26 +8,58 @@ set -e [ -f /etc/sysconfig/openafs ] && . /etc/sysconfig/openafs case $1 in - ExecStartPre) + ExecStart) if fs sysname >/dev/null 2>&1 ; then - echo AFS client appears to be running -- not starting - exit 1 + # If we previously tried to stop the client and failed (because + # e.g. /afs was in use), our unit will be deactivated but the + # client will keep running. So if we're starting up, but the client + # is currently running, do not perform the startup sequence but + # just return success, to let the unit activate, so stopping the + # unit can go through the shutdown sequence again. + echo AFS client appears to be running -- skipping startup + exit 0 fi sed -n 'w/usr/vice/etc/CellServDB' /usr/vice/etc/CellServDB.local /usr/vice/etc/CellServDB.dist chmod 0644 /usr/vice/etc/CellServDB - exec /sbin/modprobe openafs - ;; - ExecStart) + # If the kernel module is already initialized from a previous client + # run, it must be unloaded and loaded again. So if the module is + # currently loaded, unload it in case it was (partly) initialized. + if lsmod | grep -wq ^openafs ; then + /sbin/rmmod --verbose openafs + fi + /sbin/modprobe --verbose openafs exec /usr/vice/etc/afsd $AFSD_ARGS ;; ExecStop) - /bin/umount /afs || true + if /bin/umount --verbose /afs ; then + exit 0 + else + echo "Failed to unmount /afs: $?" + fi + exit 1 + ;; + + ExecStopPost) /usr/vice/etc/afsd -shutdown || true - exec /sbin/rmmod openafs + /sbin/rmmod --verbose openafs || true + if lsmod | grep -wq ^openafs ; then + echo "Cannot unload the OpenAFS client kernel module." + echo "systemd will consider the openafs-client.service unit inactive, but the AFS client may still be running." + echo "To stop the client, stop all access to /afs, and then either:" + echo "stop the client manually:" + echo " umount /afs" + echo " rmmod openafs" + echo "or start and stop the openafs-client.service unit:" + echo " systemctl start openafs-client.service" + echo " systemctl stop openafs-client.service" + echo 'See "journalctl -u openafs-client.service" for details.' + exit 1 + fi + exit 0 ;; esac -echo "Usage: $0 {ExecStartPre|ExecStart|ExecStop}" >&2 +echo "Usage: $0 {ExecStart|ExecStop|ExecStopPost}" >&2 exit 1 diff --git a/src/packaging/RedHat/openafs-client.service b/src/packaging/RedHat/openafs-client.service index 89069cdb8f..5036709f3e 100644 --- a/src/packaging/RedHat/openafs-client.service +++ b/src/packaging/RedHat/openafs-client.service @@ -7,9 +7,9 @@ Before=remote-fs.target [Service] Type=forking RemainAfterExit=true -ExecStartPre=/usr/vice/etc/openafs-client-systemd-helper.sh ExecStartPre ExecStart= /usr/vice/etc/openafs-client-systemd-helper.sh ExecStart ExecStop= /usr/vice/etc/openafs-client-systemd-helper.sh ExecStop +ExecStopPost=/usr/vice/etc/openafs-client-systemd-helper.sh ExecStopPost KillMode=process GuessMainPID=no SendSIGKILL=no