From fe8f979da5f51cff7021106dce8d88b2d0511402 Mon Sep 17 00:00:00 2001 From: Justin Cormack Date: Tue, 18 Jul 2017 11:41:57 +0100 Subject: [PATCH] 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 --- pkg/init/bin/rc.init | 2 +- pkg/init/bin/rc.shutdown | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pkg/init/bin/rc.init b/pkg/init/bin/rc.init index 54111f57b..7b5e65df8 100755 --- a/pkg/init/bin/rc.init +++ b/pkg/init/bin/rc.init @@ -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 diff --git a/pkg/init/bin/rc.shutdown b/pkg/init/bin/rc.shutdown index f91b45e26..02ae06587 100755 --- a/pkg/init/bin/rc.shutdown +++ b/pkg/init/bin/rc.shutdown @@ -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