Skip to content

Commit

Permalink
s6 initial prayer
Browse files Browse the repository at this point in the history
  • Loading branch information
akerl committed Dec 14, 2014
1 parent ed0375c commit 8ddd3aa
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 2 deletions.
14 changes: 14 additions & 0 deletions overlay/etc/s6/crash
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/command/execlineb -P

# This file is run when an unrecoverable error happens
# to s6-svscan. Edit it to suit your needs.

cd /
redirfd -r 0 /dev/console
redirfd -w 1 /dev/console
fdmove -c 2 1

foreground { s6-echo "s6-svscan panicked! Dropping to a root shell.\n" }

/bin/sh -i

1 change: 1 addition & 0 deletions overlay/etc/s6/env/PATH
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/usr/bin
39 changes: 39 additions & 0 deletions overlay/etc/s6/init-stage1
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/execlineb -P

# This file is the first program run at boot time,
# as process 1.
# Edit it to suit your needs.

# Make sure everything is sane and ignore input
cd /
umask 022
fdclose 0

/etc/s6/crash

# This should be printed to the console
if { s6-echo "* init stage 1" }


# Mount /sys and /proc
if { s6-mount -wt sysfs sys /sysfs }
if { s6-mount -wt proc proc /procfs }

# Close remaining handles to /dev/console
fdclose 1 fdclose 2

# Now no process has any open fd to /dev/console (or to
# anything for that matter).
# We can safely overwrite the minimal /dev with the real one.

# Reopen stdin/stdout/stderr and make them point to the right places
redirfd -r 0 /dev/null
redirfd -wnb 1 /service/s6-svscan-log/fifo # (black magic: doesn't block)
fdmove -c 2 1

# Load the general environment
s6-envdir /etc/s6/env

# Start stage 2.
s6-svscan -t0 /service

47 changes: 47 additions & 0 deletions overlay/etc/s6/init-stage3
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/command/execlineb -S0

# This is the shutdown script, running as process 1.

# Make sure we have no open handle to anywhere else
# than /dev/console
cd /
fdclose 0
redirfd -w 1 /dev/console
fdmove -c 2 1

foreground { s6-echo "Syncing disks." }
foreground { s6-sync }


# Even if s6-svscan properly brought all the services down
# before exec'ing into this script, users might have launched
# background nohup processes, so we have to kill everything.

foreground { s6-echo "Sending all processes the TERM signal." }
foreground { s6-nuke -th }
foreground { s6-sleep 1 }
foreground { s6-echo "Sending all processes the KILL signal." }
foreground { s6-nuke -k }

# Here, s6-nuke sends a SIGKILL to every process on the system.
# It kills itself, but not before the SIGKILL has been broadcast.
# The "foreground" process runs as process 1, so it survives,
# and execs into the rest of the script when s6-nuke dies.

# Reap the huge army of zombies we just created
wait { }


foreground { s6-echo "Syncing disks." }
foreground { s6-sync } # yes, it helps.
foreground { s6-echo "Unmounting disks." }

# Unmount all your filesystems here, turn off swap,
# remount / read-only if needed, etc.
# foreground { s6-umount /mnt/rwfs }

# Reboot, halt or poweroff the machine, depending on the parameter
# that was given to the script.
foreground { s6-echo "\nPerforming "${1}"." }
s6-${1}

1 change: 1 addition & 0 deletions overlay/service/.s6-svscan/crash
1 change: 1 addition & 0 deletions overlay/service/.s6-svscan/finish
1 change: 1 addition & 0 deletions overlay/usr/bin/init
2 changes: 0 additions & 2 deletions packages
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,3 @@ pacman
procps-ng
radvd
sed
systemd
systemd-sysvcompat

0 comments on commit 8ddd3aa

Please sign in to comment.