OSDN Git Service

upg
[joborun/jobcore.git] / runit / runit-hook
1 #!/bin/sh -e
2
3 runit_live() {
4   if [ ! -L /run/runit/service ]; then
5     echo >&2 "  Skipped: Current root is not booted."
6     exit 0
7   fi
8 }
9
10 svc_help(){
11     echo "      ==> Start/stop/restart a service:"
12     echo "      sv <service> <start/stop/restart>"
13 }
14
15 svc_add_help(){
16     echo "      ==> Add a service:"
17     echo "      ln -s /etc/runit/sv/<service> /run/runit/service/"
18     svc_help
19 }
20
21 svc_del_help(){
22     echo "      ==> Remove a service:"
23     echo "      rm /run/runit/service/<service>"
24     svc_help
25 }
26
27 each_conf() {
28   while read -r f; do
29     "$@" "/$f"
30   done
31 }
32
33 op="$1"; shift
34
35 case $op in
36   sysctl)   runit_live; each_conf /usr/bin/sysctl -q -p ;;
37   binfmt)   runit_live; each_conf /usr/lib/rc/sv.d/binfmt once ;;
38     # For use by other packages
39   reload)   runit_live; /usr/bin/sv "$@" reload ;;
40   add)      svc_add_help ;;
41   del)      svc_del_help ;;
42   *) echo >&2 "  Invalid operation '$op'"; exit 1 ;;
43 esac
44
45 exit 0