Complete Ramblings

My thoughts (facts) on everything

Tuesday, July 29, 2008

Gem Server Init Script

We recently upgraded from rubygems 0.9.x to 1.2.0. Unfortunately, there doesn’t appear to be a working service init script for this new version, so I had to hand-craft a basic one to start/stop the service. You’ll find it below in all its glory (and probably under/incorrectly-implemented as I am in no way a linux guru, nor do I intend to be). It works for my use however, maybe it’ll help you.

#!/bin/bash
# chkconfig: 2345 20 80
# description: gem server
# processname: gem_server
# pidfile: /var/lock/subsys/gem_server

source /etc/rc.d/init.d/functions
prog=”/usr/local/bin/gem server –daemon”

start() {
pid=$(ps ax -o pid,command | grep “gem server” | grep daemon | awk ‘{print $1}’)
if test -n “$pid”
then
echo “gem server already running : PID $pid”
else
$prog
fi
}

stop() {
pid=$(ps ax -o pid,command | grep “gem server” | grep daemon | awk ‘{print $1}’)
if test -n “$pid”
then
echo “stopping gem server”
kill $pid
else
echo “gem server not running”
fi
}

case “$1″ in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo $”Usage: $0 {start|stop|restart}”
exit 1
esac

posted by Justin at 9:40 am  

Powered by WordPress