--- smsdaemon/scripts/smsdaemon-initscript 2008/12/09 22:16:26 170 +++ smsdaemon/scripts/smsdaemon-initscript 2008/12/19 07:33:01 204 @@ -1,211 +1,53 @@ -#! /bin/sh -# -# smsdaemon Startup script for the SMS daemon -# - -### BEGIN INIT INFO -# Provides: smsdaemon -# Required-Start: $syslog -# Required-Stop: $syslog -# Should-Start: $local_fs -# Should-Stop: $local_fs -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: starts smsdaemon -### END INIT INFO - -PATH=/sbin:/bin:/usr/sbin:/usr/bin -DAEMON=/usr/local/sbin/smsdaemon -NAME=smsdaemon -PACKAGE=smsdaemon -DESC='SMS Daemon' +#! /bin/bash PIDFILE="/var/run/smsdaemon.pid" - - -test -x $DAEMON || exit 0 - - - - -start () { - - if ! ps -C smsdaemon > /dev/null 2>&1 ; then - - if [ -f $PIDFILE ]; then - rm $PIDFILE - fi - fi - - #make sure we have the directories and access where needed - if [ ! -d $(dirname $PIDFILE) ]; then - install -d -o $USER -g $GROUP -m 755 $(dirname $PIDFILE) - else - chown -R $USER:$GROUP $(dirname $PIDFILE) - fi - - - - # Start the daemon - ARGS="--daemon" - if start-stop-daemon -q --start --background -p $PIDFILE --exec $DAEMON -- $ARGS ; then - echo "$NAME." - else - echo "$NAME already running." - fi - - sleep 1 +function start_d +{ + /usr/local/sbin/smsdaemon --daemon } -forcestop () +function stop_d { - if [ -f $PIDFILE ]; then - PID=`cat $PIDFILE 2>/dev/null` - fi - - if ! kill -0 $PID 2>/dev/null 2>/dev/null; then - echo "$NAME not running." - else - kill -9 $PID - if [ -f $PIDFILE ]; then - rm $PIDFILE - fi - - if kill -0 $PID 2>/dev/null 2>/dev/null; then - echo "Failed." + if [ -f $PIDFILE ] ; then + PID=`cat $PIDFILE` + LINES=`ps aux | grep smsdaemon | grep $PID | wc -l` + if [ "$LINES" == "1" ] ; then + kill $PID else - echo "$NAME." + echo "pidfile found -- but smsdaemon not running" fi - fi + else + echo "PIDFILE not found !!!!!!!!" + fi } -status() +function status_d { - if [ ! -f $PIDFILE ]; then - return 1; - fi - - start-stop-daemon --start --quiet -p $PIDFILE --exec $DAEMON --test > /dev/null - if [ "$?" = '0' ]; then - return 1 # Daemon is not running - else - return 0 # Daemon is running - fi -} - -stop () { - - restartmode="0" - - if [ "$1" = 'restart' ]; then - restartmode=1 - fi - - if [ -f $PIDFILE ]; then - PID=`cat $PIDFILE 2>/dev/null` - fi - - if ! kill -0 $PID 2>/dev/null 2>/dev/null; then - echo "$NAME not running." - - if [ "$restartmode" -lt 1 ] - then - return 0 + if [ -f $PIDFILE ] ; then + PID=`cat $PIDFILE` + LINES=`ps aux | grep smsdaemon | grep $PID | wc -l` + if [ "$LINES" == "1" ] ; then + echo "smsdaemon running (pid=$PID)" + else + echo "pidfile found -- but smsdaemon not running" fi - fi - - infofound=0 - maxwait=15 - - start-stop-daemon --stop --quiet --pidfile $PIDFILE --exec $DAEMON - - # - # Now we have to wait until smsd has _really_ stopped - # - sleep 1 - - if test -n "$PID" && kill -0 $PID 2>/dev/null - then - echo -n "(waiting..." - - seconds=0 - while kill -0 $PID 2>/dev/null - do - if [ $infofound -lt 1 ]; then - if [ -f $INFOFILE ]; then - infofound=1 - fi - fi - - if [ $infofound -lt 1 ]; then - seconds=`expr $seconds + 1` - fi - - if [ $seconds -ge $maxwait ]; then - echo -n "failed)" - echo -n "Timeout occured, killing smsd hardly." - - kill -9 $PID - if [ -f $PIDFILE ]; then - rm $PIDFILE - fi - - echo "" - exit 0 - fi - - sleep 1 - done - - echo -n "done)" - fi - - if [ "$restartmode" -lt 1 ]; then - echo "$NAME." + else + echo "no pidfile - smsdaemon not started" fi } -case "$1" in - start) - echo -n "Starting $DESC: " - start - ;; - - stop) - echo -n "Stopping $DESC: " - stop - ;; - - status) - echo -n "Status of $DESC: " - status - case "$?" in - 0) - echo "$NAME is running." - ;; - 1) - echo "$NAME is not running." - ;; - esac - ;; - force-stop) - echo -n "Forcing stop of $DESC: " - force-stop - echo "$NAME." - - ;; - - restart|reload|force-reload) - echo -n "Restarting $DESC: " - stop restart - start - ;; - +case $1 in + "start") + start_d + ;; + "stop") + stop_d + ;; + "status") + status_d + ;; *) - echo "Usage: /etc/init.d/$NAME {start|stop|force-stop|reload|force-reload|restart|status}" - exit 3 - ;; + echo "Usage $0 [start|stop|status]" + ;; esac - -exit 0