summaryrefslogtreecommitdiff
path: root/run
blob: 2d1e4f4cbb75a11cf75e04ed6f5c1695aea5d2bc (plain)
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
#!/bin/execlineb -S1
# the -S1 tells execline to substitute 1 positional parameter
# which for this file is: the name of the service directory

# TODO:
# a sane example of handling the arguments would be nice

# populate some variables
define RUN_USER jdoe
define INSTANCE_NAME jane
backtick HOME { homeof ${RUN_USER} }
importas -n -u HOME HOME

# redirect STDERR to STDIN so it can be caught by a logging service
fdmove -c 2 1

# switch to a different user for running this
s6-setuidgid ${RUN_USER}

# handle SIGTERM
trap -x {
	SIGTERM {
		pipeline { echo "system_powerdown\n" }
		s6-ipcclient ${HOME}/${INSTANCE_NAME}-monitor.socket
		s6-ioconnect -67
	}
}

# the command to start and supervise
imaginary_service -l 127.0.0.1 -p 31337 ${HOME}/run/listener_${INSTANCE_NAME}/${INSTANCE_NAME}.conf