Knowledge Base

Preserving for the future: Shell scripts, AoC, and more

Devuan: fix rsyslog hang on shutdown

I use nfs mounts in my GNU/Linux network. I should investigate using freeipa-defined autofs mounts, but I have never gotten around to that. For now, I still use hardcoded entries in /etc/fstab on all systems.

I finally bothered to research why rsyslog tends to hang at shutdown/reboot of my Devuan GNU+Linux systems. Its dependencies are out of order with unmounting nfs! Perhaps the authors of the rsyslog init script think that rsyslog writes to an nfs location. If I were to ship logs elsewhere, I think I would use native rsyslog network capabilities and not depend on the filesystem.

So, by writing a custom init script adapted from /etc/init.d/umountnfs.sh, I can get my systems to shutdown correctly instead of hanging for an indeterminate amount of time (sometimes until I forcefully power off).

See downloadable file stackrmps-nfs.sh, whose contents are also listed inline here. Observe that I have added to Should-Stop (so stop this service file before stopping each of these listed services) items connman and wicd, which are various network managers I've used. Wicd was fine, until python2 was removed because it was way past EOL. Connman is OK, and is only slightly better than wicd was.

#!/bin/sh
# File: /etc/init.d/stackrpms-nfs.sh
# Author: bgstack15
# Startdate: 2022-05-01
# Usage:
#    After deploying this file, run `update-rc.d stackrpms-nfs.sh defaults`
# Reference:
#    https://wiki.debian.org/LSBInitScripts/
#    https://forums.debian.net/viewtopic.php?t=70798&start=30
### BEGIN INIT INFO
# Provides:          stackrpms-umountnfs
# Required-Start:
# Required-Stop:     
# Should-Stop:       $network $portmap nfs-common connman wicd
# Default-Start:
# Default-Stop:      0 6
# Short-Description: Unmount my nfs mounts
# Description:       Customized for stackrpms usage from umountnfs.sh
# chkconfig: 2 100 0
### END INIT INFO
PATH=/usr/sbin:/usr/bin:/sbin:/bin
KERNEL="$(uname -s)"
RELEASE="$(uname -r)"
. /lib/init/vars.sh
. /lib/lsb/init-functions
do_stop () {
   for word in $( mount | awk '/type nfs/{print $3}' | sort -r ) ;
   do
      umount --lazy --force "${word}" &
   done
   # for good measure
   sleep 1
   :
}
case "$1" in
  start|status)
    # No-op
    ;;
  restart|reload|force-reload)
    echo "Error: argument '$1' not supported" >&2
    exit 3
    ;;
  stop|"")
    do_stop
    ;;
  *)
    echo "Usage: stackrpms-nfs.sh [start|stop]" >&2
    exit 3
    ;;
esac
:

References

  1. shutdown hangs stopping enhanced syslogd: rsyslogd - Page 2 - Debian User Forums

Comments