107 lines
2.7 KiB
Text
107 lines
2.7 KiB
Text
|
#!/bin/sh
|
||
|
### BEGIN INIT INFO
|
||
|
# Provides: shellinabox
|
||
|
# Required-Start: $network $remote_fs
|
||
|
# Required-Stop: $network $remote_fs
|
||
|
# Default-Start: 2 3 4 5
|
||
|
# Default-Stop: 0 1 6
|
||
|
# Short-Description: Shell In A Box Daemon
|
||
|
# Description: Daemon for publishing a login shell at
|
||
|
# http://localhost:4200
|
||
|
### END INIT INFO
|
||
|
|
||
|
PATH=/sbin:/bin:/usr/sbin:/usr/bin
|
||
|
DESC="Shell In A Box Daemon"
|
||
|
NAME="shellinabox"
|
||
|
DAEMON="/usr/bin/shellinaboxd"
|
||
|
PIDFILE="/var/run/shellinaboxd.pid"
|
||
|
SCRIPTNAME=/etc/init.d/$NAME
|
||
|
|
||
|
# Gracefully exit if the package has been removed.
|
||
|
test -x $DAEMON || exit 0
|
||
|
|
||
|
. /lib/lsb/init-functions
|
||
|
|
||
|
# Include shellinabox defaults if available.
|
||
|
test -f /etc/default/shellinabox && . /etc/default/shellinabox
|
||
|
|
||
|
#
|
||
|
# Function that starts the daemon/service.
|
||
|
#
|
||
|
d_start() {
|
||
|
if [ -z "$SHELLINABOX_DAEMON_START" -o \
|
||
|
"$SHELLINABOX_DAEMON_START" = "0" ]; then
|
||
|
return 0
|
||
|
fi
|
||
|
|
||
|
start-stop-daemon --start --oknodo --quiet --pidfile "$PIDFILE" \
|
||
|
--exec "$DAEMON" -- -q --background="$PIDFILE" \
|
||
|
-c /var/lib/shellinabox -p ${SHELLINABOX_PORT:-4200} \
|
||
|
-u shellinabox -g shellinabox ${SHELLINABOX_ARGS}
|
||
|
}
|
||
|
|
||
|
#
|
||
|
# Function that stops the daemon/service.
|
||
|
#
|
||
|
d_stop() {
|
||
|
start-stop-daemon --stop --oknodo --pidfile "$PIDFILE"
|
||
|
rm -f "$PIDFILE"
|
||
|
}
|
||
|
|
||
|
#
|
||
|
# Function that reloads the config file for the daemon/service.
|
||
|
#
|
||
|
d_reload() {
|
||
|
# Only reload if there are no active sessions running
|
||
|
[ -r "$PIDFILE" ] &&
|
||
|
[ `ps o pid= --ppid "\`cat "$PIDFILE"\`\`ps o pid= --ppid \
|
||
|
\\\`cat "$PIDFILE"\\\`|
|
||
|
xargs -r -n 1 printf ',%s'\`" |
|
||
|
wc -l` -gt 1 ] &&
|
||
|
return 1
|
||
|
|
||
|
d_stop
|
||
|
d_start
|
||
|
}
|
||
|
|
||
|
#
|
||
|
# Function that check the status of the daemon/service.
|
||
|
#
|
||
|
d_status() {
|
||
|
[ -r "$PIDFILE" && kill -0 `cat "$PIDFILE"` ] &&
|
||
|
echo "$DESC is running" || echo "$DESC is not running"
|
||
|
}
|
||
|
|
||
|
case "$1" in
|
||
|
start)
|
||
|
log_daemon_msg "Starting $DESC" "$NAME"
|
||
|
d_start
|
||
|
log_end_msg $?
|
||
|
;;
|
||
|
stop)
|
||
|
log_daemon_msg "Stopping $DESC" "$NAME"
|
||
|
d_stop
|
||
|
log_end_msg $?
|
||
|
;;
|
||
|
reload)
|
||
|
log_daemon_msg "Reloading services for $DESC" "$NAME"
|
||
|
d_reload
|
||
|
log_end_msg $?
|
||
|
;;
|
||
|
restart|force-reload)
|
||
|
log_daemon_msg "Restarting $DESC" "$NAME"
|
||
|
d_stop
|
||
|
d_start
|
||
|
log_end_msg $?
|
||
|
;;
|
||
|
status)
|
||
|
d_status
|
||
|
;;
|
||
|
*)
|
||
|
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|reload}" >&2
|
||
|
exit 1
|
||
|
;;
|
||
|
esac
|
||
|
|
||
|
exit 0
|