3
# Master side of master/slave replication
7
ROOTARGS="-uroot -p`cat /var/lib/ensemble/mysql.passwd`"
10
apt-get -y install apache2
11
# disable wide-open access (restrict to each db IP)
12
allowline=`augtool get /files/etc/apache2/sites-available/default/VirtualHost/Directory[2]/directive[4]/arg[2]`
13
if [ "$allowline" = "/files/etc/apache2/sites-available/default/VirtualHost/Directory[2]/directive[4]/arg[2] = all" ] ; then
14
# disable allow from all
16
defvar webroot /files/etc/apache2/sites-available/default/VirtualHost/Directory[2]
17
rm \$webroot/directive[4]
20
service apache2 reload
23
# TODO: settings.. make mmin tunable as it is highly subjective
24
recent_backup=`find $snapdir -name 'replication_seed.*.sql.gz' -mmin -60|head -1`
25
if [ -z "$recent_backup" ] ; then
26
name=replication_seed.`date +%Y%m%d%H%M%S`.sql.gz
27
echo `date`: Creating snapshot $recent_backup
28
# Assumes transactional storage -- MyISAM please GO AWAY
29
mysqldump $ROOTARGS --all-databases --single-transaction --master-data |gzip>$snapdir/$name
30
# Make sure webserver can serve it
32
name=`basename $recent_backup`
34
chown -v -R www-data.www-data /var/www
36
remote_ip=`relation-get ip`
37
test -n "$remote_ip" || exit 1
38
local_ip=`ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'|head -n 1`
41
defvar webroot /files/etc/apache2/sites-available/default/VirtualHost/Directory[2]
42
set \$webroot/directive[last()+1] allow
43
set \$webroot/directive[last()]/arg[1] from
44
set \$webroot/directive[last()]/arg[2] $remote_ip/32
47
service apache2 reload
48
mysql $ROOTARGS -e "GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO \`$ENSEMBLE_REMOTE_UNIT\`@\`$remote_ip\` IDENTIFIED BY '$pass'"
49
relation-set dumpurl=/snaps/$name \
50
user=$ENSEMBLE_REMOTE_UNIT \