#!/bin/sh -ex # cd into couchdb directory, run ./replication-ring-continuous.sh N from there # requires N CouchDB installs running on ports 5985 to 5984 + N N=$1 if [ -z "$N" ]; then echo "usage: ./replication-ring-continuous.sh N" exit 1 fi setup_replication() { # pull replication N=$1 MAX=$2 TARGET_PORT=`expr 5984 + $N` # when we set up 1st couch, we replicate from Nth couch if [ $N -eq 1 ]; then SOURCE_PORT=`expr 5984 + $MAX` else SOURCE_PORT=`expr 5984 + $N - 1` fi TARGET="http://127.0.0.1:$TARGET_PORT" SOURCE="http://127.0.0.1:$SOURCE_PORT" # create dbs, ignore errors curl -X PUT "$SOURCE/db" curl -X PUT "$TARGET/db" curl -X POST "$TARGET/_replicate" -d "{\"source\":\"$SOURCE/db\",\"target\":\"db\",\"continuous\":true}" } MAX=$N while([ $N -gt 0 ]); do echo "Do CouchDB N=$N" setup_replication $N $MAX N=`expr $N - 1` done # insert some docs echo "Done" # Done