Skip to content

Instantly share code, notes, and snippets.

@wilsonmichael
Created June 7, 2013 09:15
Show Gist options
  • Save wilsonmichael/5728060 to your computer and use it in GitHub Desktop.
Save wilsonmichael/5728060 to your computer and use it in GitHub Desktop.
Rserve init.d file that uses R to startup Rserve and stops correctly
!/bin/sh
. /lib/lsb/init-functions
## Variables
LOGFILE="/srv/R/tmp/Rserv/rserve.log"
CONFIGFILE="/etc/Rserv.conf"
RUN_AS="webapps"
# Rserve configs
RBIN="/usr/bin/R"
RCMD="CMD Rserve --vanilla"
DAEMON="/usr/lib/R/bin/Rserve"
#test -f $CONFIGFILE || exit 0
#test -x $DAEMON || exit 0
stop_rserve()
{
# Stop the Rserve daemon
start-stop-daemon --stop --quiet --oknodo --exec $DAEMON
}
start_rserve()
{
# Start the Rsere daemon with the R CMD
start-stop-daemon --start --quiet --oknodo --chuid $RUN_AS --exec $RBIN -- $RCMD;
}
case "$1" in
start)
log_daemon_msg "Starting rserve"
if start_rserve ; then
log_end_msg 0
else
log_end_msg 1
fi
;;
stop)
log_daemon_msg "Stopping rserve"
if stop_rserve; then
log_end_msg 0
else
log_end_msg 1
fi
;;
restart)
log_daemon_msg "Stopping rserve for restart"
stop_rserve
log_end_msg 0
sleep 2
log_daemon_msg "Restarting rserve"
start_rserve
log_end_msg 0
;;
status)
status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment