blob: 1fc05a0ee30ce7b9542b3beb0c7cdfa01f602f4c [file] [log] [blame]
brians343bc112013-02-10 01:53:46 +00001#! /bin/sh
2### BEGIN INIT INFO
3# Provides: starter
4# Required-Start: $remote_fs $syslog sshd $all
5# Required-Stop: $remote_fs $syslog
6# Default-Start: 2 3 4 5
7# Default-Stop: 0 1 6
8# Short-Description: AOS Startup Code
9# Description: Starts up all of the AOS-related things (FRC robot code).
10### END INIT INFO
11# pam_limits
12
13# Author: Spartan Robotics <spartanrobotics.org>
14
Brian Silverman8b34e272013-08-28 16:22:11 -070015# Install by placing in /etc/init.d/ and then `update-rc.d starter defaults`.
16
brians343bc112013-02-10 01:53:46 +000017# Do NOT "set -e"
18
19# PATH should only include /usr/* if it runs after the mountnfs.sh script
20PATH=/sbin:/usr/sbin:/bin:/usr/bin
21DESC="FRC robot code"
22NAME=starter
23DAEMON=/home/driver/robot_code/bin/$NAME.sh
24DAEMON_ARGS="/home/driver/robot_code/bin/start_list.txt"
25PIDFILE=/tmp/$NAME.pid
26SCRIPTNAME=/etc/init.d/$NAME
27
28# Exit if the package is not installed
29[ -x "$DAEMON" ] || exit 0
30
31# Read configuration variable file if it is present
32[ -r /etc/default/$NAME ] && . /etc/default/$NAME
33
34# Load the VERBOSE setting and other rcS variables
35. /lib/init/vars.sh
36
37# Define LSB log_* functions.
38# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
39# and status_of_proc is working.
40. /lib/lsb/init-functions
41VERBOSE=yes
42
43#
44# Function that starts the daemon/service
45#
46do_start()
47{
48 # Return
49 # 0 if daemon has been started
50 # 1 if daemon was already running
51 # 2 if daemon could not be started
52 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
53 || return 1
54 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
55 $DAEMON_ARGS \
56 || return 2
57 # Add code here, if necessary, that waits for the process to be ready
58 # to handle requests from services started subsequently which depend
59 # on this one. As a last resort, sleep for some time.
60}
61
62#
63# Function that stops the daemon/service
64#
65do_stop()
66{
67 # Return
68 # 0 if daemon has been stopped
69 # 1 if daemon was already stopped
70 # 2 if daemon could not be stopped
71 # other if a failure occurred
Brian Silverman0b882522014-02-16 15:47:34 -080072 killall starter_loop.sh
brians343bc112013-02-10 01:53:46 +000073 start-stop-daemon --stop --quiet --retry=INT/10/KILL/5 --pidfile $PIDFILE
74 RETVAL="$?"
75 [ "$RETVAL" = 2 ] && return 2
76 # Wait for children to finish too if this is a daemon that forks
77 # and if the daemon is only ever run from this initscript.
78 # If the above conditions are not satisfied then add some other code
79 # that waits for the process to drop all resources that could be
80 # needed by services started subsequently. A last resort is to
81 # sleep for some time.
82 #start-stop-daemon --stop --quiet --oknodo --retry=INT/10/KILL/5
83 #[ "$?" = 2 ] && return 2
Brian Silverman0b882522014-02-16 15:47:34 -080084 sleep 5
brians343bc112013-02-10 01:53:46 +000085 # Many daemons don't delete their pidfiles when they exit.
86 rm -f $PIDFILE
87 return "$RETVAL"
88}
89
90#
91# Function that sends a SIGHUP to the daemon/service
92#
93do_reload() {
94 #
95 # If the daemon can reload its configuration without
96 # restarting (for example, when it is sent a SIGHUP),
97 # then implement that here.
98 #
99 start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
100 return 0
101}
102
103case "$1" in
104 start)
105 [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
106 do_start
107 case "$?" in
108 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
109 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
110 esac
111 ;;
112 stop)
113 [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
114 do_stop
115 case "$?" in
116 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
117 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
118 esac
119 ;;
120 status)
121 status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
122 ;;
123 #reload|force-reload)
124 #
125 # If do_reload() is not implemented then leave this commented out
126 # and leave 'force-reload' as an alias for 'restart'.
127 #
128 #log_daemon_msg "Reloading $DESC" "$NAME"
129 #do_reload
130 #log_end_msg $?
131 #;;
132 restart|force-reload)
133 #
134 # If the "reload" option is implemented then remove the
135 # 'force-reload' alias
136 #
137 log_daemon_msg "Restarting $DESC" "$NAME"
138 do_stop
139 case "$?" in
140 0|1)
141 do_start
142 case "$?" in
143 0) log_end_msg 0 ;;
144 1) log_end_msg 1 ;; # Old process is still running
145 *) log_end_msg 1 ;; # Failed to start
146 esac
147 ;;
148 *)
149 # Failed to stop
150 log_end_msg 1
151 ;;
152 esac
153 ;;
154 *)
155 #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
156 echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
157 exit 3
158 ;;
159esac
160
161: