#! /bin/sh
### BEGIN INIT INFO
# Provides: mono-xsp
# Required-Start:
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Mono XSP
# Description: Debian init script for Mono XSP.
### END INIT INFO
#
# Written by Pablo Fischer
# Dylan R. E. Moonfire
# Modified for Debian GNU/Linux
#
# Version: @(#)mono-xsp
pablo@pablo.com.mx
#
# Variables
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/xsp
NAME=mono-xsp
DESC="XSP WebServer"
DEFAULT=/etc/default/$NAME
CFGDIR=/etc/xsp
VIRTUALFILE=$CFGDIR/debian.webapp
MONO_SHARED_DIR=/var/run/$NAME
# Use LSB
. /lib/lsb/init-functions
# If we don't have the basics, don't bother
test -x $DAEMON || exit 0
test -f $DEFAULT && . $DEFAULT
if [ ! -e $MONO_SHARED_DIR ];then
mkdir $MONO_SHARED_DIR
chown $user.$group $MONO_SHARED_DIR
fi
should_start() {
if [ ! -e $VIRTUALFILE -o `cat $VIRTUALFILE | wc -l` = "2" ]; then
log_action_msg "You have an incomplete $VIRTUALFILE"
log_action_msg "To fix it, you need to install at least one package for xsp (like asp.net-examples)"
return 1
fi
if [ -f /var/run/$NAME.pid ]; then
# Are we really running xsp?
xsp_pid=`cat /var/run/$NAME.pid`
xsp_ps=`ps -p $xsp_pid | wc -l`
if [ "$xsp_ps" != "1" ]; then
log_action_msg "Sorry, there is already a xsp running, stop it first"
return 1
fi
fi
return 0
}
case "$1" in
start)
if should_start ; then
log_daemon_msg "Starting $DESC" "$NAME"
export MONO_SHARED_DIR
start-stop-daemon --start --background --make-pidfile \
--quiet --pidfile /var/run/$NAME.pid \
--user $user --group $group --chuid $user \
--exec $DAEMON -- \
--port $port --address $address --appconfigdir \
$CFGDIR --nonstop
log_end_msg $?
fi
;;
stop)
log_daemon_msg "Stopping $DESC" "$NAME"
for i in $(ps aux | grep -v grep | grep 'xsp.exe' | cut -c 10-15)
do
kill $i >& /dev/null
done
log_end_msg $?
;;
restart|force-reload)
$0 stop
$0 start
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0