blob: befa0c75c8103a06e9c491061fe6400f578b480f [file] [log] [blame]
Matt Hart25c24be2013-08-22 09:55:38 +01001#!/bin/sh
2### BEGIN INIT INFO
matthew.hart@linaro.org5e4fce92013-08-22 11:29:21 +01003# Provides: lavapdu-runner
Neil Williams29c339e2014-07-28 12:29:46 +01004# Required-Start: $remote_fs $network postgresql
Neil Williams544998b2014-02-13 11:14:55 +00005# Required-Stop: $remote_fs $network
Matt Hart25c24be2013-08-22 09:55:38 +01006# 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.org5e4fce92013-08-22 11:29:21 +010014LOGFILE="--logfile /var/log/lavapdu-runner.log"
matthew.hart@linaro.org426d0852013-10-30 15:23:15 -070015LOGLEVEL="--loglevel=INFO"
Matt Hart25c24be2013-08-22 09:55:38 +010016
17# PATH should only include /usr/* if it runs after the mountnfs.sh script
18PATH=/sbin:/usr/sbin:/bin:/usr/bin
matthew.hart@linaro.org5e4fce92013-08-22 11:29:21 +010019DESC="lavapdu-runner" # short description
20NAME=lavapdu-runner # short server's name (truncated for 15 chars)
Neil Williams424fbbb2014-05-16 20:34:00 +010021DAEMON=/usr/sbin/lavapdu-runner # server's location
Matt Hart25c24be2013-08-22 09:55:38 +010022DAEMON_ARGS="$LOGLEVEL" # Arguments to run the daemon with
23PIDFILE=/var/run/$DESC.pid
24SCRIPTNAME=/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#
42do_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#
61do_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 Hartd4a09982015-07-17 16:13:11 +010068 start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
Matt Hart25c24be2013-08-22 09:55:38 +010069 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 Hartd4a09982015-07-17 16:13:11 +010078 if [ $RETVAL -lt 2 ]
79 then
80 rm -f $PIDFILE
81 fi
Matt Hart25c24be2013-08-22 09:55:38 +010082 return "$RETVAL"
83}
84
85case "$1" in
86 start)
87 [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME"
88 do_start
Matt Hartd4a09982015-07-17 16:13:11 +010089 sleep 1
90 echo -n " "
91 cat $PIDFILE
Matt Hart25c24be2013-08-22 09:55:38 +010092 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 Williams544998b2014-02-13 11:14:55 +0000134esac