Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Changes to couchdb (1.3.0) startup script
*** etc/init/couchdb Tue Apr 30 15:11:17 2013
--- /etc/rc.d/couchdb Thu May 2 11:34:40 2013
***************
*** 66,72 ****
command="$command $COUCHDB_OPTIONS"
fi
if test -n "$COUCHDB_USER"; then
! if su $COUCHDB_USER -c "$command"; then
return $SCRIPT_OK
else
return $SCRIPT_ERROR
--- 67,73 ----
command="$command $COUCHDB_OPTIONS"
fi
if test -n "$COUCHDB_USER"; then
! if su -l $COUCHDB_USER -c "$command"; then
return $SCRIPT_OK
else
return $SCRIPT_ERROR
*** bin/couchdb Tue Apr 30 15:11:16 2013
--- /usr/local/bin/couchdb Thu May 2 11:33:50 2013
***************
*** 28,33 ****
--- 28,34 ----
LOCAL_CONFIG_DIR=/usr/local/etc/couchdb/local.d
LOCAL_CONFIG_FILE=/usr/local/etc/couchdb/local.ini
PID_FILE=/usr/local/var/run/couchdb/couchdb.pid
+ SHEPARD_PID_FILE=/usr/local/var/run/couchdb/couchdb_shep.pid
RECURSED=false
RESET_CONFIG=true
RESPAWN_TIMEOUT=0
***************
*** 112,117 ****
--- 113,125 ----
false
}
+ _get_shep_pid () {
+ if test -f $SHEPARD_PID_FILE; then
+ SHEPPID=`cat $SHEPARD_PID_FILE`
+ fi
+ echo $SHEPPID
+ }
+
_get_pid () {
if test -f $PID_FILE; then
PID=`cat $PID_FILE`
***************
*** 236,241 ****
--- 244,250 ----
if test "$BACKGROUND" = "true" -a "$RECURSED" = "false"; then
$0 $background_start_arguments -b -r $RESPAWN_TIMEOUT -p $PID_FILE \
-o $STDOUT_FILE -e $STDERR_FILE -R &
+ printf "$!" > $SHEPARD_PID_FILE
echo "Apache CouchDB has started, time to relax."
else
if test "$RECURSED" = "true"; then
***************
*** 270,275 ****
--- 279,289 ----
}
stop_couchdb () {
+ # First, we need to kill the shepard program, otherwise it will respawn
+ SHEP_PID=`_get_shep_pid`
+ if test -n "$SHEP_PID"; then
+ kill -TERM $SHEP_PID 2> /dev/null
+ fi
PID=`_get_pid`
STOP_TIMEOUT=60
if test -n "$PID"; then
@mgmarino

This comment has been minimized.

Copy link
Owner Author

mgmarino commented Nov 22, 2013

The summary is that this now tracks the pid of the shepherd program, which respawns couchdb if it dies. When a stop of couchdb is requested, the shepherd program is killed before to avoid any re-spawning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.