]> git.netwichtig.de Git - user/henk/code/s6/service_directory_template.git/blob - run
add note about s6-permafailon
[user/henk/code/s6/service_directory_template.git] / run
1 #!/bin/execlineb -S1
2 # the -S1 tells execline to substitute 1 positional parameter
3 # which for this file is: the name of the service directory
4
5 # TODO:
6 # a sane example of handling the arguments would be nice
7
8 # populate some variables
9 define RUN_USER jdoe
10 define INSTANCE_NAME jane
11 backtick HOME { homeof ${RUN_USER} }
12 importas -n -u HOME HOME
13
14 # redirect STDERR to STDIN so it can be caught by a logging service
15 fdmove -c 2 1
16
17 # switch to a different user for running this
18 s6-setuidgid ${RUN_USER}
19
20 # handle SIGTERM
21 trap -x {
22         SIGTERM {
23                 pipeline { echo "system_powerdown\n" }
24                 s6-ipcclient ${HOME}/${INSTANCE_NAME}-monitor.socket
25                 s6-ioconnect -67
26         }
27 }
28
29 # the command to start and supervise
30 imaginary_service -l 127.0.0.1 -p 31337 ${HOME}/run/listener_${INSTANCE_NAME}/${INSTANCE_NAME}.conf