commit ae31bfb40875e55c736f0cf962f9f0b8e73fba2a Author: mrgrouse <bdmfegys@duck.com> Date: Mon, 21 Jul 2025 00:25:52 -0400 create (UNTESTED) rc.shutdown execline script; create sinit directory Diffstat:
| A | sinit/rc.shutdown | | | 76 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 76 insertions(+), 0 deletions(-)
diff --git a/sinit/rc.shutdown b/sinit/rc.shutdown @@ -0,0 +1,76 @@ +#!/bin/execlineb -S1 + +# creating new files +# execline provides `posix-umask` and `execline-umask` +# at the moment i just use posix but will change it if i am wrong +posix-umask 022 + +# getting env vars +envfile /etc/rc.conf + +case -N -- $1 +{ + "reboot" {} + + "poweroff" {} + +# may not work as execline treats globs as characters typically + "*" {foreground { printf "Invalid option '%s' for %s" $1 $0 } exit 1 } +} + +# set linefeed mode to avoid staircase effect +foreground { echo } +foreground { /bin/stty onclr } + +background { printf "Shutting down...\n" } + +define hwclock_params "-w" + +case -N -- $HARDWARECLOCK +{ + "" {} + "UTC" { HW } #FIXME + "localtime" { define hwclock_params "-l ${hwclock_params}" } + "*" { define hwclock_params "" } +} + +if { eltest -n $hwclock_params } +{ + background { printf "Saving System Clock\n" } + foreground { + if { eltest -n $TIMEZONE } + { export TZ $TIMEZONE } + } + if { /bin/hwclock ${hwclock_params} /dev/rtc0 } + { unexport TZ } +} + +background { /bin/printf "Storing random seed...\n" } + +foreground { redirfd -w 2 /dev/null { /bin/dd if=/dev/urandom of=/etc/random-seed count=1 bs=512 } } + +background { /bin/printf "Stopping all svc services...\n" } +foreground { /bin/svc -k } + +background { /bin/printf "Sending TERM to all processes...\n" } +foreground { /bin/killall5 -s TERM } +foreground { sleep 2 } + +background { /bin/printf "Sending KILL to all processes...\n" } +foreground { /bin/killall5 -s KILL } + +background { /bin/printf "Remounting / as read-only...\n" } +foreground { /bin/mount -o remount,ro / } + +background { /bin/printf "Unmounting all fs'es...\n" } +foreground { /bin/umount -a } +foreground { /bin/sync } +foreground { /bin/sleep 2 } +foreground { wait {} } + +background { /bin/printf "BYE BYE!!! \n" } +case -N -- $1 +{ + "reboot" { /bin/halt -r } + "poweroff" { /bin/halt -p } +}