Thomas Vachuska | 71ff332 | 2016-05-03 15:33:05 -0700 | [diff] [blame] | 1 | #! /bin/bash |
| 2 | # ----------------------------------------------------------------------------- |
| 3 | # init.d script to run ON.Lab test cell warden |
| 4 | ## ----------------------------------------------------------------------------- |
| 5 | ### BEGIN INIT INFO |
| 6 | # Provides: warden |
| 7 | # Required-Start: $network $remote_fs $syslog |
| 8 | # Required-Stop: $network $remote_fs $syslog |
| 9 | # Default-Start: 2 3 4 5 |
| 10 | # Default-Stop: 0 1 6 |
| 11 | # Short-Description: ON.Lab Test Cell Warden |
| 12 | # Description: Warden is a broker for sharing test cell infrastructure among ON.Lab developers. |
| 13 | ### END INIT INFO |
| 14 | |
| 15 | WARDEN_USER="sdn" |
| 16 | WARDEN_HOME="/home/$WARDEN_USER/warden" |
| 17 | WARDEN_VERSION="1.6.0-SNAPSHOT" |
| 18 | DEBUG="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005" |
| 19 | |
| 20 | cd $WARDEN_HOME |
| 21 | |
| 22 | start () { |
| 23 | # Start warden if it's not already running |
| 24 | if ! status >/dev/null; then |
| 25 | echo "Starting Warden" |
| 26 | startwarden |
| 27 | else |
| 28 | echo "Warden is already running" |
| 29 | fi |
| 30 | } |
| 31 | |
| 32 | startwarden () { |
| 33 | start-stop-daemon --signal INT --start --chuid $WARDEN_USER \ |
| 34 | --pidfile $WARDEN_HOME/warden.pid --make-pidfile \ |
| 35 | --background --chdir $WARDEN_HOME \ |
| 36 | --exec /usr/bin/java -- -jar onlab-warden-$WARDEN_VERSION.jar \ |
| 37 | &>$WARDEN_HOME/std.log |
| 38 | } |
| 39 | |
| 40 | stop () { |
| 41 | if status >/dev/null; then |
| 42 | echo "Stopping Warden" |
| 43 | start-stop-daemon --signal INT --stop --chuid $WARDEN_USER \ |
| 44 | --pidfile $WARDEN_HOME/warden.pid |
| 45 | rm warden.pid |
| 46 | else |
| 47 | echo "Warden is not running" |
| 48 | fi |
| 49 | } |
| 50 | |
| 51 | restart () { |
| 52 | stop |
| 53 | start |
| 54 | } |
| 55 | |
| 56 | status () { |
| 57 | start-stop-daemon --signal INT --status --chuid $WARDEN_USER \ |
| 58 | --pidfile $WARDEN_HOME/warden.pid |
| 59 | } |
| 60 | |
| 61 | case $1 in |
| 62 | start) |
| 63 | start |
| 64 | ;; |
| 65 | stop | force-stop) |
| 66 | stop |
| 67 | ;; |
| 68 | restart) |
| 69 | shift |
| 70 | restart "$@" |
| 71 | ;; |
| 72 | status) |
| 73 | status && echo "Warden is running" || echo "Warden is stopped" |
| 74 | exit $? |
| 75 | ;; |
| 76 | *) |
| 77 | echo "Usage: $0 {start|stop|restart|status}" >&2 |
| 78 | exit 1 |
| 79 | ;; |
| 80 | esac |
| 81 | |
| 82 | exit 0 |