2008-12-30 00:57:07 +01:00
|
|
|
#!/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
|
2012-03-24 21:12:55 +01:00
|
|
|
# http://localhost:SHELLINABOX_PORT
|
|
|
|
# where default port number is 4200.
|
2008-12-30 00:57:07 +01:00
|
|
|
### END INIT INFO
|
|
|
|
|
2012-03-24 21:12:55 +01:00
|
|
|
# Authors: Markus Gutschke <markus@shellinabox.com>, Marc Singer <elf@buici.com>
|
|
|
|
|
|
|
|
# PATH should only include /usr/* if it runs after the mountnfs.sh script
|
2008-12-30 00:57:07 +01:00
|
|
|
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
|
|
|
|
|
2012-03-24 21:12:55 +01:00
|
|
|
# Exit if the package is not installed
|
|
|
|
[ -x $DAEMON ] || exit 0
|
2008-12-30 00:57:07 +01:00
|
|
|
|
2012-03-24 21:12:55 +01:00
|
|
|
# Read configuration variable file if it is present
|
|
|
|
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
|
2008-12-30 00:57:07 +01:00
|
|
|
|
2012-03-24 21:12:55 +01:00
|
|
|
# Load the VERBOSE setting and other rcS variables
|
|
|
|
. /lib/init/vars.sh
|
|
|
|
|
|
|
|
# Define LSB log_* functions.
|
|
|
|
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
|
|
|
|
. /lib/lsb/init-functions
|
2008-12-30 00:57:07 +01:00
|
|
|
|
2009-03-30 18:09:37 +02:00
|
|
|
# Set some default values
|
|
|
|
SHELLINABOX_DATADIR="${SHELLINABOX_DATADIR:-/var/lib/shellinabox}"
|
|
|
|
SHELLINABOX_PORT="${SHELLINABOX_PORT:-4200}"
|
|
|
|
SHELLINABOX_USER="${SHELLINABOX_USER:-shellinabox}"
|
|
|
|
SHELLINABOX_GROUP="${SHELLINABOX_GROUP:-shellinabox}"
|
|
|
|
|
2012-04-07 19:53:29 +02:00
|
|
|
# Export SO file names
|
|
|
|
export SHELLINABOX_LIBCRYPTO_SO="${SHELLINABOX_LIBCRYPTO_SO:-libcrypto.so}"
|
|
|
|
export SHELLINABOX_LIBSSL_SO="${SHELLINABOX_LIBSSL_SO:-libssl.so}"
|
|
|
|
|
2008-12-30 00:57:07 +01:00
|
|
|
#
|
|
|
|
# Function that starts the daemon/service.
|
|
|
|
#
|
|
|
|
d_start() {
|
|
|
|
if [ -z "$SHELLINABOX_DAEMON_START" -o \
|
|
|
|
"$SHELLINABOX_DAEMON_START" = "0" ]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2009-08-12 21:55:25 +02:00
|
|
|
eval start-stop-daemon --start --oknodo --pidfile "'$PIDFILE'" \
|
|
|
|
--exec "'$DAEMON'" -- -q --background="'$PIDFILE'" \
|
|
|
|
-c "'${SHELLINABOX_DATADIR}'" -p "'${SHELLINABOX_PORT}'" \
|
|
|
|
-u "'${SHELLINABOX_USER}'" -g "'${SHELLINABOX_GROUP}'" \
|
2009-08-15 07:24:31 +02:00
|
|
|
$(for i in $(ls /etc/shellinabox/options-enabled/*.css |
|
|
|
|
sed -e \
|
|
|
|
's/.*[/]\([0-9]*\)[-_+][^/:,;]*[.]css/\1/'|
|
|
|
|
sort -u); do
|
|
|
|
for j in /etc/shellinabox/options-enabled/"$i"*.css; do
|
|
|
|
echo -n "$j" |
|
|
|
|
sed -e 's/\(.*[/]\)\([0-9]*\)\([-_+]\)\([^/:,;]*\)[.]css/\4:\3\1\2\3\4.css,/
|
|
|
|
s/:_/:-/'
|
|
|
|
done |
|
|
|
|
sed -e 's/,$/;/'
|
|
|
|
done |
|
|
|
|
sed -e 's/;$//
|
|
|
|
//b
|
|
|
|
s/.*/--user-css "\0"/') \
|
2009-08-12 21:55:25 +02:00
|
|
|
"${SHELLINABOX_ARGS}"
|
2008-12-30 00:57:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# 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() {
|
2012-01-04 10:32:12 +01:00
|
|
|
[ -r "$PIDFILE" ] && kill -0 `cat "$PIDFILE"` &&
|
2008-12-30 00:57:07 +01:00
|
|
|
echo "$DESC is running" || echo "$DESC is not running"
|
|
|
|
}
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
start)
|
2012-03-24 21:12:55 +01:00
|
|
|
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
|
2008-12-30 00:57:07 +01:00
|
|
|
d_start
|
2012-03-24 21:12:55 +01:00
|
|
|
case "$?" in
|
|
|
|
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
|
|
|
|
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
|
|
|
|
esac
|
2008-12-30 00:57:07 +01:00
|
|
|
;;
|
|
|
|
stop)
|
2012-03-24 21:12:55 +01:00
|
|
|
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
|
2008-12-30 00:57:07 +01:00
|
|
|
d_stop
|
2012-03-24 21:12:55 +01:00
|
|
|
case "$?" in
|
|
|
|
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
|
|
|
|
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
|
|
|
|
esac
|
2008-12-30 00:57:07 +01:00
|
|
|
;;
|
|
|
|
reload)
|
2012-03-24 21:12:55 +01:00
|
|
|
[ "$VERBOSE" != no ] && log_daemon_msg "Reloading services for $DESC" "$NAME"
|
2008-12-30 00:57:07 +01:00
|
|
|
d_reload
|
2012-03-24 21:12:55 +01:00
|
|
|
case "$?" in
|
|
|
|
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
|
|
|
|
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
|
|
|
|
esac
|
2008-12-30 00:57:07 +01:00
|
|
|
;;
|
|
|
|
restart|force-reload)
|
2012-03-24 21:12:55 +01:00
|
|
|
[ "$VERBOSE" != no ] && log_daemon_msg "Restarting $DESC" "$NAME"
|
2008-12-30 00:57:07 +01:00
|
|
|
d_stop
|
|
|
|
d_start
|
2012-03-24 21:12:55 +01:00
|
|
|
case "$?" in
|
|
|
|
0) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
|
|
|
|
1) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
|
|
|
|
*) [ "$VERBOSE" != no ] && log_end_msg 1 ;; # Failed to start
|
|
|
|
esac
|
2008-12-30 00:57:07 +01:00
|
|
|
;;
|
|
|
|
status)
|
|
|
|
d_status
|
2012-01-04 10:32:12 +01:00
|
|
|
;;
|
2008-12-30 00:57:07 +01:00
|
|
|
*)
|
|
|
|
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|reload}" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|