]> Pileus Git - mkinit/blob - src/service
97280b39f18b252af9629e1ae8244e1a799b7d48
[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 '  -F,--flush    Resest all services to stopped'
14         echo '  -q,--query    Print the state of a service'
15         exit
16 }
17
18 # Main
19 state=/lib/mkinit/state
20 if (~ $MKINIT_STATE ?*)
21         state=$MKINIT_STATE
22
23 action=$1
24 service=`{echo $2 | sed s/-.*//}
25
26 if(~ $action '')
27         usage
28 if(! ~ $action -F && ~ $service '')
29         usage
30
31 switch($1){
32 case -u --is-up
33         test   -e $state/$service
34 case -d --is-down
35         test ! -e $state/$service
36 case -U --set-up
37         touch     $state/$service
38 case -D --set-down
39         rm -f     $state/$service
40 case -F --flush
41         rm -f     $state/*
42 case -q --query
43         echo -n Service "$service" is
44         test -e $state/$service \
45                 && echo ' running' \
46                 || echo ' stopped'
47 case *
48         usage
49 }