3
# Master side of master/slave replication
5
ROOTARGS="-uroot -p`cat /var/lib/ensemble/mysql.passwd`"
8
apt-get -y install apache2
9
# disable wide-open access (restrict to each db IP)
10
allowline=`augtool get /files/etc/apache2/sites-available/default/VirtualHost/Directory[2]/directive[4]/arg[2]`
11
if [ "$allowline" = "/files/etc/apache2/sites-available/default/VirtualHost/Directory[2]/directive[4]/arg[2] = all" ] ; then
12
# disable allow from all
14
defvar webroot /files/etc/apache2/sites-available/default/VirtualHost/Directory[2]
15
rm \$webroot/directive[4]
18
service apache2 reload
20
# TODO: settings.. make mmin tunable as it is highly subjective
21
recent_backup=`find $snapdir -name 'replication_seed.*.sql.gz' -mmin -60|head -1`
22
if [ -z "$recent_backup" ] ; then
23
recent_backup=replication_seed.`date +%Y%m%d%H%M%S`.sql.gz
24
echo `date`: Creating snapshot $recent_backup
25
mysqldump $ROOTARGS --all-databases --single-transaction --master-data |gzip>$snapdir/$recent_backup
28
case $ENSEMBLE_CHANGE in
32
remote_ip=`relation-get ip`
33
local_ip=`ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'|head -n 1`
35
defvar webroot /files/etc/apache2/sites-available/default/VirtualHost/Directory[2]
36
set \$webroot/directive[last()+1] allow
37
set \$webroot/directive[last()]/arg from
38
set \$webroot/directive[last()]/arg $remote_ip/32
41
service apache2 reload
42
mysql $ROOTARGS -e "GRANT REPLICATION_CLIENT ON *.* TO \`$ENSEMBLE_REMOTE_UNIT\`@\`$remote_ip\` IDENTIFIED BY '$pass'"
43
relation-set dumpurl=/snaps/$name \
44
user=$ENSEMBLE_REMOTE_UNIT \
50
remote_ip=`relation-get ip`
51
mysql $ROOTARGS -e "REVOKE PRIVILEGES ON *.* FROM `$ENSEMBLE_REMOTE_UNIT`@`$remote_ip`"
53
for aline in `augtool ls /files/etc/apache2/sites-available/default/VirtualHost/Directory[2]|grep " = allow"|cut -d' ' -f1` ; do
54
ip=`augtool get /files/etc/apache2/sites-available/default/VirtualHost/Directory[2]/$aline/arg[2]`
55
if [ "$ip" = "$remote_ip/32" ] ; then
56
echo -e "rm /files/etc/apache2/sites-available/default/VirtualHost/Directory[2]/$aline\nsave" | augtool -b
57
echo removed $aline from /files/etc/apache2/sites-available/default/VirtualHost/Directory[2]
58
service apache2 reload