Logo




Subscribe:
RSS 2.0 | Atom 1.0
Categories:

Sign In


[Giagnocavo]Michael::Write()

 Thursday, December 09, 2004
xsp init.d service script

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 1
esac

exit $?

Code
Thursday, December 09, 2004 6:33:30 AM UTC  #    Comments [1]  |  Trackback Tracked by:
"http://cypvori.biz/college-basketball-recruiting.html" (http://cypvori.biz/coll... [Pingback]


Thursday, December 09, 2004 8:08:23 AM UTC
My Debian system installs the following init.d-file for XSP (I'm pretty sure it auto-starts the server - YMMV):

http://totalannihilation.dk/mac/download/mono-xsp

Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Live Comment Preview