Sunday 5 October 2008

Super cool startup script for linux

I recently had to get a startup script going which works on Ubuntu and Sles for loggerhead. I came up with these install instructions and following simple but super cool init script. Note that this should work for basically any linux daemon, you just need to rename the script (loggerheadd) and change the script a little.
  1. Copy loggerheadd to /etc/init.d
  2. Edit the file to configure it.
  3. Register the service:
    cd /etc/init.d
  • on upstart based systems like Ubuntu run:
    update-rc.d loggerheadd defaults
  • on Sysvinit based systems like Centos or SuSE run:
    chkconfig --add loggerheadd

Here follows the script (the indentation is a bit messed up by blogspot)

#!/bin/sh
### BEGIN INIT INFO
# Required-Start: $local_fs $remote_fs $network
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: Loggerhead
# Description: Manage Loggerhead (a web viewer for projects in bazaar)
### END INIT INFO

# Configure this please: #
LOGGERHEAD_PATH=/opt/loggerhead
LOG_FOLDER=/var/log/loggerhead
LOG_FILE=$LOG_FOLDER/loggerheadd.log
PREFIX=/loggerhead
PORT=8080

# You can add additional options to serve-branches here:
START_CMD="$LOGGERHEAD_PATH/serve-branches --prefix=$PREFIX --log-folder=$LOG_FOLDER --port=$PORT /var/lib/gforge/bzrroot/"

#
# main part
#
case "$1" in
start)
python $START_CMD > $LOG_FILE 2>&1 &
echo "Started loggerhead. (See $LOG_FOLDER for details.)"
;;
stop)
pkill -f "$START_CMD"
;;
status)
proccess=`pgrep -fl "$START_CMD"`
echo "$proccess"
netstat -anp |grep -e ":$PORT"
if [ -z "$proccess" ]; then
echo "Loggerhead is not running."
else
echo "Loggerhead is running."
fi
;;

*)
echo "Usage: loggerheadd { start | stop | status }"
exit 1
esac

1 comment:

  1. Just like to say thanks for this. Worked fine for me on Ubuntu Intrepid with loggerhead 1.6, except I had to remove the --log-folder option. It complained about that.

    ReplyDelete