#!/bin/sh
### BEGIN INIT INFO
# Provides:          mesos-slave
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Should-Start:      docker
# Should-Stop:       docker
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the mesos slave
# Description:       The Mesos master slave performs computing tasks
### END INIT INFO
set -ue

NAME="mesos-slave"
DESC="mesos slave"

. /lib/lsb/init-functions

PID=/var/run/mesos-slave.pid

start() {
  start-stop-daemon --start --background --quiet \
                    --pidfile "$PID" --make-pidfile \
                    --startas /usr/bin/mesos-init-wrapper -- slave
}

stop() {
  start-stop-daemon --stop --quiet --pidfile "$PID"
}

case "$1" in
  start)
    echo -n "Starting $DESC: "
    start
    echo "$NAME."
    ;;
  stop)
    echo -n "Stopping $DESC: "
    stop
    echo "$NAME."
    ;;
  restart)
    echo -n "Restarting $DESC: "
    stop
    sleep 1
    start
    echo "$NAME."
    ;;
  status)
    status_of_proc -p "$PID" "$NAME" "$NAME"
    ;;
  *)
    echo "Usage: $0 {start|stop|restart|status}" >&2
    exit 1
    ;;
esac
