#!/bin/sh PROGNAME=ping903 COMMAND=/usr/sbin/ping903 OPTIONS= CONFIG=/etc/ping903.conf if [ ! -f $CONFIG ]; then exit fi PIDFILE=$(sed -r -n 's/^[[:space:]]*pidfile[[:space:]]+//p' $CONFIG) ping903_start() { $COMMAND $OPTIONS } ping903_stop() { if [ -n "$PIDFILE" ]; then if [ -f "$PIDFILE" ]; then pid=$(head -1 $PIDFILE) prog=$(ps -p $pid -ocomm=) if [ $prog = $PROGNAME ]; then kill -TERM $pid return fi else return fi fi killall $PROGNAME } ping903_restart() { ping903_stop sleep 1 ping903_start } ping903_status() { if [ -n "$PIDFILE" ]; then if [ -f "$PIDFILE" ]; then pid=$(head -1 $PIDFILE) prog=$(ps -p $pid -ocomm=) if [ $prog = $PROGNAME ]; then echo "$PROGNAME is running (PID $pid)" else echo "$PROGNAME is not running (pidfile is stale)" fi else echo "$PROGNAME is not running" fi else pid=$(/sbin/pidof $PROGNAME | cut -d ' ' -f 1) if [ -n "$pid" ]; then echo "$PROGNAME is running (PID $pid)" else echo "$PROGNAME is not running" fi fi } case "$1" in 'start') ping903_start ;; 'stop') ping903_stop ;; 'restart') ping903_restart ;; 'status') ping903_status ;; *) echo "usage $0 start|stop|restart|status" esac