Skip to content

Commit bab2489

Browse files
committed
remote dns host management
1 parent 370569a commit bab2489

File tree

6 files changed

+299
-2
lines changed

6 files changed

+299
-2
lines changed

bin/v-add-remote-dns-host

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
# info: add new remote dns host
3+
# options: HOST PORT USER PASSWORD [TYPE] [DNS_USER]
4+
#
5+
# The function adds remote dns server to the dns cluster.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
host=$1
14+
port=$2
15+
user=$3
16+
password=$4
17+
type=${5-api}
18+
dns_user=${6-dns-cluster}
19+
20+
# Includes
21+
source $VESTA/conf/vesta.conf
22+
source $VESTA/func/main.sh
23+
source $VESTA/func/remote.sh
24+
25+
# Hiding passwords
26+
A4='******'
27+
28+
29+
#----------------------------------------------------------#
30+
# Verifications #
31+
#----------------------------------------------------------#
32+
33+
args_usage='HOST PORT USER PASSWORD [TYPE] [DNS_USER]'
34+
check_args '4' "$#" "$args_usage"
35+
validate_format 'host' 'port' 'user' 'password' 'type' 'dns_user'
36+
is_system_enabled "$DNS_SYSTEM"
37+
is_dnshost_new
38+
is_dnshost_alive
39+
40+
41+
#----------------------------------------------------------#
42+
# Action #
43+
#----------------------------------------------------------#
44+
45+
# Concatentating db host string
46+
str="HOST='$host' USER='$user' PASSWORD='$password' DNS_USER='$dns_user'"
47+
str="$str TYPE='$type' SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
48+
49+
# Adding host to dns-cluster.conf
50+
echo "$str" >> $VESTA/conf/dns-cluster.conf
51+
chmod 660 $VESTA/conf/dns-cluster.conf
52+
53+
# Enabling DNS_CLUSTER
54+
if [ -z "$(grep DNS_CLUSTER $VESTA/conf/vesta.conf)" ]; then
55+
sed -i "s/^STATS_/DNS_CLUSTER='yes'\nSTATS_/g" $VESTA/conf/vesta.conf
56+
else
57+
sed -i "s/DNS_CLUSTER=.*/DNS_CLUSTER='yes'/g" $VESTA/conf/vesta.conf
58+
fi
59+
60+
# Sync current zones
61+
$BIN/v-sync-dns-cluster
62+
return_code=$?
63+
if [ "$return_code" -ne 0 ]; then
64+
exit $return_code
65+
fi
66+
67+
#----------------------------------------------------------#
68+
# Vesta #
69+
#----------------------------------------------------------#
70+
71+
# Logging
72+
log_event "$OK" "$EVENT"
73+
74+
exit

bin/v-delete-remote-dns-domains

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/bin/bash
2+
# info: delete remote dns domains
3+
# options: [HOST]
4+
# The function deletes remote dns domains.
5+
6+
7+
#----------------------------------------------------------#
8+
# Variable&Function #
9+
#----------------------------------------------------------#
10+
11+
# Argument defenition
12+
host=$1
13+
14+
# Includes
15+
source $VESTA/conf/vesta.conf
16+
source $VESTA/func/main.sh
17+
source $VESTA/func/remote.sh
18+
19+
20+
#----------------------------------------------------------#
21+
# Verifications #
22+
#----------------------------------------------------------#
23+
24+
is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER'
25+
26+
if [ ! -e "$VESTA/conf/dns-cluster.conf" ]; then
27+
echo "Error: dns-cluster.conf doesn't exist"
28+
log_event "$E_NOTEXIST $EVENT"
29+
exit $E_NOTEXIST
30+
fi
31+
32+
number_of_proc=$(ps auxf | grep -v grep | grep $VESTA/bin/$SCRIPT | wc -l)
33+
if [ "$number_of_proc" -gt 2 ]; then
34+
echo "Error: another sync process already exists"
35+
log_event "$E_EXISTS $EVENT"
36+
exit $E_EXISTS
37+
fi
38+
39+
40+
#----------------------------------------------------------#
41+
# Action #
42+
#----------------------------------------------------------#
43+
44+
old_ifs="$IFS"
45+
IFS=$'\n'
46+
47+
if [ -z $host ]; then
48+
hosts=$(cat $VESTA/conf/dns-cluster.conf)
49+
else
50+
hosts=$(grep "HOST='$host'" $VESTA/conf/dns-cluster.conf)
51+
fi
52+
53+
# Starting cluster loop
54+
for cluster_str in $hosts; do
55+
56+
# Get host values
57+
eval $cluster_str
58+
59+
# Check connection type
60+
if [ -z "TYPE" ]; then
61+
TYPE='api'
62+
fi
63+
64+
# Print hostname
65+
if [ ! -z "$verbose" ]; then
66+
echo "HOSTNAME: $HOSTNAME"
67+
echo "TYPE: $TYPE"
68+
fi
69+
70+
# Switch on connection type
71+
case $TYPE in
72+
ssh) send_cmd="send_ssh_cmd" ;;
73+
*) send_cmd="send_api_cmd" ;;
74+
esac
75+
76+
# Check host connection
77+
$send_cmd v-list-sys-config
78+
if [ $? -ne 0 ]; then
79+
echo "Error: $TYPE connection to $HOST failed"
80+
log_event "$E_CONNECT $EVENT"
81+
exit $E_CONNECT
82+
fi
83+
84+
# Check recipient dns user
85+
if [ -z "$DNS_USER" ]; then
86+
DNS_USER='dns-cluster'
87+
fi
88+
if [ ! -z "$verbose" ]; then
89+
echo "DNS_USER: $DNS_USER"
90+
fi
91+
$send_cmd v-list-user $DNS_USER
92+
if [ $? -ne 0 ]; then
93+
echo "Error: dns user $DNS_USER doesn't exist"
94+
log_event "$E_NOTEXIST $EVENT"
95+
exit $E_NOTEXIST
96+
fi
97+
98+
# Clean source records
99+
$send_cmd v-delete-dns-domains-src $DNS_USER $HOSTNAME no
100+
if [ $? -ne 0 ]; then
101+
echo "Error: $TYPE connection to $HOST failed (cleanup)"
102+
log_event "$E_CONNECT $EVENT"
103+
exit $E_CONNECT
104+
fi
105+
106+
# Rebuild dns zones
107+
$send_cmd v-rebuild-dns-domains $DNS_USER
108+
if [ $? -ne 0 ]; then
109+
echo "Error: $TYPE connection to $HOST failed (rebuild)"
110+
log_event "$E_CONNECT $EVENT"
111+
exit $E_CONNECT
112+
fi
113+
114+
done
115+
116+
117+
#----------------------------------------------------------#
118+
# Vesta #
119+
#----------------------------------------------------------#
120+
121+
exit

bin/v-delete-remote-dns-host

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
# info: delete remote dns host
3+
# options: HOST
4+
#
5+
# The function for deleting the remote dns host from vesta configuration.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
host=$1
14+
15+
# Includes
16+
source $VESTA/conf/vesta.conf
17+
source $VESTA/func/main.sh
18+
19+
20+
#----------------------------------------------------------#
21+
# Verifications #
22+
#----------------------------------------------------------#
23+
24+
check_args '1' "$#" 'HOST'
25+
validate_format 'host'
26+
is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER'
27+
is_object_valid "../../conf/dns-cluster" 'HOST' "$host"
28+
29+
30+
#----------------------------------------------------------#
31+
# Action #
32+
#----------------------------------------------------------#
33+
34+
# Deleting domains
35+
$BIN/v-delete-remote-dns-domains $host >>/dev/null 2>&1
36+
37+
# Deleting server
38+
sed -i "/HOST='$host' /d" $VESTA/conf/dns-cluster.conf
39+
40+
# Disabling DNS_CLUSTER
41+
check_cluster=$(grep HOST $VESTA/conf/dns-cluster.conf |wc -l)
42+
if [ "$check_cluster" -eq '0' ]; then
43+
rm -f $VESTA/conf/dns-cluster.conf
44+
sed -i "/DNS_CLUSTER=/d" $VESTA/conf/vesta.conf
45+
fi
46+
47+
48+
#----------------------------------------------------------#
49+
# Vesta #
50+
#----------------------------------------------------------#
51+
52+
# Logging
53+
log_history "deleted $type database server $host" '' 'admin'
54+
log_event "$OK" "$EVENT"
55+
56+
exit

bin/v-sync-dns-cluster

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ source $VESTA/func/remote.sh
2121
# Verifications #
2222
#----------------------------------------------------------#
2323

24-
is_system_enabled "$DNS_CLUSTER"
24+
is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER'
2525

2626
if [ ! -e "$VESTA/conf/dns-cluster.conf" ]; then
2727
echo "Error: dns-cluster.conf doesn't exist"

func/main.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ check_args() {
8787
# Subsystem checker
8888
is_system_enabled() {
8989
if [ -z "$1" ] || [ "$1" = no ]; then
90-
echo "Error: subsystem disabled"
90+
echo "Error: $2 is disabled in the vesta.conf"
9191
log_event "$E_DISABLED" "$EVENT"
9292
exit $E_DISABLED
9393
fi

func/remote.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,49 @@ scp_cmd() {
6161
return 0
6262
fi
6363
}
64+
65+
is_dnshost_new() {
66+
if [ -e "$VESTA/conf/dns-cluster.conf" ]; then
67+
check_host=$(grep "HOST='$host'" $VESTA/conf/dns-cluster.conf)
68+
if [ ! -z "$check_host" ]; then
69+
echo "Error: dns host $host exists"
70+
log_event "$E_EXISTS" "$EVENT"
71+
exit $E_EXISTS
72+
fi
73+
fi
74+
}
75+
76+
is_dnshost_alive() {
77+
HOST=$host
78+
PORT=$port
79+
USER=$user
80+
PASSWORD=$password
81+
82+
# Switch on connection type
83+
case $type in
84+
ssh) send_cmd="send_ssh_cmd" ;;
85+
*) send_cmd="send_api_cmd" ;;
86+
esac
87+
88+
# Check host connection
89+
$send_cmd v-list-sys-config
90+
if [ $? -ne 0 ]; then
91+
echo "Error: $type connection to $HOST failed"
92+
log_event "$E_CONNECT $EVENT"
93+
exit $E_CONNECT
94+
fi
95+
96+
# Check recipient dns user
97+
if [ -z "$DNS_USER" ]; then
98+
DNS_USER='dns-cluster'
99+
fi
100+
if [ ! -z "$verbose" ]; then
101+
echo "DNS_USER: $DNS_USER"
102+
fi
103+
$send_cmd v-list-user $DNS_USER
104+
if [ $? -ne 0 ]; then
105+
echo "Error: dns user $DNS_USER doesn't exist"
106+
log_event "$E_NOTEXIST $EVENT"
107+
exit $E_NOTEXIST
108+
fi
109+
}

0 commit comments

Comments
 (0)