]> Pileus Git - mkinit/blob - src/service
rcifying things, (rc version of mkinit is broken)
[mkinit] / src / service
1 #!/usr/lib/plan9/bin/rc
2
3 # Copyright (C) 2009 Andy Spencer
4 # See ../COPYING for terms
5
6 fn usage {
7         echo 'usage: '$0' <action> [start-|stop-]<service>'
8         echo 'Action:'
9         echo '  -u,--is-up    Test is service is running'
10         echo '  -d,--is-down  Test is service is stopped'
11         echo '  -U,--set-up   Set service to running'
12         echo '  -D,--set-down Set service to stopped'
13         echo '  -q,--query    Print the state of a service'
14         exit
15 }
16
17 # Main
18 STATE=/lib/mkinit/state
19
20 action=$1
21 service=`{echo $2 | sed s/-.*//}
22
23 if(~ $action '' || ~ $service '')
24         usage
25
26 switch($1){
27 case -u --is-up
28         test   -e $STATE/$service
29 case -d --is-down
30         test ! -e $STATE/$service
31 case -U --set-up
32         touch     $STATE/$service
33 case -D --set-down
34         rm        $STATE/$service
35 case -q --query
36         echo -n Service "$service" is
37         test -e $STATE/$service \
38                 && echo ' running' \
39                 || echo ' stopped'
40 case *
41         usage
42 }