Skip to content

Instantly share code, notes, and snippets.

@vjt
Created November 3, 2010 13:13
Show Gist options
  • Save vjt/661059 to your computer and use it in GitHub Desktop.
Save vjt/661059 to your computer and use it in GitHub Desktop.
# CouchDB replication configuration restore,
# after a restart via the init script.
# Configure your replicas in a plain text file:
-----8<------------------------------------------------------->8------
# Credentials to access the database,
# in the username:password format.
#
CREDENTIALS admin:password
# Source Target
#
https://user:[email protected]/panmind panmind
-----8<------------------------------------------------------->8------
# Add these pieces to your couchdb init script:
# Variable
REPLICAS=/usr/local/etc/couchdb/replicas
# Function
setup_replicas () {
[ -r $REPLICAS ] || return
echo -n ' * Setting up replicas: waiting..'
while ! nc -z localhost 5984; do
echo -n '.'
sleep 1;
done
echo 'ok, configuring'
local uri="http://localhost:5984/_replicate"
while read source target; do
case "$source" in
\#*) continue ;;
CREDENTIALS)
uri=`echo $uri|sed "s#^http://#&$target@#"`
;;
*)
[ -z "$source" -o -z "$target" ] && continue
echo -n ' * '
curl -X POST "$uri" -H "Content-Type: application/json" --data-binary \
'{"source":"'$source'", "target":"'$target'", "continuous":true}'
;;
esac
done < $REPLICAS
}
# Call setup_replics after starting CouchDB,
# around line 172 of the distributed script:
170 log_daemon_msg "Starting $DESCRIPTION" $NAME
171 if start_couchdb; then
172 setup_replicas
173 log_end_msg $SCRIPT_OK
174 else
175 log_end_msg $SCRIPT_ERROR
176 fi
# And on the following start_couchdb invocation as well, in the "restart" block.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment