1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
#!/bin/sh
# generic init file for darkice
#
# Niels Dettenbach - nd@syndicat.com - 2009-11-05
# Last Change: 2010-12-21
#
# thanks to:
# - Roland Whitehead
# GPL (2009)
# 0.7
## settings ##
# check your paths!
program=/usr/bin/darkice
pidfile=/var/run/darkice.pid
configfile=/etc/darkice.cfg
logfile=/var/log/darkice.log
progname="darkice"
restart_delay=2
verbose="5"
## end of settings ##
RETVAL=0
if [ ! -f $configfile ]
then
echo "$progname: config file not found"
exit
fi
if [ ! -f $program ]
then
echo "$progname: programm file $program not found"
exit
fi
case $1 in
'start')
if [ -f $pidfile ]; then
PID=`cat $pidfile`
running=`ps --no-headers -o "%c" -p $PID`
if ( [ "$progname" == "$running" ] ); then
echo "$progname is still running"
else
echo "$progname seems crashed - PID ($PID) does not match the deamon"
echo "removing stale PID File $pidfile"
rm -f $pidfile
$0 start
exit $?
fi
exit 0
else
echo -n $"Starting $progname "
RETVAL=1
$program -v $verbose -c $configfile 2>%1 >> $logfile &
echo
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
echo $! > $pidfile
echo " started"
else
echo " not started"
echo $RETVAL
exit 0
fi
RETVAL=$?
fi
;;
'stop')
if [ -f $pidfile ]; then
echo -n $"Stop $progname "
PID=`cat $pidfile`
kill -s TERM $PID 2> /dev/null
echo
sleep $restart_delay
rm -f $pidfile
echo " stopped"
else
echo "$progname not running"
fi
RETVAL=$?
;;
'status')
if [ -f $pidfile ]; then
PID=`cat $pidfile`
running=`ps --no-headers -o "%c" -p $PID`
if ( [ "$progname" == "$running" ] ); then
echo "$progname IS running with PID `cat $pidfile`."
else
echo "$progname process is dead or stale PID File $pidfile"
exit 0
fi
else
echo "$progname is not running"
exit 0
fi
;;
'restart')
$0 stop
$0 start
RETVAL=$?
;;
'restartifdown')
if [ -f $pidfile ]; then
PID=`cat $pidfile`
running=`ps --no-headers -o "%c" -p $PID`
if ( [ "$progname" == "$running" ] ); then
echo "$progname IS running with PID `cat $pidfile` - no restart."
else
echo "$progname PID $PID seems dead - restart"
$0 stop
$0 start
RETVAL=$?
fi
else
echo "PID file $pidfile found - restart"
$0 stop
$0 start
RETVAL=$?
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status|restartifdown} "
exit 1;
;;
esac
exit $RETVAL
|