OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 # Start/stop the Dartino agent. | 2 # Start/stop the Dartino agent. |
3 # | 3 # |
4 ### BEGIN INIT INFO | 4 ### BEGIN INIT INFO |
5 # Provides: dartino-agent | 5 # Provides: dartino-agent |
6 # Required-Start: $syslog $network | 6 # Required-Start: $syslog $network |
7 # Required-Stop: $syslog $network | 7 # Required-Stop: $syslog $network |
8 # Default-Start: 2 3 4 5 | 8 # Default-Start: 2 3 4 5 |
9 # Default-Stop: 0 1 6 | 9 # Default-Stop: 0 1 6 |
10 # Short-Description: Dartino agent for managing Dartino VMs. | 10 # Short-Description: Dartino agent for managing Dartino VMs. |
11 # Description: The Dartino agent is used by the Dartino compiler to start | 11 # Description: The Dartino agent is used by the Dartino compiler to start |
12 # and stop Dartino VMs on a Raspberry Pi2 device. | 12 # and stop Dartino VMs on a Raspberry Pi2 device. |
13 ### END INIT INFO | 13 ### END INIT INFO |
14 | 14 |
15 PATH=/bin:/usr/bin:/sbin:/usr/sbin | 15 PATH=/bin:/usr/bin:/sbin:/usr/sbin |
16 AGENT_SNAPSHOT=/usr/lib/dartino-agent/bin/fletch-agent.snapshot | 16 AGENT_SNAPSHOT=/usr/lib/dartino-agent/bin/dartino-agent.snapshot |
17 NAME=dartino-agent | 17 NAME=dartino-agent |
18 | 18 |
19 if [ ! -r /lib/lsb/init-functions ]; then | 19 if [ ! -r /lib/lsb/init-functions ]; then |
20 echo "Missing lsb init-functions to run the Fletch agent" | 20 echo "Missing lsb init-functions to run the Dartino agent" |
21 exit 1 | 21 exit 1 |
22 fi | 22 fi |
23 . /lib/lsb/init-functions | 23 . /lib/lsb/init-functions |
24 | 24 |
25 # Setup environment variables until we support passing arguments to fletch | 25 # Setup environment variables until we support passing arguments to dartino |
26 # programs. | 26 # programs. |
27 if [ ! -r /etc/default/dartino-agent ]; then | 27 if [ ! -r /etc/default/dartino-agent ]; then |
28 echo "Missing Dartino environment file, /etc/default/dartino-agent" | 28 echo "Missing Dartino environment file, /etc/default/dartino-agent" |
29 exit 1 | 29 exit 1 |
30 fi | 30 fi |
31 . /etc/default/dartino-agent | 31 . /etc/default/dartino-agent |
32 | 32 |
33 # Check the environment and create VM directories if necessary. | 33 # Check the environment and create VM directories if necessary. |
34 if [ ! -x $FLETCH_VM ]; then | 34 if [ ! -x $DARTINO_VM ]; then |
35 log_daemon_msg "No Dartino VM found or VM not executable" | 35 log_daemon_msg "No Dartino VM found or VM not executable" |
36 fi | 36 fi |
37 if [ ! -d $VM_LOG_DIR ]; then | 37 if [ ! -d $VM_LOG_DIR ]; then |
38 mkdir -p $VM_LOG_DIR | 38 mkdir -p $VM_LOG_DIR |
39 fi | 39 fi |
40 | 40 |
41 case "$1" in | 41 case "$1" in |
42 start) log_daemon_msg "Starting" "$NAME" | 42 start) log_daemon_msg "Starting" "$NAME" |
43 start-stop-daemon --background --start --quiet --oknodo \ | 43 start-stop-daemon --background --start --quiet --oknodo \ |
44 » --pidfile $AGENT_PID_FILE --exec $FLETCH_VM $AGENT_SNAPSHOT | 44 » --pidfile $AGENT_PID_FILE --exec $DARTINO_VM $AGENT_SNAPSHOT |
45 log_end_msg $? | 45 log_end_msg $? |
46 ;; | 46 ;; |
47 stop) log_daemon_msg "Stopping" "$NAME" | 47 stop) log_daemon_msg "Stopping" "$NAME" |
48 » killproc -p $AGENT_PID_FILE $FLETCH_VM | 48 » killproc -p $AGENT_PID_FILE $DARTINO_VM |
49 RETVAL=$? | 49 RETVAL=$? |
50 [ $RETVAL -eq 0 ] && [ -e "$AGENT_PID_FILE" ] && rm -f $AGENT_PID_FILE | 50 [ $RETVAL -eq 0 ] && [ -e "$AGENT_PID_FILE" ] && rm -f $AGENT_PID_FILE |
51 log_end_msg $RETVAL | 51 log_end_msg $RETVAL |
52 ;; | 52 ;; |
53 restart) log_daemon_msg "Restarting" "$NAME" | 53 restart) log_daemon_msg "Restarting" "$NAME" |
54 $0 stop | 54 $0 stop |
55 sleep 2 | 55 sleep 2 |
56 $0 start | 56 $0 start |
57 ;; | 57 ;; |
58 status) | 58 status) |
59 » status_of_proc -p $AGENT_PID_FILE $FLETCH_VM $NAME && exit 0 || exit $? | 59 » status_of_proc -p $AGENT_PID_FILE $DARTINO_VM $NAME && exit 0 || exit $? |
60 ;; | 60 ;; |
61 *) log_action_msg \ | 61 *) log_action_msg \ |
62 "Usage: /etc/init.d/dartino-agent {start|stop|status|restart}" | 62 "Usage: /etc/init.d/dartino-agent {start|stop|status|restart}" |
63 exit 2 | 63 exit 2 |
64 ;; | 64 ;; |
65 esac | 65 esac |
66 exit 0 | 66 exit 0 |
OLD | NEW |