]> Pileus Git - mkinit/blobdiff - src/service
Update mkinit
[mkinit] / src / service
index d4b7a7d612789bea7827cab801190993e1377818..67dd734adaddc540c20040369e88875dfd3f55c4 100755 (executable)
@@ -1,41 +1,49 @@
-#!/bin/bash
+#!/opt/plan9/bin/rc
 
 # Copyright (C) 2009 Andy Spencer
 # See ../COPYING for terms
 
-function usage {
-cat - <<EOF
-usage: $0 <action> [start-|stop-]<service>
-Action:
-  -u,--is-up    Test is service is running
-  -d,--is-down  Test is service is stopped
-  -U,--set-up   Set service to running
-  -D,--set-down Set service to stopped
-  -q,--query    Print the state of a service
-EOF
-exit
+fn usage {
+       echo 'usage: '$0' <action> [start-|stop-]<service>'
+       echo 'Action:'
+       echo '  -u,--is-up    Test is service is running'
+       echo '  -d,--is-down  Test is service is stopped'
+       echo '  -U,--set-up   Set service to running'
+       echo '  -D,--set-down Set service to stopped'
+       echo '  -F,--flush    Resest all services to stopped'
+       echo '  -q,--query    Print the state of a service'
+       exit
 }
 
 # Main
-STATE=/lib/mkinit/state
+state=/lib/mkinit/state
+if (~ $MKINIT_STATE ?*)
+       state=$MKINIT_STATE
 
-action="$1"
-service="${2/-*}"
+action=$1
+service=`{echo $2 | sed s/-.*//}
 
-[ "$action" -a "$service" ] || usage
+if(~ $action '')
+       usage
+if(! ~ $action -F && ~ $service '')
+       usage
 
-# echo "$0 $@"
-
-case "$1" in
-       -u|--is-up    ) test   -e "$STATE/$service" ;;
-       -d|--is-down  ) test ! -e "$STATE/$service" ;;
-       -U|--set-up   ) touch     "$STATE/$service" ;;
-       -D|--set-down ) rm        "$STATE/$service" ;;
-       -q|--query    ) 
-               echo -n "Service \`$service' is "
-               test -e "$STATE/$service" \
-                       && echo running \
-                       || echo stopped
-               ;;
-       * ) usage ;;
-esac
+switch($1){
+case -u --is-up
+       test   -e $state/$service
+case -d --is-down
+       test ! -e $state/$service
+case -U --set-up
+       touch     $state/$service
+case -D --set-down
+       rm -f     $state/$service
+case -F --flush
+       rm -f     $state/*
+case -q --query
+       echo -n Service "$service" is
+       test -e $state/$service \
+               && echo ' running' \
+               || echo ' stopped'
+case *
+       usage
+}