mirror of
https://github.com/myvesta/vesta
synced 2025-08-19 21:04:07 -07:00
suspend remote dns if connection failed
This commit is contained in:
parent
bbc652c331
commit
f70ba768a3
9 changed files with 85 additions and 74 deletions
|
@ -50,8 +50,10 @@ fi
|
||||||
old_ifs="$IFS"
|
old_ifs="$IFS"
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
|
|
||||||
# Starting cluster loop
|
# Check remote dns nodes
|
||||||
for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
|
remote_dns_health_check
|
||||||
|
|
||||||
|
for cluster_str in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
|
||||||
|
|
||||||
# Get host values
|
# Get host values
|
||||||
eval $cluster_str
|
eval $cluster_str
|
||||||
|
@ -61,31 +63,17 @@ for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
|
||||||
TYPE='api'
|
TYPE='api'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Check recipient dns user
|
||||||
|
if [ -z "$DNS_USER" ]; then
|
||||||
|
DNS_USER='dns-cluster'
|
||||||
|
fi
|
||||||
|
|
||||||
# Switch on connection type
|
# Switch on connection type
|
||||||
case $TYPE in
|
case $TYPE in
|
||||||
ssh) send_cmd="send_ssh_cmd" ;;
|
ssh) send_cmd="send_ssh_cmd" ;;
|
||||||
*) send_cmd="send_api_cmd" ;;
|
*) send_cmd="send_api_cmd" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Check host connection
|
|
||||||
$send_cmd v-list-sys-config
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "Error: $TYPE connection to $HOST failed"
|
|
||||||
log_event "$E_CONNECT $EVENT"
|
|
||||||
exit $E_CONNECT
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check recipient dns user
|
|
||||||
if [ -z "$DNS_USER" ]; then
|
|
||||||
DNS_USER='dns-cluster'
|
|
||||||
fi
|
|
||||||
$send_cmd v-list-user $DNS_USER
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "Error: dns user $DNS_USER doesn't exist"
|
|
||||||
log_event "$E_NOTEXIST $EVENT"
|
|
||||||
exit $E_NOTEXIST
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check dns exceptions
|
# Check dns exceptions
|
||||||
if [ -z "$DNS_CLUSTER_IGNORE" ]; then
|
if [ -z "$DNS_CLUSTER_IGNORE" ]; then
|
||||||
DNS_CLUSTER_IGNORE='dns-cluster'
|
DNS_CLUSTER_IGNORE='dns-cluster'
|
||||||
|
@ -111,7 +99,7 @@ for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
|
||||||
# Rebuild dns zone
|
# Rebuild dns zone
|
||||||
$send_cmd v-rebuild-dns-domain $DNS_USER $domain 'scheduled'
|
$send_cmd v-rebuild-dns-domain $DNS_USER $domain 'scheduled'
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Error: $TYPE connection to $HOST failed (rebuild)"
|
echo "Error: $TYPE connection to $HOST failed"
|
||||||
log_event "$E_CONNECT $EVENT"
|
log_event "$E_CONNECT $EVENT"
|
||||||
exit $E_CONNECT
|
exit $E_CONNECT
|
||||||
fi
|
fi
|
||||||
|
@ -119,6 +107,7 @@ for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
|
||||||
done
|
done
|
||||||
|
|
||||||
# Update pipe
|
# Update pipe
|
||||||
|
rm -f $tmpfile
|
||||||
pipe="$VESTA/data/queue/dns-cluster.pipe"
|
pipe="$VESTA/data/queue/dns-cluster.pipe"
|
||||||
str=$(grep -n "$SCRIPT $1 $2$" $pipe | cut -f1 -d: | head -n1)
|
str=$(grep -n "$SCRIPT $1 $2$" $pipe | cut -f1 -d: | head -n1)
|
||||||
if [ ! -z "$str" ]; then
|
if [ ! -z "$str" ]; then
|
||||||
|
|
|
@ -52,9 +52,10 @@ fi
|
||||||
old_ifs="$IFS"
|
old_ifs="$IFS"
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
|
|
||||||
# Starting cluster loop
|
# Check remote dns nodes
|
||||||
for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
|
remote_dns_health_check
|
||||||
|
|
||||||
|
for cluster_str in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
|
||||||
# Get host values
|
# Get host values
|
||||||
eval $cluster_str
|
eval $cluster_str
|
||||||
|
|
||||||
|
@ -69,24 +70,10 @@ for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
|
||||||
*) send_cmd="send_api_cmd" ;;
|
*) send_cmd="send_api_cmd" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Check host connection
|
|
||||||
$send_cmd v-list-sys-config
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "Error: $TYPE connection to $HOST failed"
|
|
||||||
log_event "$E_CONNECT $EVENT"
|
|
||||||
exit $E_CONNECT
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check recipient dns user
|
# Check recipient dns user
|
||||||
if [ -z "$DNS_USER" ]; then
|
if [ -z "$DNS_USER" ]; then
|
||||||
DNS_USER='dns-cluster'
|
DNS_USER='dns-cluster'
|
||||||
fi
|
fi
|
||||||
$send_cmd v-list-user $DNS_USER
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "Error: dns user $DNS_USER doesn't exist"
|
|
||||||
log_event "$E_NOTEXIST $EVENT"
|
|
||||||
exit $E_NOTEXIST
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check dns exceptions
|
# Check dns exceptions
|
||||||
if [ -z "$DNS_CLUSTER_IGNORE" ]; then
|
if [ -z "$DNS_CLUSTER_IGNORE" ]; then
|
||||||
|
|
|
@ -50,8 +50,10 @@ fi
|
||||||
old_ifs="$IFS"
|
old_ifs="$IFS"
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
|
|
||||||
# Starting cluster loop
|
# Check remote dns nodes
|
||||||
for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
|
remote_dns_health_check
|
||||||
|
|
||||||
|
for cluster_str in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
|
||||||
|
|
||||||
# Get host values
|
# Get host values
|
||||||
eval $cluster_str
|
eval $cluster_str
|
||||||
|
@ -67,24 +69,10 @@ for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
|
||||||
*) send_cmd="send_api_cmd" ;;
|
*) send_cmd="send_api_cmd" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Check host connection
|
|
||||||
$send_cmd v-list-sys-config
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "Error: $TYPE connection to $HOST failed"
|
|
||||||
log_event "$E_CONNECT $EVENT"
|
|
||||||
exit $E_CONNECT
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check recipient dns user
|
# Check recipient dns user
|
||||||
if [ -z "$DNS_USER" ]; then
|
if [ -z "$DNS_USER" ]; then
|
||||||
DNS_USER='dns-cluster'
|
DNS_USER='dns-cluster'
|
||||||
fi
|
fi
|
||||||
$send_cmd v-list-user $DNS_USER
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "Error: dns user $DNS_USER doesn't exist"
|
|
||||||
log_event "$E_NOTEXIST $EVENT"
|
|
||||||
exit $E_NOTEXIST
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check dns exceptions
|
# Check dns exceptions
|
||||||
if [ -z "$DNS_CLUSTER_IGNORE" ]; then
|
if [ -z "$DNS_CLUSTER_IGNORE" ]; then
|
||||||
|
@ -95,6 +83,11 @@ for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
|
||||||
str=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf)
|
str=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf)
|
||||||
eval $str
|
eval $str
|
||||||
$send_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME 'scheduled'
|
$send_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME 'scheduled'
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Error: $TYPE connection to $HOST failed"
|
||||||
|
log_event "$E_CONNECT $EVENT"
|
||||||
|
exit $E_CONNECT
|
||||||
|
fi
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
|
@ -50,8 +50,10 @@ fi
|
||||||
old_ifs="$IFS"
|
old_ifs="$IFS"
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
|
|
||||||
# Starting cluster loop
|
# Check remote dns nodes
|
||||||
for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
|
remote_dns_health_check
|
||||||
|
|
||||||
|
for cluster_str in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
|
||||||
|
|
||||||
# Get host values
|
# Get host values
|
||||||
eval $cluster_str
|
eval $cluster_str
|
||||||
|
@ -67,24 +69,10 @@ for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
|
||||||
*) send_cmd="send_api_cmd" ;;
|
*) send_cmd="send_api_cmd" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Check host connection
|
|
||||||
$send_cmd v-list-sys-config
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "Error: $TYPE connection to $HOST failed"
|
|
||||||
log_event "$E_CONNECT $EVENT"
|
|
||||||
exit $E_CONNECT
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check recipient dns user
|
# Check recipient dns user
|
||||||
if [ -z "$DNS_USER" ]; then
|
if [ -z "$DNS_USER" ]; then
|
||||||
DNS_USER='dns-cluster'
|
DNS_USER='dns-cluster'
|
||||||
fi
|
fi
|
||||||
$send_cmd v-list-user $DNS_USER
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "Error: dns user $DNS_USER doesn't exist"
|
|
||||||
log_event "$E_NOTEXIST $EVENT"
|
|
||||||
exit $E_NOTEXIST
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check dns exceptions
|
# Check dns exceptions
|
||||||
if [ -z "$DNS_CLUSTER_IGNORE" ]; then
|
if [ -z "$DNS_CLUSTER_IGNORE" ]; then
|
||||||
|
|
|
@ -50,8 +50,11 @@ fi
|
||||||
old_ifs="$IFS"
|
old_ifs="$IFS"
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
|
|
||||||
|
# Check remote dns nodes
|
||||||
|
remote_dns_health_check
|
||||||
|
|
||||||
# Starting cluster loop
|
# Starting cluster loop
|
||||||
for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
|
for cluster_str in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
|
||||||
|
|
||||||
# Get host values
|
# Get host values
|
||||||
eval $cluster_str
|
eval $cluster_str
|
||||||
|
|
|
@ -32,7 +32,7 @@ if [ ! -e "$conf" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Defining fileds to select
|
# Defining fileds to select
|
||||||
fields='$HOST $USER $DNS_USER $TYPE $TIME $DATE'
|
fields='$HOST $USER $DNS_USER $SUSPENDED $TIME $DATE'
|
||||||
|
|
||||||
case $format in
|
case $format in
|
||||||
json) json_list ;;
|
json) json_list ;;
|
|
@ -34,7 +34,11 @@ if [ ! -z "$DNS_SYSTEM" ]; then
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
/etc/init.d/$DNS_SYSTEM restart >/dev/null 2>&1
|
/etc/init.d/$DNS_SYSTEM restart >/dev/null 2>&1
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
|
if [ -e "$VESTA/web/inc/mail-wrapper.php" ]; then
|
||||||
send_mail="$VESTA/web/inc/mail-wrapper.php"
|
send_mail="$VESTA/web/inc/mail-wrapper.php"
|
||||||
|
else
|
||||||
|
send_mail=$(which mail)
|
||||||
|
fi
|
||||||
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
|
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
|
||||||
email=$(echo "$email" | cut -f 2 -d "'")
|
email=$(echo "$email" | cut -f 2 -d "'")
|
||||||
tmpfile=$(mktemp)
|
tmpfile=$(mktemp)
|
||||||
|
|
|
@ -46,7 +46,7 @@ old_ifs="$IFS"
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
|
|
||||||
if [ -z $host ]; then
|
if [ -z $host ]; then
|
||||||
hosts=$(cat $VESTA/conf/dns-cluster.conf)
|
hosts=$(cat $VESTA/conf/dns-cluster.conf | grep "SUSPENDED=='no'")
|
||||||
rm -f $VESTA/data/queue/dns-cluster.pipe
|
rm -f $VESTA/data/queue/dns-cluster.pipe
|
||||||
touch $VESTA/data/queue/dns-cluster.pipe
|
touch $VESTA/data/queue/dns-cluster.pipe
|
||||||
chmod 660 $VESTA/data/queue/dns-cluster.pipe
|
chmod 660 $VESTA/data/queue/dns-cluster.pipe
|
||||||
|
|
|
@ -107,3 +107,50 @@ is_dnshost_alive() {
|
||||||
exit $E_NOTEXIST
|
exit $E_NOTEXIST
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
remote_dns_health_check() {
|
||||||
|
# Define tmp mail vars
|
||||||
|
subj="DNS sync failed"
|
||||||
|
email=$(grep CONTACT $VESTA/data/users/admin/user.conf | cut -f 2 -d \')
|
||||||
|
send_mail="$VESTA/web/inc/mail-wrapper.php"
|
||||||
|
tmpfile=$(mktemp)
|
||||||
|
|
||||||
|
# Starting health-check
|
||||||
|
for str in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
|
||||||
|
|
||||||
|
# Get host values
|
||||||
|
eval $str
|
||||||
|
|
||||||
|
# Check connection type
|
||||||
|
if [ -z "TYPE" ]; then
|
||||||
|
TYPE='api'
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Switch on connection type
|
||||||
|
case $TYPE in
|
||||||
|
ssh) send_cmd="send_ssh_cmd" ;;
|
||||||
|
*) send_cmd="send_api_cmd" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Check host connection
|
||||||
|
$send_cmd v-list-sys-config
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "$(basename $0) $*" > $tmpfile
|
||||||
|
echo -e "Error: $TYPE connection to $HOST failed.\n" >> $tmpfile
|
||||||
|
echo -n "Remote dns host has been suspended." >> $tmpfile
|
||||||
|
echo -n "After resolving issue run " >> $tmpfile
|
||||||
|
echo -e "following commands:\n" >> $tmpfile
|
||||||
|
echo "v-unsuspend-remote-dns-host $HOST" >> $tmpfile
|
||||||
|
echo "v-sync-dns-clustert $HOST" >> $tmpfile
|
||||||
|
echo -e "\n\n--\nVesta Control Panel\n$(hostname)" >> $tmpfile
|
||||||
|
cat $tmpfile | $send_mail -s "$subj" $email
|
||||||
|
|
||||||
|
log_event "$E_CONNECT $EVENT"
|
||||||
|
dconf="../../../conf/dns-cluster"
|
||||||
|
update_object_value "$dconf" 'HOST' "$HOST" '$SUSPENDED' 'yes'
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove tmp file
|
||||||
|
rm -f $tmpfile
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue