forked from postgres/postgres
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsetup.sh
executable file
·68 lines (59 loc) · 1.61 KB
/
setup.sh
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
DBNAME=postgres
DBUSER=$USER
HOSTS=hosts.lst
PORT=5432
ARBITER_PORT=4321
while getopts ":d:u:l:a:p:" opt; do
case $opt in
p) PORT="$OPTARG"
;;
a) ARBITER_PORT="$OPTARG"
;;
d) DBNAME="$OPTARG"
;;
u) DBUSER="$OPTARG"
;;
h) HOSTS="$OPTARG"
;;
\?) echo "Invalid option -$OPTARG" >&2
echo "Supported options:"
echo " -p PORT postgres server port ($PORT)"
echo " -a PORT multimaster arbiter port ($ARBITER_PORT)"
echo " -d DBNAME postgres database name ($DBNAME)"
echo " -u DBUSER postgres database user ($USER)"
echo " -h FILE file with list of hosts ($HOSTS)"
exit 1
;;
esac
done
echo "Setup multimaster dbname=$DBNAME user=$DBUSER hosts=$HOSTS port=$PORT arbiter_port=$ARBITER_PORT"
rm -f nodes.lst # nodes.lst will be contructed from
for host in $HOSTS
do
echo "dbname=$DBNAME user=$DBUSER host=$host port=$PORT arbiter_port=$ARBITER_PORT sslmode=disable" >> nodes.lst
done
i=1
for host in $HOSTS
do
echo "Setup database at node $host"
ssh $host "rm -fr node$i node$i.log ; initdb node$i"
if [ "$DBNAME" != "postgres" ]
then
ssh $host "pg_ctl -w -D node$i -l node$i.log start; createdb $DBNAME; pg_ctl -w -D node$i -l node$i.log stop"
fi
scp pg_hba.conf.template $host:node$i/pg_hba.conf
scp nodes.lst n$host:node$i
scp postgresql.conf.template $host:node$i/postgresql.conf
ssh $host "echo port=$PORT >> node$i/postgresql.conf"
ssh $host "echo multimaster.arbiter_port=$ARBITER_PORT >> node$i/postgresql.conf"
((i++))
done
i=1
for host in $HOSTS
do
ssh $host "pg_ctl -D node$i -l node$i.log start"
((i++))
done
sleep 5
echo Done