supervision - discussion about system services, daemon supervision, init, runlevel management, and tools such as s6 and runit
 help / color / mirror / Atom feed
* Scripting Stage 3 and 4
@ 2025-01-09 20:25 Paul Sopka
  2025-01-09 23:19 ` Laurent Bercot
  2025-01-11 13:22 ` Guillermo
  0 siblings, 2 replies; 7+ messages in thread
From: Paul Sopka @ 2025-01-09 20:25 UTC (permalink / raw)
  To: supervision


[-- Attachment #1.1.1: Type: text/plain, Size: 2451 bytes --]

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


[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3195 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-01-11 15:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-09 20:25 Scripting Stage 3 and 4 Paul Sopka
2025-01-09 23:19 ` Laurent Bercot
2025-01-11  8:30   ` Paul Sopka
2025-01-11 12:21     ` Re[2]: " Laurent Bercot
2025-01-11 15:15       ` Paul Sopka
2025-01-11 13:22 ` Guillermo
2025-01-11 15:29   ` Paul Sopka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).