about summary refs log tree commit diff
path: root/bin/svtree-run
blob: 72f47b010907a642b7fdfe4d702fc268faffd9d0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/execlineb -P

importas -iS HOME
importas -iS XDG_RUNTIME_DIR

envfile -I /opt/svtree/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