Skip to content

Commit f70ba76

Browse files
committed
suspend remote dns if connection failed
1 parent bbc652c commit f70ba76

9 files changed

+85
-74
lines changed

bin/v-add-remote-dns-domain

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ fi
5050
old_ifs="$IFS"
5151
IFS=$'\n'
5252

53-
# Starting cluster loop
54-
for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
53+
# Check remote dns nodes
54+
remote_dns_health_check
55+
56+
for cluster_str in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
5557

5658
# Get host values
5759
eval $cluster_str
@@ -61,31 +63,17 @@ for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
6163
TYPE='api'
6264
fi
6365

66+
# Check recipient dns user
67+
if [ -z "$DNS_USER" ]; then
68+
DNS_USER='dns-cluster'
69+
fi
70+
6471
# Switch on connection type
6572
case $TYPE in
6673
ssh) send_cmd="send_ssh_cmd" ;;
6774
*) send_cmd="send_api_cmd" ;;
6875
esac
6976

70-
# Check host connection
71-
$send_cmd v-list-sys-config
72-
if [ $? -ne 0 ]; then
73-
echo "Error: $TYPE connection to $HOST failed"
74-
log_event "$E_CONNECT $EVENT"
75-
exit $E_CONNECT
76-
fi
77-
78-
# Check recipient dns user
79-
if [ -z "$DNS_USER" ]; then
80-
DNS_USER='dns-cluster'
81-
fi
82-
$send_cmd v-list-user $DNS_USER
83-
if [ $? -ne 0 ]; then
84-
echo "Error: dns user $DNS_USER doesn't exist"
85-
log_event "$E_NOTEXIST $EVENT"
86-
exit $E_NOTEXIST
87-
fi
88-
8977
# Check dns exceptions
9078
if [ -z "$DNS_CLUSTER_IGNORE" ]; then
9179
DNS_CLUSTER_IGNORE='dns-cluster'
@@ -111,14 +99,15 @@ for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
11199
# Rebuild dns zone
112100
$send_cmd v-rebuild-dns-domain $DNS_USER $domain 'scheduled'
113101
if [ $? -ne 0 ]; then
114-
echo "Error: $TYPE connection to $HOST failed (rebuild)"
102+
echo "Error: $TYPE connection to $HOST failed"
115103
log_event "$E_CONNECT $EVENT"
116104
exit $E_CONNECT
117105
fi
118106

119107
done
120108

121109
# Update pipe
110+
rm -f $tmpfile
122111
pipe="$VESTA/data/queue/dns-cluster.pipe"
123112
str=$(grep -n "$SCRIPT $1 $2$" $pipe | cut -f1 -d: | head -n1)
124113
if [ ! -z "$str" ]; then

bin/v-add-remote-dns-record

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ fi
5252
old_ifs="$IFS"
5353
IFS=$'\n'
5454

55-
# Starting cluster loop
56-
for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
55+
# Check remote dns nodes
56+
remote_dns_health_check
5757

58+
for cluster_str in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
5859
# Get host values
5960
eval $cluster_str
6061

@@ -69,24 +70,10 @@ for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
6970
*) send_cmd="send_api_cmd" ;;
7071
esac
7172

72-
# Check host connection
73-
$send_cmd v-list-sys-config
74-
if [ $? -ne 0 ]; then
75-
echo "Error: $TYPE connection to $HOST failed"
76-
log_event "$E_CONNECT $EVENT"
77-
exit $E_CONNECT
78-
fi
79-
8073
# Check recipient dns user
8174
if [ -z "$DNS_USER" ]; then
8275
DNS_USER='dns-cluster'
8376
fi
84-
$send_cmd v-list-user $DNS_USER
85-
if [ $? -ne 0 ]; then
86-
echo "Error: dns user $DNS_USER doesn't exist"
87-
log_event "$E_NOTEXIST $EVENT"
88-
exit $E_NOTEXIST
89-
fi
9077

9178
# Check dns exceptions
9279
if [ -z "$DNS_CLUSTER_IGNORE" ]; then

bin/v-change-remote-dns-domain-exp

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ fi
5050
old_ifs="$IFS"
5151
IFS=$'\n'
5252

53-
# Starting cluster loop
54-
for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
53+
# Check remote dns nodes
54+
remote_dns_health_check
55+
56+
for cluster_str in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
5557

5658
# Get host values
5759
eval $cluster_str
@@ -67,24 +69,10 @@ for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
6769
*) send_cmd="send_api_cmd" ;;
6870
esac
6971

70-
# Check host connection
71-
$send_cmd v-list-sys-config
72-
if [ $? -ne 0 ]; then
73-
echo "Error: $TYPE connection to $HOST failed"
74-
log_event "$E_CONNECT $EVENT"
75-
exit $E_CONNECT
76-
fi
77-
7872
# Check recipient dns user
7973
if [ -z "$DNS_USER" ]; then
8074
DNS_USER='dns-cluster'
8175
fi
82-
$send_cmd v-list-user $DNS_USER
83-
if [ $? -ne 0 ]; then
84-
echo "Error: dns user $DNS_USER doesn't exist"
85-
log_event "$E_NOTEXIST $EVENT"
86-
exit $E_NOTEXIST
87-
fi
8876

8977
# Check dns exceptions
9078
if [ -z "$DNS_CLUSTER_IGNORE" ]; then
@@ -95,6 +83,11 @@ for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
9583
str=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf)
9684
eval $str
9785
$send_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME 'scheduled'
86+
if [ $? -ne 0 ]; then
87+
echo "Error: $TYPE connection to $HOST failed"
88+
log_event "$E_CONNECT $EVENT"
89+
exit $E_CONNECT
90+
fi
9891

9992
done
10093

bin/v-change-remote-dns-domain-soa

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ fi
5050
old_ifs="$IFS"
5151
IFS=$'\n'
5252

53-
# Starting cluster loop
54-
for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
53+
# Check remote dns nodes
54+
remote_dns_health_check
55+
56+
for cluster_str in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
5557

5658
# Get host values
5759
eval $cluster_str
@@ -67,24 +69,10 @@ for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
6769
*) send_cmd="send_api_cmd" ;;
6870
esac
6971

70-
# Check host connection
71-
$send_cmd v-list-sys-config
72-
if [ $? -ne 0 ]; then
73-
echo "Error: $TYPE connection to $HOST failed"
74-
log_event "$E_CONNECT $EVENT"
75-
exit $E_CONNECT
76-
fi
77-
7872
# Check recipient dns user
7973
if [ -z "$DNS_USER" ]; then
8074
DNS_USER='dns-cluster'
8175
fi
82-
$send_cmd v-list-user $DNS_USER
83-
if [ $? -ne 0 ]; then
84-
echo "Error: dns user $DNS_USER doesn't exist"
85-
log_event "$E_NOTEXIST $EVENT"
86-
exit $E_NOTEXIST
87-
fi
8876

8977
# Check dns exceptions
9078
if [ -z "$DNS_CLUSTER_IGNORE" ]; then

bin/v-change-remote-dns-domain-ttl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,11 @@ fi
5050
old_ifs="$IFS"
5151
IFS=$'\n'
5252

53+
# Check remote dns nodes
54+
remote_dns_health_check
55+
5356
# Starting cluster loop
54-
for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
57+
for cluster_str in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
5558

5659
# Get host values
5760
eval $cluster_str
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ if [ ! -e "$conf" ]; then
3232
fi
3333

3434
# Defining fileds to select
35-
fields='$HOST $USER $DNS_USER $TYPE $TIME $DATE'
35+
fields='$HOST $USER $DNS_USER $SUSPENDED $TIME $DATE'
3636

3737
case $format in
3838
json) json_list ;;

bin/v-restart-dns

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ if [ ! -z "$DNS_SYSTEM" ]; then
3434
if [ $? -ne 0 ]; then
3535
/etc/init.d/$DNS_SYSTEM restart >/dev/null 2>&1
3636
if [ $? -ne 0 ]; then
37-
send_mail="$VESTA/web/inc/mail-wrapper.php"
37+
if [ -e "$VESTA/web/inc/mail-wrapper.php" ]; then
38+
send_mail="$VESTA/web/inc/mail-wrapper.php"
39+
else
40+
send_mail=$(which mail)
41+
fi
3842
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
3943
email=$(echo "$email" | cut -f 2 -d "'")
4044
tmpfile=$(mktemp)

bin/v-sync-dns-cluster

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ old_ifs="$IFS"
4646
IFS=$'\n'
4747

4848
if [ -z $host ]; then
49-
hosts=$(cat $VESTA/conf/dns-cluster.conf)
49+
hosts=$(cat $VESTA/conf/dns-cluster.conf | grep "SUSPENDED=='no'")
5050
rm -f $VESTA/data/queue/dns-cluster.pipe
5151
touch $VESTA/data/queue/dns-cluster.pipe
5252
chmod 660 $VESTA/data/queue/dns-cluster.pipe

func/remote.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,50 @@ is_dnshost_alive() {
107107
exit $E_NOTEXIST
108108
fi
109109
}
110+
111+
remote_dns_health_check() {
112+
# Define tmp mail vars
113+
subj="DNS sync failed"
114+
email=$(grep CONTACT $VESTA/data/users/admin/user.conf | cut -f 2 -d \')
115+
send_mail="$VESTA/web/inc/mail-wrapper.php"
116+
tmpfile=$(mktemp)
117+
118+
# Starting health-check
119+
for str in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
120+
121+
# Get host values
122+
eval $str
123+
124+
# Check connection type
125+
if [ -z "TYPE" ]; then
126+
TYPE='api'
127+
fi
128+
129+
# Switch on connection type
130+
case $TYPE in
131+
ssh) send_cmd="send_ssh_cmd" ;;
132+
*) send_cmd="send_api_cmd" ;;
133+
esac
134+
135+
# Check host connection
136+
$send_cmd v-list-sys-config
137+
if [ $? -ne 0 ]; then
138+
echo "$(basename $0) $*" > $tmpfile
139+
echo -e "Error: $TYPE connection to $HOST failed.\n" >> $tmpfile
140+
echo -n "Remote dns host has been suspended." >> $tmpfile
141+
echo -n "After resolving issue run " >> $tmpfile
142+
echo -e "following commands:\n" >> $tmpfile
143+
echo "v-unsuspend-remote-dns-host $HOST" >> $tmpfile
144+
echo "v-sync-dns-clustert $HOST" >> $tmpfile
145+
echo -e "\n\n--\nVesta Control Panel\n$(hostname)" >> $tmpfile
146+
cat $tmpfile | $send_mail -s "$subj" $email
147+
148+
log_event "$E_CONNECT $EVENT"
149+
dconf="../../../conf/dns-cluster"
150+
update_object_value "$dconf" 'HOST' "$HOST" '$SUSPENDED' 'yes'
151+
fi
152+
153+
# Remove tmp file
154+
rm -f $tmpfile
155+
done
156+
}

0 commit comments

Comments
 (0)