I'm putting XSP into production this week (yey, right on time for Mono 1.0.5). For those who don't know, XSP is a lightweight ASP.NET webserver for Mono (.NET). I have a few webservices that need to run on Linux, and XSP seemed like the easiest way to do it.One of the things I ran across was how to start up XSP automatically. I'm not that familiar with Linux yet, so I wasn't sure how to go about it. The only site I found with anything on it is here, but it didn't work correctly (shutdown) for me. So after playing around with other scripts made for mod_mono (didn't work), I decided to figure out how init.d scripts work. After a bit of learning and lots of copy and paste from the other init.d files, I came up with the following. I'm pretty sure it's not that great, so please correct me.Steps: 1 - Create /etc/init.d/xsp and paste the contents in (from below). Be sure the permissions are right (chmod 755 /etc/init.d/xsp). 2 - Create /etc/xsp.conf and add the command-line args. Example: --port 8080 --root /path/to/site/ 3 - Run chkconfig --add chkconfig 4 - service xsp start/etc/init.d/xsp:#!/bin/bash## Startup script for xsp server## chkconfig: 3 84 16# description: xsp is a asp.net server# ARGS=`cat /etc/xsp.conf | grep -v \# `
. /etc/init.d/functions
start() { echo -n $"Starting xsp: " # Check PID/existence pid="" if [ -f /var/run/xsp.pid ] ; then read pid < /var/run/xsp.pid if [ -n "$pid" ]; then rm /var/run/xsp.pid else echo -n $"xsp is already running." failure echo return 1 fi fi
mono /usr/bin/xsp.exe --nonstop $ARGS > /dev/null & RETVAL=$? if [ $RETVAL != 0 ]; then failure echo return $RETVAL fi PID=$! echo $PID > /var/run/xsp.pid success echo return 0}
stop() { echo -n $"Shutting down xsp: "
if [ ! -f /var/run/xsp.pid ]; then echo -n $"xsp not running" failure echo return 1 fi
kill -15 `cat /var/run/xsp.pid` RETVAL=$?
if [ $RETVAL = 0 ]; then rm /var/run/xsp.pid success echo return 0 else failure echo return $RETVAL fi }
restart() { stop start}
case "$1" in start) start ;; stop) stop ;; restart) restart ;; *) echo $"Usage: $0 {start|stop|restart}" exit 1esac
exit $?
Remember Me