#!/bin/sh
#
### BEGIN INIT INFO
# Provides:          rstudio-launcher
# Required-Start:    $local_fs $remote_fs $syslog $network $named
# Required-Stop:     $local_fs $remote_fs $syslog $network $named
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: RStudio Launcher
# Description:       RStudio Launcher provides a means to launch jobs on various cluster/batch systems.
### END INIT INFO

# Check for missing binaries 
LAUNCHER_BIN="/usr/lib/rstudio-server/bin/rstudio-launcher"
test -x $LAUNCHER_BIN || { echo "$LAUNCHER_BIN not installed";
	if [ "$1" = "stop" ]; then exit 0;
	else exit 5; fi; }


# Source LSB init functions
. /etc/rc.status

# Reset status of this service
rc_reset

case "$1" in
    start)
        echo -n "Starting rstudio-launcher "

	## Start daemon with startproc(8). If this fails
	## the return value is set appropriately by startproc.
        /sbin/startproc -s -q $LAUNCHER_BIN

	# Remember status and be verbose
	rc_status -v
	;;
    stop)
        echo -n "Shutting down rstudio-launcher "

	## Stop daemon with killproc(8) and if this fails
	## killproc sets the return value according to LSB.
        /sbin/killproc $LAUNCHER_BIN

	# Remember status and be verbose
	rc_status -v
	;;
    restart)
	## Stop the service and regardless of whether it was
	## running or not, start it again.
	$0 stop
	$0 start

	# Remember status and be quiet
	rc_status
	;;
    reload)
	## we don't support reload
	rc_failed 3
	rc_status -v
	;;
    status)
        echo -n "Checking for service rstudio-launcher"

	## Check status with checkproc(8), if process is running
	## checkproc will return with exit status 0.
        /sbin/checkproc $LAUNCHER_BIN

	# Remember status and be verbose
	rc_status -v
	;;
esac
rc_exit
