#!/usr/lib/plan9/bin/rc # Copyright (C) 2009 Andy Spencer # See ../COPYING for terms fn usage { echo 'usage: '$0' [start-|stop-]' 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 if (~ $MKINIT_STATE ?*) state=$MKINIT_STATE action=$1 service=`{echo $2 | sed s/-.*//} if(~ $action '') usage if(! ~ $action -F && ~ $service '') usage 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 }