| 1 |
#! /bin/sh |
| 2 |
### BEGIN INIT INFO |
| 3 |
# Provides: shiny-server |
| 4 |
# Required-Start: $remote_fs |
| 5 |
# Required-Stop: $remote_fs |
| 6 |
# Default-Start: 2 3 4 5 |
| 7 |
# Default-Stop: 0 1 6 |
| 8 |
# Short-Description: shiny Server |
| 9 |
# Description: shiny server deploys R shiny applications |
| 10 |
### END INIT INFO |
| 11 |
|
| 12 |
# Author: RStudio <[email protected]> |
| 13 |
# |
| 14 |
|
| 15 |
# Do NOT "set -e" |
| 16 |
|
| 17 |
# PATH should only include /usr/* if it runs after the mountnfs.sh script |
| 18 |
PATH=/sbin:/usr/sbin:/bin:/usr/bin |
| 19 |
DESC="shiny server" |
| 20 |
NAME=shiny-server |
| 21 |
DAEMON=shiny-server |
| 22 |
SCRIPTNAME=/etc/init.d/shiny-server |
| 23 |
|
| 24 |
# Exit if the package is not installed |
| 25 |
[ -x "$DAEMON" ] || exit 0 |
| 26 |
|
| 27 |
# Load the VERBOSE setting and other rcS variables |
| 28 |
. /lib/init/vars.sh |
| 29 |
|
| 30 |
# Define LSB log_* functions. |
| 31 |
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present. |
| 32 |
. /lib/lsb/init-functions |
| 33 |
|
| 34 |
# |
| 35 |
# Function that starts the daemon/service |
| 36 |
# |
| 37 |
do_start() |
| 38 |
{ |
| 39 |
# Return |
| 40 |
# 0 if daemon has been started |
| 41 |
# 1 if daemon was already running |
| 42 |
# 2 if daemon could not be started |
| 43 |
start-stop-daemon --start --quiet --background --exec $DAEMON --test > /dev/null \ |
| 44 |
|| return 1 |
| 45 |
start-stop-daemon --start --quiet --background --exec $DAEMON \ |
| 46 |
|| return 2 |
| 47 |
} |
| 48 |
|
| 49 |
# |
| 50 |
# Function that stops the daemon/service |
| 51 |
# |
| 52 |
do_stop() |
| 53 |
{ |
| 54 |
# Return |
| 55 |
# 0 if daemon has been stopped |
| 56 |
# 1 if daemon was already stopped |
| 57 |
# 2 if daemon could not be stopped |
| 58 |
# other if a failure occurred |
| 59 |
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --name $NAME |
| 60 |
RETVAL="$?" |
| 61 |
[ "$RETVAL" = 2 ] && return 2 |
| 62 |
return "$RETVAL" |
| 63 |
} |
| 64 |
|
| 65 |
case "$1" in |
| 66 |
start) |
| 67 |
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" |
| 68 |
do_start |
| 69 |
case "$?" in |
| 70 |
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
| 71 |
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
| 72 |
esac |
| 73 |
;; |
| 74 |
stop) |
| 75 |
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" |
| 76 |
do_stop |
| 77 |
case "$?" in |
| 78 |
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
| 79 |
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
| 80 |
esac |
| 81 |
;; |
| 82 |
restart|force-reload) |
| 83 |
log_daemon_msg "Restarting $DESC" "$NAME" |
| 84 |
do_stop |
| 85 |
case "$?" in |
| 86 |
0|1) |
| 87 |
do_start |
| 88 |
case "$?" in |
| 89 |
0) log_end_msg 0 ;; |
| 90 |
1) log_end_msg 1 ;; # Old process is still running |
| 91 |
*) log_end_msg 1 ;; # Failed to start |
| 92 |
esac |
| 93 |
;; |
| 94 |
*) |
| 95 |
# Failed to stop |
| 96 |
log_end_msg 1 |
| 97 |
;; |
| 98 |
esac |
| 99 |
;; |
| 100 |
*) |
| 101 |
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 |
| 102 |
exit 3 |
| 103 |
;; |
| 104 |
esac |
| 105 |
|
| 106 |
: |