forked from robynhub/kit-censura
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload-bind-config
executable file
·84 lines (64 loc) · 1.98 KB
/
upload-bind-config
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
source config.sh
# override the list of target servers
if [ "$1" ]; then
SERVERS="$1"
fi
##############################################################################
copy_config() {
local file="$1"
local server rc
rc=0
for server in $SERVERS; do
dprintf "Copying to $server..."
for zone in $LISTS; do
if [ -e db.$zone ] ; then
if rsync $RSYNC_OPTIONS db.$zone $server:$CONFDIR; then
dprintf "The zone db.$zone has been correctly copied to $CONFDIR on $server" >&2
else
dprintf "ERROR: the zone db.$zone has not been correctly copied to $server!" >&2
fi
fi
done
if rsync $RSYNC_OPTIONS $file $server:$CONFFILE; then
dprintf "Succesfully copied $file to $CONFFILE on $server."
if ssh $server "named-checkconf $CONFFILE && rndc reconfig"; then
dprintf "Configuration successfully reloaded on $server."
else
dprintf "ERROR: the configuration has not been correctly reloaded on $server!" >&2
rc=1
fi
else
dprintf "ERROR: the configuration has not been correctly copied to $server!" >&2
rc=1
fi
done
return $rc
}
#if [ -t 0 ]; then VERBOSE=1; fi
dprintf() {
# [ "$VERBOSE" ] || return 0
printf "$* \n"
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - $*" >> $LOGFILE
}
##############################################################################
# debugging
if [ "$PWD" = "/home/md/projects/kit-censura" ]; then
rsync() { echo "DEBUG: rsync $*"; }
ssh() { echo "DEBUG: ssh $*"; }
fi
##############################################################################
if cmp -s $CONF $CONF.new; then
# the new config file is unchanged, we are done
dprintf "$CONF is unchanged, exiting."
exit 0
fi
dprintf "$CONF has changed."
# copy named.conf to the servers
# rename the file only if everything was successful
if copy_config $CONF.new; then
cp -a $CONF.new $CONF
else
rm -f $CONF.new
fi
exit 0