debian init.d script for shiny-server

99 views
Skip to first unread message

Gareth Williams

unread,
Sep 3, 2015, 4:28:40 AM9/3/15
to Shiny - Web Framework for R
I had problems with the existing init.d script for shiny-server and have made some additions and fixes.I'm pasting the diffs here, interspersed with comments in bold and am hoping most can be incorporated into the source.

Gareth

diff -Naur /apps/shiny-server/1.4.0/shiny-server/config/init.d/debian/shiny-server /etc/init.d/shiny-server
--- /apps/shiny-server/1.4.0/shiny-server/config/init.d/debian/shiny-server     2015-04-15 00:30:49.000000000 +1000
+++ /etc/init.d/shiny-server    2015-08-31 13:03:21.931666888 +1000

set some variables that might need to be customized and source a default file to override the distribution defaults
I set R and DAEMON and USERID (which could be unset for root) in /etc/default/shiny-server
PIDFILE must go in a directory that USERID can write to

@@ -19,13 +19,22 @@
 DESC="shiny server"
 NAME=shiny-server
 DAEMON=shiny-server
+USERID=shiny
+LOGDIR=/var/log/${NAME}
+LOG=${LOGDIR}/${NAME}.log
+PIDFILE=/var/run/${NAME}/${NAME}.pid
 SCRIPTNAME=/etc/init.d/shiny-server
+if [ -f /etc/default/$NAME ]; then
+       . /etc/default/$NAME
+fi
+
 
note that this check is busted unless DAEMON is customized to specify the full path

 # Exit if the package is not installed
 [ -x "$DAEMON" ] || exit 0
 
my debian setup gives no feedback if VERBOSE is not set to yes - and it gets set to no in vars.sh :-(

 # Load the VERBOSE setting and other rcS variables
 . /lib/init/vars.sh
+VERBOSE=yes
 
a few changes here...
options to run without root
a bit of bash to make the $LOG get written as $USERID
use shiny-server's pidfile capability to enable cleaner status and stop

 # Define LSB log_* functions.
 # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
@@ -42,7 +51,10 @@
        #   2 if daemon could not be started
        start-stop-daemon --start --quiet --background --exec $DAEMON --test > /dev/null \
                || return 1
-       start-stop-daemon --start --quiet --background --exec $DAEMON \
+       start-stop-daemon --start --background --name $NAME \
+               ${USERID:+"--user"} ${USERID:+"$USERID"} \
+               ${USERID:+"--chuid"} ${USERID:+"$USERID"} \
+               --startas /bin/bash -- -c "exec $DAEMON --pidfile=$PIDFILE >> $LOG  2>&1" \
                || return 2
 }
 
without this change, the service script itself would be killed on stop

@@ -56,7 +68,7 @@
        #   1 if daemon was already stopped
        #   2 if daemon could not be stopped
        #   other if a failure occurred
-       start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --name $NAME
+       start-stop-daemon --stop --pidfile=$PIDFILE --retry=TERM/30/KILL/5 --name $NAME
        RETVAL="$?"
        [ "$RETVAL" = 2 ] && return 2
        return "$RETVAL"

adding a status option seemed a good idea

@@ -79,6 +91,9 @@
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        esac
        ;;
+  status)
+       status_of_proc -p $PIDFILE $DAEMON $NAME
+       ;;
   restart|force-reload)
        log_daemon_msg "Restarting $DESC" "$NAME"
        do_stop
Reply all
Reply to author
Forward
0 new messages