login.capability.service (2888B)
1 #!/bin/zsh 2 setopt no_unset warn_create_global extended_glob 3 4 # s6-svc [ -wu | -wU | -wd | -wD | -wr | -wR ] [ -T timeout ] [ -s signal | -abqhkti12pcy ] [ -roduDUxO ] servicedir 5 # 6 ### allowed: 7 # • -o : once. Equivalent to "-uO". 8 # • -d : down. If the supervised process is up, send it a SIGTERM (by default) then a SIGCONT (to make sure even 9 # stopped processes receive the signal aimed to kill them) and do not restart it. The SIGTERM default can be changed 10 # by editing the ./down-signal file in the service directory. 11 # • -D : down, and create a ./down file so the service does not restart automatically if the supervisor dies. This 12 # option is mostly used by automated systems working on top of s6; as a human user, you probably don't need it. 13 # • -u : up. If the supervised process is down, start it. Automatically restart it when it dies. 14 # • -U : up, and remove any ./down file that may exist, in order to make sure the service is automatically restarted 15 # even if the supervisor dies. This option is mostly used by automated systems working on top of s6; as a human user, 16 # you probably don't need it. 17 # • -O : mark the service to run once at most. iow: do not restart the supervised process when it dies. If it is down 18 # when the command is received, do not even start it. 19 # • -Q : once at most, and create a ./down file. Like -D, but do not terminate the service if it is currently running. 20 # • -r : If the service is up, restart it, by sending it a signal to kill it and letting s6-supervise start it again. 21 # By default, the signal is a SIGTERM; this can be configured via the ./down-signal file in the service directory. 22 # 23 ### disallowed: 24 # • -x : exit. When the service is asked to be down and the supervised process dies, s6-supervise will exit too. This 25 # command should normally never be used on a working system. Note that if this command is sent and a ./finish script 26 # exists for the service, the last ./finish invocation before s6-supervise exits will run with its stdin and stdout 27 # redirected to /dev/null. 28 29 die_n() { 30 exitcode=$1 31 shift 32 printf >&2 '%s\n' "$@" 33 exit $exitcode 34 } 35 36 die100() { 37 die_n 100 "$@" 38 } 39 40 die111() { 41 die_n 111 "$@" 42 } 43 44 check_option() { 45 case $1 in 46 ([abqhkti12pcy]) return;; # Send signal 47 ([oOuUdDrQ]) return;; # State management 48 esac 49 die100 "invalid option: ${(qqq)1}" 50 } 51 52 check_service() { 53 case $1 in 54 (container.dhcpcd.dhcpcd) return;; 55 (container.tinc.tinc) return;; 56 (container.unbound.unbound) return;; 57 (container.wpa_supplicant.wpa_supplicant) return;; 58 esac 59 die100 "service not permitted: ${(qqq)1}" 60 } 61 62 typeset -g scandir=/run/service 63 64 main() { 65 [[ $# == 2 ]] || die100 "usage: ${0:t} service-name action" 66 check_service $1 67 local opt 68 for opt in ${(s::)2}; do 69 check_option $opt 70 done 71 exec s6-svc -$2 $scandir/$1 72 } 73 typeset -f -t main 74 75 main "$@" 76 # vim: ft=zsh noet ts=4 sts=4 sw=4