about summary refs log tree commit diff
path: root/bin/svtree-run
diff options
context:
space:
mode:
Diffstat (limited to 'bin/svtree-run')
-rwxr-xr-xbin/svtree-run50
1 files changed, 50 insertions, 0 deletions
diff --git a/bin/svtree-run b/bin/svtree-run
new file mode 100755
index 0000000..b5121cc
--- /dev/null
+++ b/bin/svtree-run
@@ -0,0 +1,50 @@
+#!/bin/execlineb -P
+
+importas -iS HOME
+importas -iS XDG_RUNTIME_DIR
+
+envfile -I ../dirs.conf
+
+# compiled (setup by init script)
+if { eltest -e ${COMPILED_DIR} }
+
+# TODO: cgroup support
+#define CG /sys/fs/cgroup/usr
+#if { test -d ${CG} }
+#if { test -w ${CG}/cgroup.procs }
+
+# nuke any other svscan process
+foreground { s6-svscanctl -qN ${SCAN_DIR} }
+foreground { s6-svwait -D ${SCAN_DIR}/s6rc-fdholder }
+
+# cleanup
+foreground { rm -rf ${SCAN_DIR} }
+foreground { elglob l ${LIVE_DIR}* rm -rf ${l} }
+
+# setup rundir
+if { cp -va -- ${CONF_DIR}/run-image/service ${SCAN_DIR} }
+
+background {
+	# catch-all logger
+	fdmove -c 4 2
+	redirfd -wnb 2 ${SCAN_DIR}/s6-svscan-log/fifo
+	fdmove -c 1 2
+
+	# TODO: why do we need this?
+	execline-cd ${HOME}
+
+	# run s6
+	s6-svscan ${SCAN_DIR}
+}
+
+# setup s6-rc
+foreground { s6-rc-init -c ${COMPILED_DIR} -l ${LIVE_DIR} -d -- ${SCAN_DIR} }
+
+# launch default target
+foreground { s6-rc -v2 -l ${LIVE_DIR} -pu change default }
+
+# block on s6
+importas -i scanpid !
+wait -i { ${scanpid} }
+
+exit 0