blob: f82df4b4e3500099d9647733471b04871d09565d [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
15# Do NOT "set -e"
16
17# PATH should only include /usr/* if it runs after the mountnfs.sh script
18PATH=/sbin:/usr/sbin:/bin:/usr/bin
19DESC="FRC robot code"
20NAME=starter
21DAEMON=/home/driver/robot_code/bin/$NAME.sh
22DAEMON_ARGS="/home/driver/robot_code/bin/start_list.txt"
23PIDFILE=/tmp/$NAME.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.2-14) to ensure that this file is present
37# and status_of_proc is working.
38. /lib/lsb/init-functions
39VERBOSE=yes
40
41#
42# Function that starts the daemon/service
43#
44do_start()
45{
46 # Return
47 # 0 if daemon has been started
48 # 1 if daemon was already running
49 # 2 if daemon could not be started
50 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
51 || return 1
52 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
53 $DAEMON_ARGS \
54 || return 2
55 # Add code here, if necessary, that waits for the process to be ready
56 # to handle requests from services started subsequently which depend
57 # on this one. As a last resort, sleep for some time.
58}
59
60#
61# Function that stops the daemon/service
62#
63do_stop()
64{
65 # Return
66 # 0 if daemon has been stopped
67 # 1 if daemon was already stopped
68 # 2 if daemon could not be stopped
69 # other if a failure occurred
70 start-stop-daemon --stop --quiet --retry=INT/10/KILL/5 --pidfile $PIDFILE
71 RETVAL="$?"
72 [ "$RETVAL" = 2 ] && return 2
73 # Wait for children to finish too if this is a daemon that forks
74 # and if the daemon is only ever run from this initscript.
75 # If the above conditions are not satisfied then add some other code
76 # that waits for the process to drop all resources that could be
77 # needed by services started subsequently. A last resort is to
78 # sleep for some time.
79 #start-stop-daemon --stop --quiet --oknodo --retry=INT/10/KILL/5
80 #[ "$?" = 2 ] && return 2
81 sleep 10
82 # Many daemons don't delete their pidfiles when they exit.
83 rm -f $PIDFILE
84 return "$RETVAL"
85}
86
87#
88# Function that sends a SIGHUP to the daemon/service
89#
90do_reload() {
91 #
92 # If the daemon can reload its configuration without
93 # restarting (for example, when it is sent a SIGHUP),
94 # then implement that here.
95 #
96 start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
97 return 0
98}
99
100case "$1" in
101 start)
102 [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
103 do_start
104 case "$?" in
105 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
106 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
107 esac
108 ;;
109 stop)
110 [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
111 do_stop
112 case "$?" in
113 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
114 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
115 esac
116 ;;
117 status)
118 status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
119 ;;
120 #reload|force-reload)
121 #
122 # If do_reload() is not implemented then leave this commented out
123 # and leave 'force-reload' as an alias for 'restart'.
124 #
125 #log_daemon_msg "Reloading $DESC" "$NAME"
126 #do_reload
127 #log_end_msg $?
128 #;;
129 restart|force-reload)
130 #
131 # If the "reload" option is implemented then remove the
132 # 'force-reload' alias
133 #
134 log_daemon_msg "Restarting $DESC" "$NAME"
135 do_stop
136 case "$?" in
137 0|1)
138 do_start
139 case "$?" in
140 0) log_end_msg 0 ;;
141 1) log_end_msg 1 ;; # Old process is still running
142 *) log_end_msg 1 ;; # Failed to start
143 esac
144 ;;
145 *)
146 # Failed to stop
147 log_end_msg 1
148 ;;
149 esac
150 ;;
151 *)
152 #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
153 echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
154 exit 3
155 ;;
156esac
157
158: