blob: 24de00c8c94544ba0882a44bbcd0c26acb893438 [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
Matt Hart25c24be2013-08-22 09:55:38 +01004# Required-Start: $network
5# Default-Start: 2 3 4 5
6# Default-Stop: 0 1 6
7# Short-Description: LAVA PDU Runner
8# Description: Runner daemon to process PDU requests
9### END INIT INFO
10
11# Author: Matthew Hart <matthew.hart@linaro.org>
12
matthew.hart@linaro.org5e4fce92013-08-22 11:29:21 +010013LOGFILE="--logfile /var/log/lavapdu-runner.log"
Matt Hart25c24be2013-08-22 09:55:38 +010014LOGLEVEL="--loglevel=DEBUG"
15
16# PATH should only include /usr/* if it runs after the mountnfs.sh script
17PATH=/sbin:/usr/sbin:/bin:/usr/bin
matthew.hart@linaro.org5e4fce92013-08-22 11:29:21 +010018DESC="lavapdu-runner" # short description
19NAME=lavapdu-runner # short server's name (truncated for 15 chars)
20DAEMON=/usr/bin/lavapdu-runner # server's location
Matt Hart25c24be2013-08-22 09:55:38 +010021DAEMON_ARGS="$LOGLEVEL" # Arguments to run the daemon with
22PIDFILE=/var/run/$DESC.pid
23SCRIPTNAME=/etc/init.d/$NAME
24
25# Exit if the package is not installed
26[ -x $DAEMON ] || exit 0
27
28# Read configuration variable file if it is present
29[ -r /etc/default/$NAME ] && . /etc/default/$NAME
30
31# Load the VERBOSE setting and other rcS variables
32#. /lib/init/vars.sh
33
34# Define LSB log_* functions.
35# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
36. /lib/lsb/init-functions
37
38#
39# Function that starts the daemon/service
40#
41do_start()
42{
43 # Return
44 # 0 if daemon has been started
45 # 1 if daemon was already running
46 # 2 if daemon could not be started
47 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
48 || return 1
49 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
50 $DAEMON_ARGS \
51 || return 2
52 # Add code here, if necessary, that waits for the process to be ready
53 # to handle requests from services started subsequently which depend
54 # on this one. As a last resort, sleep for some time.
55}
56
57#
58# Function that stops the daemon/service
59#
60do_stop()
61{
62 # Return
63 # 0 if daemon has been stopped
64 # 1 if daemon was already stopped
65 # 2 if daemon could not be stopped
66 # other if a failure occurred
67 start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
68 RETVAL="$?"
69 [ "$RETVAL" = 2 ] && return 2
70 # Wait for children to finish too if this is a daemon that forks
71 # and if the daemon is only ever run from this initscript.
72 # If the above conditions are not satisfied then add some other code
73 # that waits for the process to drop all resources that could be
74 # needed by services started subsequently. A last resort is to
75 # sleep for some time.
76 # Many daemons don't delete their pidfiles when they exit.
77 rm -f $PIDFILE
78 return "$RETVAL"
79}
80
81case "$1" in
82 start)
83 [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME"
84 do_start
85 case "$?" in
86 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
87 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
88 esac
89 ;;
90 stop)
91 [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
92 do_stop
93 case "$?" in
94 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
95 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
96 esac
97 ;;
98 status)
99 status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
100 ;;
101 restart|force-reload)
102 #
103 # If the "reload" option is implemented then remove the
104 # 'force-reload' alias
105 #
106 log_daemon_msg "Restarting $DESC" "$NAME"
107 do_stop
108 case "$?" in
109 0|1)
110 do_start
111 case "$?" in
112 0) log_end_msg 0 ;;
113 1) log_end_msg 1 ;; # Old process is still running
114 *) log_end_msg 1 ;; # Failed to start
115 esac
116 ;;
117 *)
118 # Failed to stop
119 log_end_msg 1
120 ;;
121 esac
122 ;;
123 *)
124 echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
125 exit 3
126 ;;
127esac