Matt Hart | 25c24be | 2013-08-22 09:55:38 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | ### BEGIN INIT INFO |
matthew.hart@linaro.org | 5e4fce9 | 2013-08-22 11:29:21 +0100 | [diff] [blame] | 3 | # Provides: lavapdu-runner |
Neil Williams | 29c339e | 2014-07-28 12:29:46 +0100 | [diff] [blame] | 4 | # Required-Start: $remote_fs $network postgresql |
Neil Williams | 544998b | 2014-02-13 11:14:55 +0000 | [diff] [blame] | 5 | # Required-Stop: $remote_fs $network |
Matt Hart | 25c24be | 2013-08-22 09:55:38 +0100 | [diff] [blame] | 6 | # Default-Start: 2 3 4 5 |
| 7 | # Default-Stop: 0 1 6 |
| 8 | # Short-Description: LAVA PDU Runner |
| 9 | # Description: Runner daemon to process PDU requests |
| 10 | ### END INIT INFO |
| 11 | |
| 12 | # Author: Matthew Hart <matthew.hart@linaro.org> |
| 13 | |
matthew.hart@linaro.org | 5e4fce9 | 2013-08-22 11:29:21 +0100 | [diff] [blame] | 14 | LOGFILE="--logfile /var/log/lavapdu-runner.log" |
matthew.hart@linaro.org | 426d085 | 2013-10-30 15:23:15 -0700 | [diff] [blame] | 15 | LOGLEVEL="--loglevel=INFO" |
Matt Hart | 25c24be | 2013-08-22 09:55:38 +0100 | [diff] [blame] | 16 | |
| 17 | # PATH should only include /usr/* if it runs after the mountnfs.sh script |
| 18 | PATH=/sbin:/usr/sbin:/bin:/usr/bin |
matthew.hart@linaro.org | 5e4fce9 | 2013-08-22 11:29:21 +0100 | [diff] [blame] | 19 | DESC="lavapdu-runner" # short description |
| 20 | NAME=lavapdu-runner # short server's name (truncated for 15 chars) |
Neil Williams | 424fbbb | 2014-05-16 20:34:00 +0100 | [diff] [blame] | 21 | DAEMON=/usr/sbin/lavapdu-runner # server's location |
Matt Hart | 25c24be | 2013-08-22 09:55:38 +0100 | [diff] [blame] | 22 | DAEMON_ARGS="$LOGLEVEL" # Arguments to run the daemon with |
| 23 | PIDFILE=/var/run/$DESC.pid |
| 24 | SCRIPTNAME=/etc/init.d/$NAME |
| 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 | #. /lib/init/vars.sh |
| 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 | # Function that starts the daemon/service |
| 41 | # |
| 42 | do_start() |
| 43 | { |
| 44 | # Return |
| 45 | # 0 if daemon has been started |
| 46 | # 1 if daemon was already running |
| 47 | # 2 if daemon could not be started |
| 48 | start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ |
| 49 | || return 1 |
| 50 | start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \ |
| 51 | $DAEMON_ARGS \ |
| 52 | || return 2 |
| 53 | # Add code here, if necessary, that waits for the process to be ready |
| 54 | # to handle requests from services started subsequently which depend |
| 55 | # on this one. As a last resort, sleep for some time. |
| 56 | } |
| 57 | |
| 58 | # |
| 59 | # Function that stops the daemon/service |
| 60 | # |
| 61 | do_stop() |
| 62 | { |
| 63 | # Return |
| 64 | # 0 if daemon has been stopped |
| 65 | # 1 if daemon was already stopped |
| 66 | # 2 if daemon could not be stopped |
| 67 | # other if a failure occurred |
Matt Hart | d4a0998 | 2015-07-17 16:13:11 +0100 | [diff] [blame] | 68 | start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE |
Matt Hart | 25c24be | 2013-08-22 09:55:38 +0100 | [diff] [blame] | 69 | RETVAL="$?" |
| 70 | [ "$RETVAL" = 2 ] && return 2 |
| 71 | # Wait for children to finish too if this is a daemon that forks |
| 72 | # and if the daemon is only ever run from this initscript. |
| 73 | # If the above conditions are not satisfied then add some other code |
| 74 | # that waits for the process to drop all resources that could be |
| 75 | # needed by services started subsequently. A last resort is to |
| 76 | # sleep for some time. |
| 77 | # Many daemons don't delete their pidfiles when they exit. |
Matt Hart | d4a0998 | 2015-07-17 16:13:11 +0100 | [diff] [blame] | 78 | if [ $RETVAL -lt 2 ] |
| 79 | then |
| 80 | rm -f $PIDFILE |
| 81 | fi |
Matt Hart | 25c24be | 2013-08-22 09:55:38 +0100 | [diff] [blame] | 82 | return "$RETVAL" |
| 83 | } |
| 84 | |
| 85 | case "$1" in |
| 86 | start) |
| 87 | [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME" |
| 88 | do_start |
Matt Hart | d4a0998 | 2015-07-17 16:13:11 +0100 | [diff] [blame] | 89 | sleep 1 |
| 90 | echo -n " " |
| 91 | cat $PIDFILE |
Matt Hart | 25c24be | 2013-08-22 09:55:38 +0100 | [diff] [blame] | 92 | case "$?" in |
| 93 | 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
| 94 | 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
| 95 | esac |
| 96 | ;; |
| 97 | stop) |
| 98 | [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" |
| 99 | do_stop |
| 100 | case "$?" in |
| 101 | 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
| 102 | 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
| 103 | esac |
| 104 | ;; |
| 105 | status) |
| 106 | status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? |
| 107 | ;; |
| 108 | restart|force-reload) |
| 109 | # |
| 110 | # If the "reload" option is implemented then remove the |
| 111 | # 'force-reload' alias |
| 112 | # |
| 113 | log_daemon_msg "Restarting $DESC" "$NAME" |
| 114 | do_stop |
| 115 | case "$?" in |
| 116 | 0|1) |
| 117 | do_start |
| 118 | case "$?" in |
| 119 | 0) log_end_msg 0 ;; |
| 120 | 1) log_end_msg 1 ;; # Old process is still running |
| 121 | *) log_end_msg 1 ;; # Failed to start |
| 122 | esac |
| 123 | ;; |
| 124 | *) |
| 125 | # Failed to stop |
| 126 | log_end_msg 1 |
| 127 | ;; |
| 128 | esac |
| 129 | ;; |
| 130 | *) |
| 131 | echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 |
| 132 | exit 3 |
| 133 | ;; |
Neil Williams | 544998b | 2014-02-13 11:14:55 +0000 | [diff] [blame] | 134 | esac |