new version of rc.darkice

This commit is contained in:
rafael@riseup.net 2010-12-21 13:32:59 +00:00
parent 84760a8f0c
commit 704124e400
1 changed files with 90 additions and 89 deletions

View File

@ -1,12 +1,13 @@
#!/bin/sh #!/bin/sh
# generic init file for darkice # generic init file for darkice
# #
# Author:
# Niels Dettenbach - nd@syndicat.com - 2009-11-05 # Niels Dettenbach - nd@syndicat.com - 2009-11-05
# Last Change: 2010-12-21
# #
# License: # thanks to:
# GPLv3 (2009) # - Roland Whitehead
# # GPL (2009)
# 0.7
## settings ## ## settings ##
# check your paths! # check your paths!
@ -24,8 +25,8 @@ verbose="5"
RETVAL=0 RETVAL=0
if [ ! -f $configfile ] if [ ! -f $configfile ]
then then
echo "$progname: config file not found" echo "$progname: config file not found"
exit exit
fi fi
if [ ! -f $program ] if [ ! -f $program ]
@ -36,94 +37,94 @@ fi
case $1 in case $1 in
'start') 'start')
if [ -f $pidfile ]; then if [ -f $pidfile ]; then
PID=`cat $pidfile` PID=`cat $pidfile`
running=`ps --no-headers -o "%c" -p $PID` running=`ps --no-headers -o "%c" -p $PID`
if ( [ "$progname" == "$running" ] ); then if ( [ "$progname" == "$running" ] ); then
echo "$progname is still running" echo "$progname is still running"
else else
echo "$progname seems crashed - PID does not match the deamon" echo "$progname seems crashed - PID ($PID) does not match the deamon"
echo "removing stale PID File $pidfile" echo "removing stale PID File $pidfile"
rm $pidfile rm -f $pidfile
$0 start $0 start
exit $? exit $?
fi fi
exit 0 exit 0
else else
echo -n $"Starting $progname " echo -n $"Starting $progname "
RETVAL=1 RETVAL=1
$program -v $verbose -c $configfile 2>%1 >> $logfile & $program -v $verbose -c $configfile 2>%1 >> $logfile &
echo echo
RETVAL=$? RETVAL=$?
if [ $RETVAL -eq 0 ]; then if [ $RETVAL -eq 0 ]; then
echo $! > $pidfile echo $! > $pidfile
echo " started" echo " started"
else else
echo " not started" echo " not started"
echo $RETVAL echo $RETVAL
exit 0 exit 0
fi fi
RETVAL=$? RETVAL=$?
fi fi
;; ;;
'stop') 'stop')
if [ -f $pidfile ]; then if [ -f $pidfile ]; then
echo -n $"Stop $progname " echo -n $"Stop $progname "
PID=`cat $pidfile` PID=`cat $pidfile`
kill -s TERM $PID 2> /dev/null kill -s TERM $PID 2> /dev/null
echo echo
sleep $restart_delay sleep $restart_delay
rm $pidfile rm -f $pidfile
echo " stopped" echo " stopped"
else else
echo "$progname not running" echo "$progname not running"
fi fi
RETVAL=$? RETVAL=$?
;; ;;
'status') 'status')
if [ -f $pidfile ]; then if [ -f $pidfile ]; then
PID=`cat $pidfile` PID=`cat $pidfile`
running=`ps --no-headers -o "%c" -p $PID` running=`ps --no-headers -o "%c" -p $PID`
if ( [ "$progname" == "$running" ] ); then if ( [ "$progname" == "$running" ] ); then
echo "$progname IS running with PID `cat $pidfile`." echo "$progname IS running with PID `cat $pidfile`."
else else
echo "$progname process is dead or stale PID File $pidfile" echo "$progname process is dead or stale PID File $pidfile"
exit 0 exit 0
fi fi
else else
echo "$progname is not running" echo "$progname is not running"
exit 0 exit 0
fi fi
;; ;;
'restart') 'restart')
$0 stop $0 stop
$0 start $0 start
RETVAL=$? RETVAL=$?
;; ;;
'restartifdown') 'restartifdown')
if [ -f $pidfile ]; then if [ -f $pidfile ]; then
PID=`cat $pidfile` PID=`cat $pidfile`
running=`ps --no-headers -o "%c" -p $PID` running=`ps --no-headers -o "%c" -p $PID`
if ( [ "$progname" == "$running" ] ); then if ( [ "$progname" == "$running" ] ); then
echo "$progname IS running with PID `cat $pidfile` - no restart." echo "$progname IS running with PID `cat $pidfile` - no restart."
else else
echo "$progname PID $PID seems dead - restart" echo "$progname PID $PID seems dead - restart"
$0 stop $0 stop
$0 start $0 start
RETVAL=$? RETVAL=$?
fi fi
else else
echo "PID file $pidfile found - restart" echo "PID file $pidfile found - restart"
$0 stop $0 stop
$0 start $0 start
RETVAL=$? RETVAL=$?
fi fi
;; ;;
*) *)
echo "Usage: $0 {start|stop|restart|status|restartifdown} " echo "Usage: $0 {start|stop|restart|status|restartifdown} "
exit 1; exit 1;
;; ;;
esac esac