Scripting Stage 3 and 4

From: Paul Sopka <psopka_at_sopka.ch>
Date: Thu, 9 Jan 2025 21:25:45 +0100

Hey everybody,

I scripted shutdown stage 3 and 4 based on s6-linux-init-shutdownd and
it works quite well,
even though being VERY rough around the edges currently:
(Linux-powertool is a minimal program that just makes the syscall to
halt, poweroff or reboot)

| #!/bin/execlineb -P
|
| multisubstitute {
|     importas -SD /etc/s6-rc G6CONFIGDIR
|     importas -SD /run G6LIVEDIR
| }
|
| fdmove -c 2 1
| redirfd -w 1 /dev/console
| redirfd -r 0 /dev/null
|
| tryexec { ./stage3b }
|
| foreground { rm -f fifo }
| foreground { mkfifo -m 0700 fifo }
| foreground { fdmove 1 3 echo "" }
| redirfd -r 0 fifo
| withstdinas -E DIRECTIVE
|
| if { eltest \\\\${DIRECTIVE} =~ ^-[hpr]$ }
|
| foreground { s6-rc -l ${G6LIVEDIR}/s6-rc -v2 -bDa -t 10000 change }
| foreground {
|     pipeline { ls -1 ${G6LIVEDIR}/service/ }
|     pipeline { sed /g6-shutdown/d }
|     forstdin -pE SERVICE
|         mv -f ${G6LIVEDIR}/service/${SERVICE}
${G6LIVEDIR}/service/.${SERVICE}
| }
| foreground { s6-svscanctl -h ${G6LIVEDIR}/service }
|
| foreground {
|     redirfd -w 1 stage3b
|     echo "#!/bin/execlineb
|         tryexec { ./stage4 }
|         foreground { mv stage4p stage4 }
|         foreground { kill -SIGCONT -- -1 }
|         foreground { sleep 1 }
|         foreground { echo sending all processes the KILL signal... }
|         foreground { kill -SIGKILL -- -1 }"
| }
| foreground { chmod o+x stage3b }
|
| foreground {
|     redirfd -w 1 stage4p
|     echo "#!/bin/execlineb
|         foreground { mount -o remount,ro / }
|         foreground { umount -a }
|         linux-powertool ${DIRECTIVE}"
| }
| foreground { chmod o+x stage4p }
|
| foreground { echo "sending all processes the TERM signal..." }
| foreground { kill -SIGTERM -- -1 }

Now I was wondering why you, Laurent recommend against using the finish
script of s6-svscan
for the shutdown procedure (here:
https://skarnet.org/software/s6/s6-svscan-1.html#stage3).

Using that would make good portion of my implementation more elegant and
simple,
especially all the dance around creating scripts to be ran by "tryexec"
after being restarted upon being signaled to stop...

I figured that other people might also have some interest in this,
so I am posting the question here.

Regards,

Paul

Received on Thu Jan 09 2025 - 21:25:45 CET

This archive was generated by hypermail 2.4.0 : Thu Jan 09 2025 - 21:26:25 CET