3
ROOTARGS="-uroot -p`cat /var/lib/ensemble/mysql.passwd`"
5
case "$ENSEMBLE_CHANGE" in
7
local_ip=`ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'|head -n 1`
8
relation-set ip=$local_ip
11
master=`relation-list | head -1`
12
if [ "$ENSEMBLE_REMOTE_UNIT" != "$master" ] ; then
17
dumpurl=http://`relation-get ip`/`relation-get dumpurl`
18
curl $dumpurl | mysql $ROOTARGS
19
user=`relation-get user`
20
pass=`relation-get psasword`
21
remote_ip=`relation-get ip`
22
port=`relation-get port`
23
serverid=`augtool ls /files/etc/mysql/my.cnf/target[3]/server_id`
24
if [ $serverid -lt 100000 ] ; then
25
# add 100000 to server_id to avoid conflicts w/ masters
26
let serverid=$serverid+100000
27
echo -e "set /files/etc/mysql/my.cnf/target[3]/server_id $serverid\nsave" | augtool -b
30
binlog=`augtool get /files/etc/mysql/my.cnf/target[3]/log_bin|cut -d' ' -f3`
31
backupdir=/var/backups/binlogs-`date +%Y%m%d%H%M%S`
33
mv $binlog* $backupdir
36
mysql $ROOTARGS -e "CHANGE MASTER TO MASTER_HOST=\`$remote_ip\`, MASTER_USER=\`$user\`, MASTER_PASSWORD='$pass', MASTER_PORT=$port"
37
mysql $ROOTARGS -e "START SLAVE"
38
mysql $ROOTARGS -e "SHOW SLAVE STATUS"
41
echo $ENSEMBLE_REMOTE_UNIT master departed, doing nothing.
42
# TODO re-init to another master automatically