-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathsetup-dns.sh
executable file
·83 lines (67 loc) · 2.03 KB
/
setup-dns.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
set -uo pipefail
#==============================================================#
# File : setup-dns.sh
# Mtime : 2019-03-02
# Desc : Setup DNS for pg testing env
# Path : bin/setup-dns.sh
# Author : Vonng([email protected])
# Note : Run this as root
#==============================================================#
# module info
__MODULE_SETUP_DNS="setup-dns"
PROG_DIR="$(cd $(dirname $0) && pwd)"
PROG_NAME="$(basename $0)"
#--------------------------------------------------------------#
# Name: setup_dns
# Desc: Write pgtest DNS entries to /etc/hosts
# Note: Run this in localhost and virtual machines
#--------------------------------------------------------------#
function setup_dns() {
if [[ $(whoami) != "root" ]]; then
echo "error: setup-dns.sh require root privilege"
return 1
fi
if $(grep 'pgtest dns entries' /etc/hosts > /dev/null 2>&1); then
echo "warn: dns already set in /etc/hosts, skip"
return 0
fi
cat >> /etc/hosts <<- EOF
# pgtest dns entries
10.10.10.10 test001m01
10.10.10.10 n1
10.10.10.10 primary
10.10.10.10 primary.test
10.10.10.10 primary.test.pg
10.10.10.11 test001s01
10.10.10.11 n2
10.10.10.11 standby
10.10.10.11 standby.test
10.10.10.11 standby.test.pg
10.10.10.12 test001o01
10.10.10.12 n3
10.10.10.12 offline
10.10.10.12 offline.test
10.10.10.12 offline.test.pg
10.10.10.13 meta001m01
10.10.10.13 n4
10.10.10.13 meta
10.10.10.13 primary.meta
10.10.10.13 primary.meta.pg
10.10.10.13 monitor
EOF
if [[ $? != 0 ]]; then
echo "error: write dns record failed"
return 2
fi
return 0
}
#==============================================================#
# Main #
#==============================================================#
# Code:
# 0 ok
# 1 insufficient privilege
# 2 write DNS record to /etc/hosts failed
#==============================================================#
setup_dns