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