/[projects]/smsdaemon/scripts/smsdaemon-initscript
ViewVC logotype

Diff of /smsdaemon/scripts/smsdaemon-initscript

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 170 by torben, Tue Dec 9 22:16:26 2008 UTC revision 209 by torben, Sun Dec 21 18:57:24 2008 UTC
# Line 1  Line 1 
1  #! /bin/sh  #! /bin/bash
 #  
 # 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'  
2    
3  PIDFILE="/var/run/smsdaemon.pid"  PIDFILE="/var/run/smsdaemon.pid"
4    
5    function start_d
6    {
7            /usr/local/sbin/smsdaemon --daemon
8    }
9    
10    function stop_d
11  test -x $DAEMON || exit 0  {
12            if [ -f $PIDFILE ] ; then
13                    PID=`cat $PIDFILE`
14                    LINES=`ps aux | grep smsdaemon | grep $PID | wc -l`
15                    if [ "$LINES" == "1" ] ; then
16  start () {                          kill $PID
17                    else
18          if ! ps -C smsdaemon > /dev/null 2>&1 ; then                          echo "pidfile found -- but smsdaemon not running"
   
                 if [ -f $PIDFILE ]; then  
                         rm $PIDFILE  
19                  fi                  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."  
20          else          else
21                  echo "$NAME already running."                  echo "PIDFILE not found !!!!!!!!"
22          fi          fi      
   
         sleep 1  
23  }  }
24    
25  forcestop ()  function status_d
26  {  {
27          if [ -f $PIDFILE ]; then          if [ -f $PIDFILE ] ; then
28                  PID=`cat $PIDFILE 2>/dev/null`                  PID=`cat $PIDFILE`
29          fi                  LINES=`ps aux | grep smsdaemon | grep $PID | wc -l`
30                    if [ "$LINES" == "1" ] ; then
31          if ! kill -0 $PID 2>/dev/null 2>/dev/null; then                          echo "smsdaemon running (pid=$PID)"
                 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."  
32                  else                  else
33                          echo "$NAME."                          echo "pidfile found -- but smsdaemon not running"
34                  fi                  fi
35            else
36                    echo "no pidfile - smsdaemon not started"
37          fi          fi
38  }  }
39    
40  status()  function reload_d
41  {  {
42          if [ ! -f $PIDFILE ]; then          PID=`cat $PIDFILE`
43                  return 1;          kill -HUP $PID
         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  
44  }  }
45    
46  stop () {  case $1 in
47            "start")
48          restartmode="0"                  start_d
49                    ;;
50          if [ "$1" = 'restart' ]; then          "stop")
51                  restartmode=1                  stop_d
52          fi                  ;;
53            "status")
54          if [ -f $PIDFILE ]; then                  status_d
55                  PID=`cat $PIDFILE 2>/dev/null`                  ;;
56          fi          "reload")
57                    reload_d
58          if ! kill -0 $PID 2>/dev/null 2>/dev/null; then                  ;;
59                  echo "$NAME not running."          "restart")
60                    stop_d
61                  if [ "$restartmode" -lt 1 ]                  sleep 5
62                  then                  start_d
63                          return 0                  ;;
                 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."  
         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  
         ;;  
   
64          *)          *)
65                  echo "Usage: /etc/init.d/$NAME {start|stop|force-stop|reload|force-reload|restart|status}"                  echo "Usage $0 [start|stop|status|reload|restart]"
66                  exit 3                  ;;
         ;;  
67  esac  esac
   
 exit 0  

Legend:
Removed from v.170  
changed lines
  Added in v.209

  ViewVC Help
Powered by ViewVC 1.1.20