Revision 393465313963 () - Diff

Link to this snippet: https://friendpaste.com/6iC7KyOglqHFexivY9g1W
Embed:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/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