Add support for shutdown scripts

These can be added by other packages if they need to do something on
clean shutdown.

Crash only software can ignore this.

Signed-off-by: Justin Cormack <justin.cormack@docker.com>
This commit is contained in:
Justin Cormack 2017-07-18 11:41:57 +01:00
parent 90d1866bdc
commit fe8f979da5
2 changed files with 11 additions and 4 deletions

View File

@ -119,7 +119,7 @@ ulimit -n 1048576
ulimit -p unlimited
# execute other init processes
INITS="$(find /etc/init.d -type f | sort)"
INITS="$(find /etc/init.d -type f 2>/dev/null | sort)"
for f in $INITS
do
$f

View File

@ -1,13 +1,20 @@
#!/bin/sh
[ "$1" = "reboot" ] && exec /sbin/reboot
# poweroff
# execute other shutdown processes
SHUTS="$(find /etc/shutdown.d -type f 2>/dev/null | sort)"
for f in $SHUTS
do
$f
done
# kill all processes and unmount filesystems
/usr/sbin/killall5 -15
/bin/sleep 5
/usr/sbin/killall5 -9
/sbin/swapoff -a
/bin/echo "Unmounting filesystems"
/bin/umount -a -r
# shutdown or reboot
[ "$1" = "reboot" ] && exec /sbin/reboot -f
/sbin/poweroff -f