Journey to s6-svscan as PID 1 on FreeBSD (almost there)

From: Dewayne Geraghty <>
Date: Thu, 8 Apr 2021 23:15:48 +1000

First we started with the documented approach of appending to /etc/ttys
"" "/usr/local/bin/s6-svscan /run/scan" "" on

Which worked nicely under FreeBSD's /sbin/init.

Then we added to loader.conf an init_script which is invoked via
/sbin/init. This also
worked well, but init remained as pid 1. The init_script variable is
defined in /boot/loader.conf, in my case as:
/sbin/init calls "init_script"

This ran nicely, but still under init as pid=1.

Finally I sucked up the courage and defined in /boot/loader.conf
which contains
#!/usr/local/bin/execlineb -S0
redirfd -wnb 1 /m/fifo/catch_all
redirfd -r - /dev/null
fdmove -c 2 1
exec -c /sbin/s6/svscan -t 0 -s /s/scan

And finally /sbin/s6-svscan runs as pid 1.

I'm very pleased with the result except... after a reboot, I have to
fsck -y /
because when I shutdown, the system crashes due to pid 1 being killed.

At the moment I have
/s/scan/.s6-svscan/SIGTERM and /s/scan/.s6-svscan/finish containing
#!/usr/local/bin/execlineb -S0
foreground { /bin/sync }
foreground { /sbin/mount -ur / }
foreground { /sbin/shutdown -o -r now } # this invokes reboot rather
than send a signal to init.

I'd greatly appreciate advice as to completing a clean shutdown?

(FYI for other FreeBSD folk, I hacked the order of calling init_script
then init_exec in init.c because the order is incorrect - I'll pursue
with the FreeBSD devs. Its only a few lines moved around. I use
init_script to prepare the environment for init_exec, though it could
all be done within init_exec script.)

Regards, Dewayne
PS This journey commenced with the simple wish to safely rotate apache
logs, now I'm hooked on s6-rc (and the peace of mind it brings)
Received on Thu Apr 08 2021 - 13:15:48 UTC

This archive was generated by hypermail 2.3.0 : Sun May 09 2021 - 19:38:49 UTC