3 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/sh --
  2. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  3. self="$(realpath "$0")"
  4. self="${self%/*}"
  5. [ -r "${self}/rc" ] && . "${self}/rc"
  6. [ -r "${self}/functions/core" ] && . "${self}/functions/core"
  7. : "${SVDIR:=/var/service}"
  8. [ -f /run/runit/printk ] && >/proc/sys/kernel/printk cat /run/runit/printk
  9. (
  10. cd "${SVDIR}" || return
  11. msg 'Waiting for getties to stop...'
  12. sv -w 10 force-shutdown ./getty-*
  13. msg 'Waiting for services to stop...'
  14. sv force-stop ./*
  15. sv exit ./*
  16. )
  17. for f in /etc/runit/shutdown-services/*.sh; do
  18. [ -f "$f" ] && . "$f"
  19. done
  20. halt -w
  21. msg 'Sending TERM signal to processes...'
  22. pkill --inverse -s0,1 -TERM
  23. sleep 0.5
  24. msg 'Sending KILL signal to processes...'
  25. pkill --inverse -s0,1 -KILL
  26. msg 'Unmounting filesystems, disabling swap...'
  27. swapoff -a
  28. umount -r -a -t nosysfs,noproc,nodevtmpfs,notmpfs
  29. msg 'Remounting rootfs read-only...'
  30. mount -o remount,ro /
  31. sync; sync
  32. for crypt in /sys/block/*/dm/uuid; do
  33. IFS=- read -r dm_type _ _ dm_name < "${crypt}"
  34. [ "${dm_type}" = CRYPT ] && cryptsetup close --deferred "${dm_name}"
  35. done
  36. msg 'Shutdown...'
  37. sleep 1
  38. if [ -e /etc/runit/reboot ] && command -v kexec >/dev/null; then
  39. msg "Triggering kexec..."
  40. kexec -e 2>/dev/null
  41. # not reached when kexec was successful.
  42. fi