couchbase-server upstart script

For those of you exploring the inner workings of couchbase and trying to bend it to your will. I have just finished an upstart script that should make your life easier. The current couchbase comes with just an old init.d script which does the job, but does not make it that easy to tie success in couchbase starting up to anything else in the upstart framework..

So without further ado

description "Couchbase Upstart Script".
version "0.1.0"
author "Keith Marlow"
start on runlevel [2345]
stop on runlevel ![2345]
env PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
env DAEMON=/opt/couchbase/bin/couchbase-server
env PIDFILE=/opt/couchbase/var/lib/couchbase/couchbase-server.pid
env NODEFILE=/opt/couchbase/var/lib/couchbase/couchbase-server.node
env COOKIEFILE=/opt/couchbase/var/lib/couchbase/couchbase-server.cookie
env STARTEDFILE=/opt/couchbase/var/lib/couchbase/couchbase-server.started
respawn
respawn limit 15 15
expect fork
pre-start script
 touch $PIDFILE $NODEFILE $COOKIEFILE
 touch $STARTEDFILE
end script
limit nofile 10250 10250
limit fsize unlimited unlimited
limit memlock unlimited unlimited
chdir /opt/couchbase/var/lib/couchbase
setuid couchbase
script
 echo $$ > $PIDFILE
 exec $DAEMON -- -noinput -detached
end script
# Remove pid file when we stop the server
pre-stop script
 $DAEMON -k
 rm $PIDFILE $STARTEDFILE
end script

 

The above starts up the couchbase server with the right environment and ensures upstart keeps a track of the right process at all times (the expect fork bit).

Remember to use update-rc.d -f couchbase-server remove to remove couchbase from the clutches of the old init.d startup framework.

This was done on the latest 12.04 Ubuntu.

Enjoy

Keith