summaryrefslogtreecommitdiff
path: root/examples/ROOT/etc/s6-init
diff options
context:
space:
mode:
Diffstat (limited to 'examples/ROOT/etc/s6-init')
-rw-r--r--examples/ROOT/etc/s6-init/README9
-rwxr-xr-xexamples/ROOT/etc/s6-init/crash13
-rw-r--r--examples/ROOT/etc/s6-init/env/PATH1
-rw-r--r--examples/ROOT/etc/s6-init/env/README6
l---------examples/ROOT/etc/s6-init/init1
-rwxr-xr-xexamples/ROOT/etc/s6-init/init-stage158
-rwxr-xr-xexamples/ROOT/etc/s6-init/init-stage241
-rwxr-xr-xexamples/ROOT/etc/s6-init/init-stage346
-rwxr-xr-xexamples/ROOT/etc/s6-init/network-config5
9 files changed, 180 insertions, 0 deletions
diff --git a/examples/ROOT/etc/s6-init/README b/examples/ROOT/etc/s6-init/README
new file mode 100644
index 0000000..7e104fd
--- /dev/null
+++ b/examples/ROOT/etc/s6-init/README
@@ -0,0 +1,9 @@
+This is an example directory containing booting scripts
+that lead to s6-svscan running as process 1 in stage 2.
+
+Read them carefully and edit them to suit your needs.
+Some scripts are Linux-dependent; they can be easily
+adapted to other Unix systems.
+
+The skarnet.org servers actually run such a system, with
+scripts that are based on this model.
diff --git a/examples/ROOT/etc/s6-init/crash b/examples/ROOT/etc/s6-init/crash
new file mode 100755
index 0000000..501e316
--- /dev/null
+++ b/examples/ROOT/etc/s6-init/crash
@@ -0,0 +1,13 @@
+#!/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
diff --git a/examples/ROOT/etc/s6-init/env/PATH b/examples/ROOT/etc/s6-init/env/PATH
new file mode 100644
index 0000000..a4c496e
--- /dev/null
+++ b/examples/ROOT/etc/s6-init/env/PATH
@@ -0,0 +1 @@
+/command:/usr/bin:/bin:/usr/sbin:/sbin
diff --git a/examples/ROOT/etc/s6-init/env/README b/examples/ROOT/etc/s6-init/env/README
new file mode 100644
index 0000000..6c84e3b
--- /dev/null
+++ b/examples/ROOT/etc/s6-init/env/README
@@ -0,0 +1,6 @@
+
+This directory is read by s6-envdir at boot time.
+It contains environment variables that will be present in
+all the supervision tree, and all the launched services.
+Make sure to remove this file, or else you'll have a
+README environment variable in all your daemons. :)
diff --git a/examples/ROOT/etc/s6-init/init b/examples/ROOT/etc/s6-init/init
new file mode 120000
index 0000000..4ac5fd9
--- /dev/null
+++ b/examples/ROOT/etc/s6-init/init
@@ -0,0 +1 @@
+init-stage1 \ No newline at end of file
diff --git a/examples/ROOT/etc/s6-init/init-stage1 b/examples/ROOT/etc/s6-init/init-stage1
new file mode 100755
index 0000000..ea946e9
--- /dev/null
+++ b/examples/ROOT/etc/s6-init/init-stage1
@@ -0,0 +1,58 @@
+#!/command/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
+
+# This should be printed to the console
+if { s6-echo "* init stage 1" }
+
+
+# Mount /sys and /proc
+if { s6-mount -wt sysfs sys /mnt/sysfs }
+if { s6-mount -wt proc proc /mnt/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.
+
+# in case some Linux kernel has mounted a devtmpfs
+foreground { s6-umount /mnt/tmpfs/dev }
+
+# Make the tmpfs
+if { s6-mount -wt tmpfs -o mode=0755,size=67108864 tmpfs /mnt/tmpfs }
+
+# Copy the image to the tmpfs
+if { s6-hiercopy /img/tmpfs /mnt/tmpfs }
+
+# Now we have a working /dev and /tmp, and a minimal writable /service
+# with a catch-all logger and a getty. We're good for stage 2 !
+
+# 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-init/env
+
+# Fork the "init-stage2" script and have it ready to start as soon
+# as the catch-all logger is in place
+background
+{
+ s6-setsid
+ redirfd -w 1 /service/s6-svscan-log/fifo # (blocks until the logger reads)
+ /etc/s6-init/init-stage2
+}
+unexport LASTPID
+
+# Start stage 2.
+s6-svscan -t0 /service
diff --git a/examples/ROOT/etc/s6-init/init-stage2 b/examples/ROOT/etc/s6-init/init-stage2
new file mode 100755
index 0000000..ad6d8ce
--- /dev/null
+++ b/examples/ROOT/etc/s6-init/init-stage2
@@ -0,0 +1,41 @@
+#!/command/execlineb -P
+
+# This file is executed (not as process 1!) as soon as s6-svscan
+# starts. It should perform all the remaining one-time initialization
+# tasks.
+
+
+if -nt
+{
+
+# This should be logged in /tmp/uncaught-logs/current,
+# NOT on /dev/console !
+ if { s6-echo "* init-stage2 starting." }
+
+# Call your one-time EARLY initialization scripts (before bringing
+# the network up) here:
+# set the hostname, mount filesystems, adjust sysctls, etc.
+# if { s6-mount -wt devpts -o noexec,nosuid,gid=0,mode=0600 devpts /dev/pts }
+# if { s6-mount -wt ext4 /dev/sda3 /mnt/rwfs }
+
+# Start the local services
+ if { s6-hiercopy /img/services-local /service }
+ if { s6-svscanctl -a /service }
+
+# Bring up the network
+ if { /etc/s6-init/network-config }
+
+# Start the late services
+ if { s6-hiercopy /img/services-network /service }
+ if { s6-svscanctl -a /service }
+
+# We're done and the machine is fully operational.
+ s6-echo "* init-stage2 completed."
+}
+
+
+# If anything in the if -nt { } block fails, control jumps here.
+# No need to do much because there's already an operational getty running.
+
+redirfd -w 1 /dev/console
+s6-echo "\n!!!!!\ninit-stage2 failed, please log in and investigate.\n!!!!!"
diff --git a/examples/ROOT/etc/s6-init/init-stage3 b/examples/ROOT/etc/s6-init/init-stage3
new file mode 100755
index 0000000..66b3062
--- /dev/null
+++ b/examples/ROOT/etc/s6-init/init-stage3
@@ -0,0 +1,46 @@
+#!/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}
diff --git a/examples/ROOT/etc/s6-init/network-config b/examples/ROOT/etc/s6-init/network-config
new file mode 100755
index 0000000..2f9e3cd
--- /dev/null
+++ b/examples/ROOT/etc/s6-init/network-config
@@ -0,0 +1,5 @@
+#!/command/execlineb -P
+
+# if { ifconfig lo 127.0.0.1 netmask 255.0.0.0 }
+
+# Configure your network interfaces and routing here.