#! /bin/sh
### BEGIN INIT INFO
# Provides:          cerberus
# Required-Start:    $syslog $time $remote_fs
# Required-Stop:     $syslog $time $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Self hosting cerberus
# Description:       Debian init script for the cerberus
### END INIT INFO


sessionName=Cerberus
user=ubuntu
execCommand="/usr/bin/mono /ebs/bin/cerberus/SelfHostingCerberus.exe"

Green='\033[0;32m'        # Green
Red='\033[0;31m'          # Red
NoColor='\033[0m'         # Text Reset


case "$1" in
  start)
    echo -n "Starting $sessionName: "
    sudo -H -u $user /usr/bin/tmux new -d -s $sessionName $execCommand
    eror=$?

    if [ $eror -eq 0 ];then
       echo "${Green}Ok${NoColor} $sessionName started uder tmux successfully"
    else
       echo -e "${Red}Error${NoColor} starting $sessionName"
    fi
    ;;
  stop)
    echo -n "Stopping $sessionName: "
    sudo -H -u $user /usr/bin/tmux kill-session -t $sessionName
    eror=$?
    if [ $eror -eq 0 ];then
       echo "${Green}Ok${NoColor} $sessionName stopped successfully"
    else
       echo -e "${Red}Error${NoColor} stopped $sessionName"
    fi
    ;;
  force-reload|restart)
    $0 stop
    $0 start
    ;;
  status)
    #status_of_proc -p $PIDFILE $DAEMON atd && exit 0 || exit $?
    sudo -H -u $user /usr/bin/tmux ls
    ;;
  *)
    echo "Usage: /etc/init.d/cerberus {start|stop|restart|status}"
    exit 1
    ;;
esac

exit 0