root/projects/AsynCluster/trunk/misc/etc_init.d_asyncluster

Revision 2, 2.8 kB (checked in by edsuom, 1 year ago)

Import of trunk from old repo

  • Property svn:executable set to *
Line 
1 #! /bin/sh
2 ### BEGIN INIT INFO
3 # Provides:          ndm-master
4 # Required-Start:    $local_fs $network $remote_fs
5 # Required-Stop:     $local_fs $network $remote_fs
6 # Default-Start:     2 3 4 5
7 # Default-Stop:      S 0 1 6
8 # Short-Description: AsynCluster - Master
9 # Description:       Master server daemon for a cluster of nodes
10 ### END INIT INFO
11
12 # Author: Ed Suominen <ed@eepatents.com>
13
14 # Do NOT "set -e"
15
16 # PATH should only include /usr/* if it runs after the mountnfs.sh script
17 PATH=/usr/sbin:/usr/bin:/sbin:/bin
18 DESC="ASYNCLUSTER"
19 NAME=asyncluster
20 DAEMON=/usr/bin/twistd
21 TACFILE=/usr/lib/asyncluster.tac
22 LOGFILE=/var/log/asyncluster.log
23 PIDFILE=/var/run/$NAME.pid
24 SCRIPTNAME=/etc/init.d/asyncluster
25
26 # Exit if the package is not installed
27 [ -x "$DAEMON" ] || exit 0
28
29 # Read configuration variable file if it is present
30 [ -r /etc/default/$NAME ] && . /etc/default/$NAME
31
32 # Load the VERBOSE setting and other rcS variables
33 [ -f /etc/default/rcS ] && . /etc/default/rcS
34
35 # Define LSB log_* functions.
36 # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
37 . /lib/lsb/init-functions
38
39
40 isrunning () {
41   if [ ! -f $PIDFILE ]
42       then
43       false
44   else
45       DAEMONPID=$(cat $PIDFILE)
46       if expr "$(cat /proc/$DAEMONPID/cmdline 2> /dev/null)" : "$DAEMON" > /dev/null 2>&1
47           then
48           true
49       else
50           false
51       fi
52   fi
53 }
54
55 #
56 # Function that starts the daemon/service
57 #
58 do_start()
59 {
60         # Return
61         #   0 if daemon has been started
62         #   1 if daemon was already running
63         #   2 if daemon could not be started
64     isrunning && return 1
65     $DAEMON --python=$TACFILE --logfile=$LOGFILE --pidfile=$PIDFILE || return 2
66 }
67
68 #
69 # Function that stops the daemon/service
70 #
71 do_stop()
72 {
73         # Return
74         #   0 if daemon has been stopped
75         #   1 if daemon was already stopped
76         #   2 if daemon could not be stopped
77         #   other if a failure occurred
78     isrunning && return 1
79     cat $PIDFILE |xargs kill
80         RETVAL="$?"
81         [ "$RETVAL" = 0 ] || return 2
82         # Many daemons don't delete their pidfiles when they exit.
83         rm -f $PIDFILE
84         return "$RETVAL"
85 }
86
87 case "$1" in
88   start)
89         [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
90         do_start
91         case "$?" in
92                 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
93                 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
94         esac
95         ;;
96   stop)
97         [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
98         do_stop
99         case "$?" in
100                 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
101                 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
102         esac
103         ;;
104   restart|force-reload)
105         log_daemon_msg "Restarting $DESC" "$NAME"
106         do_stop
107         case "$?" in
108           0|1)
109                 do_start
110                 case "$?" in
111                         0) log_end_msg 0 ;;
112                         1) log_end_msg 1 ;; # Old process is still running
113                         *) log_end_msg 1 ;; # Failed to start
114                 esac
115                 ;;
116           *)
117                 # Failed to stop
118                 log_end_msg 1
119                 ;;
120         esac
121         ;;
122   *)
123         echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
124         exit 3
125         ;;
126 esac
127
128 :
Note: See TracBrowser for help on using the browser.