| 9 | == start stop script == |
| 10 | Create a file ''deepamehta'' in ''/etc/init.d'': |
| 11 | {{{ |
| 12 | #! /bin/sh |
| 13 | ### BEGIN INIT INFO |
| 14 | # Provides: skeleton |
| 15 | # Required-Start: $remote_fs $syslog |
| 16 | # Required-Stop: $remote_fs $syslog |
| 17 | # Default-Start: 2 3 4 5 |
| 18 | # Default-Stop: 0 1 6 |
| 19 | # Short-Description: Example initscript |
| 20 | # Description: This file should be used to construct scripts to be |
| 21 | # placed in /etc/init.d. |
| 22 | ### END INIT INFO |
| 23 | |
| 24 | #echo "deepamehta start-stop-script is disabled!" |
| 25 | #exit 0 |
| 26 | |
| 27 | # Author: Juergen Neumann <j.neumann{at}junes{dot}eu> |
| 28 | # |
| 29 | # Please remove the "Author" lines above and replace them |
| 30 | # with your own name if you copy and modify this script. |
| 31 | |
| 32 | # Do NOT "set -e" |
| 33 | |
| 34 | # PATH should only include /usr/* if it runs after the mountnfs.sh script |
| 35 | PATH=/sbin:/usr/sbin:/bin:/usr/bin |
| 36 | DESC="DeepaMehta" |
| 37 | NAME=deepamehta |
| 38 | #DAEMON=/usr/sbin/$NAME |
| 39 | DAEMON=/opt/deepamehta/dm.sh |
| 40 | EXTRA_ARGS="-c root --background --make-pidfile" |
| 41 | DAEMON_ARGS="" |
| 42 | PIDFILE=/var/run/$NAME.pid |
| 43 | SCRIPTNAME=/etc/init.d/$NAME |
| 44 | |
| 45 | # Exit if the package is not installed |
| 46 | if [ ! -x "$DAEMON" ]; then |
| 47 | echo "$DAEMON not found" |
| 48 | exit 0 |
| 49 | fi |
| 50 | |
| 51 | # Read configuration variable file if it is present |
| 52 | [ -r /etc/default/$NAME ] && . /etc/default/$NAME |
| 53 | |
| 54 | # Load the VERBOSE setting and other rcS variables |
| 55 | . /lib/init/vars.sh |
| 56 | |
| 57 | # Define LSB log_* functions. |
| 58 | # Depend on lsb-base (>= 3.0-6) to ensure that this file is present. |
| 59 | . /lib/lsb/init-functions |
| 60 | |
| 61 | # |
| 62 | # Function that starts the daemon/service |
| 63 | # |
| 64 | do_start() |
| 65 | { |
| 66 | # Return |
| 67 | # 0 if daemon has been started |
| 68 | # 1 if daemon was already running |
| 69 | # 2 if daemon could not be started |
| 70 | start-stop-daemon --start --quiet --pidfile $PIDFILE --startas $DAEMON --test > /dev/null \ |
| 71 | || return 1 |
| 72 | start-stop-daemon --start $EXTRA_ARGS --quiet --pidfile $PIDFILE --startas $DAEMON $DAEMON_ARGS \ |
| 73 | || return 2 |
| 74 | # Add code here, if necessary, that waits for the process to be ready |
| 75 | # to handle requests from services started subsequently which depend |
| 76 | # on this one. As a last resort, sleep for some time. |
| 77 | } |
| 78 | |
| 79 | # |
| 80 | # Function that stops the daemon/service |
| 81 | # |
| 82 | do_stop() |
| 83 | { |
| 84 | # Return |
| 85 | # 0 if daemon has been stopped |
| 86 | # 1 if daemon was already stopped |
| 87 | # 2 if daemon could not be stopped |
| 88 | # other if a failure occurred |
| 89 | start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE |
| 90 | RETVAL="$?" |
| 91 | [ "$RETVAL" = 2 ] && return 2 |
| 92 | # Wait for children to finish too if this is a daemon that forks |
| 93 | # and if the daemon is only ever run from this initscript. |
| 94 | # If the above conditions are not satisfied then add some other code |
| 95 | # that waits for the process to drop all resources that could be |
| 96 | # needed by services started subsequently. A last resort is to |
| 97 | # sleep for some time. |
| 98 | start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --pidfile $PIDFILE |
| 99 | # --startas $DAEMON |
| 100 | [ "$?" = 2 ] && return 2 |
| 101 | # Many daemons don't delete their pidfiles when they exit. |
| 102 | rm -f $PIDFILE |
| 103 | return "$RETVAL" |
| 104 | } |
| 105 | |
| 106 | # |
| 107 | # Function that sends a SIGHUP to the daemon/service |
| 108 | # |
| 109 | do_reload() { |
| 110 | # |
| 111 | # If the daemon can reload its configuration without |
| 112 | # restarting (for example, when it is sent a SIGHUP), |
| 113 | # then implement that here. |
| 114 | # |
| 115 | start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE |
| 116 | return 0 |
| 117 | } |
| 118 | |
| 119 | case "$1" in |
| 120 | start) |
| 121 | [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" |
| 122 | do_start |
| 123 | case "$?" in |
| 124 | 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
| 125 | 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
| 126 | esac |
| 127 | ;; |
| 128 | stop) |
| 129 | [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" |
| 130 | do_stop |
| 131 | case "$?" in |
| 132 | 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
| 133 | 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
| 134 | esac |
| 135 | ;; |
| 136 | status) |
| 137 | status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? |
| 138 | ;; |
| 139 | #reload|force-reload) |
| 140 | # |
| 141 | # If do_reload() is not implemented then leave this commented out |
| 142 | # and leave 'force-reload' as an alias for 'restart'. |
| 143 | # |
| 144 | #log_daemon_msg "Reloading $DESC" "$NAME" |
| 145 | #do_reload |
| 146 | #log_end_msg $? |
| 147 | #;; |
| 148 | restart|force-reload) |
| 149 | # |
| 150 | # If the "reload" option is implemented then remove the |
| 151 | # 'force-reload' alias |
| 152 | # |
| 153 | log_daemon_msg "Restarting $DESC" "$NAME" |
| 154 | do_stop |
| 155 | case "$?" in |
| 156 | 0|1) |
| 157 | do_start |
| 158 | case "$?" in |
| 159 | 0) log_end_msg 0 ;; |
| 160 | 1) log_end_msg 1 ;; # Old process is still running |
| 161 | *) log_end_msg 1 ;; # Failed to start |
| 162 | esac |
| 163 | ;; |
| 164 | *) |
| 165 | # Failed to stop |
| 166 | log_end_msg 1 |
| 167 | ;; |
| 168 | esac |
| 169 | ;; |
| 170 | *) |
| 171 | #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2 |
| 172 | echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 |
| 173 | exit 3 |
| 174 | ;; |
| 175 | esac |
| 176 | |
| 177 | : |
| 178 | |
| 179 | #EOF |
| 180 | }}} |