bare.sh - svc - Simple service scripts and examples, to be used everywhere.
 (HTM) git clone git://r-36.net/svc
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
       bare.sh (520B)
       ---
            1 #!/bin/sh
            2 
            3 [ $# -eq 0 ] && SERVICE="$0"
            4 
            5 if [ $# -gt 0 ];
            6 then
            7         SERVICE="$1"
            8         shift 1
            9 fi
           10 
           11 [ -e "/bin/svc.d/default/$SERVICE" ] && . "/bin/svc.d/default/$SERVICE"
           12 
           13 BIN=""
           14 for p in /bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin;
           15 do
           16         if [ -x "$p/$SERVICE" ];
           17         then
           18                 BIN="$p/$SERVICE"
           19                 break
           20         fi
           21 done
           22 [ -z "$BIN" ] && exit 1
           23 
           24 PID=$(pidof -o %PPID $BIN)
           25 
           26 case $1 in
           27         -s)
           28                 [ -z "$PID" ] && $BIN $PARAMS;
           29                 ;;
           30         -k)
           31                 [ -n "$PID" ] && kill -9 $PID &> /dev/null;
           32                 ;;
           33         *)
           34                 echo "usage: $0 -s|-k"
           35                 exit 1
           36 esac
           37