1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #!/bin/sh --
- PATH=/sbin:/usr/sbin:/bin:/usr/bin
- self="$(realpath "$0")"
- self="${self%/*}"
- [ -r "${self}/rc" ] && . "${self}/rc"
- [ -r "${self}/functions/core" ] && . "${self}/functions/core"
- : "${SVDIR:=/var/service}"
- [ -f /run/runit/printk ] && >/proc/sys/kernel/printk cat /run/runit/printk
- (
- cd "${SVDIR}" || return
- msg 'Waiting for getties to stop...'
- sv -w 10 force-shutdown ./getty-*
- msg 'Waiting for services to stop...'
- sv force-stop ./*
- sv exit ./*
- )
- for f in /etc/runit/shutdown-services/*.sh; do
- [ -f "$f" ] && . "$f"
- done
- halt -w
- msg 'Sending TERM signal to processes...'
- pkill --inverse -s0,1 -TERM
- sleep 0.5
- msg 'Sending KILL signal to processes...'
- pkill --inverse -s0,1 -KILL
- msg 'Unmounting filesystems, disabling swap...'
- swapoff -a
- umount -r -a -t nosysfs,noproc,nodevtmpfs,notmpfs
- msg 'Remounting rootfs read-only...'
- mount -o remount,ro /
- sync; sync
- for crypt in /sys/block/*/dm/uuid; do
- IFS=- read -r dm_type _ _ dm_name < "${crypt}"
- [ "${dm_type}" = CRYPT ] && cryptsetup close --deferred "${dm_name}"
- done
- msg 'Shutdown...'
- sleep 1
- if [ -e /etc/runit/reboot ] && command -v kexec >/dev/null; then
- msg "Triggering kexec..."
- kexec -e 2>/dev/null
- # not reached when kexec was successful.
- fi
|