Set mysql server_id based on instance-id
Do nothing if we are booted on a server which has no instance-id set, such as a non-cloud VM or server. Change-Id: I6df81edbea1b2b4e4f1ef11a9f2ddaf100d98eda
This commit is contained in:
parent
72534d6eba
commit
6bf07b12d3
@ -6,5 +6,6 @@ set -e
|
|||||||
set -o xtrace
|
set -o xtrace
|
||||||
|
|
||||||
install -D -m 0644 -o root -g root $(dirname $0)/my.cnf /etc/mysql/my.cnf
|
install -D -m 0644 -o root -g root $(dirname $0)/my.cnf /etc/mysql/my.cnf
|
||||||
|
install $(dirname $0)/mysql-set-server-id.upstart /etc/init/mysql-set-server-id.conf
|
||||||
|
|
||||||
install-packages sysstat mytop percona-toolkit mysql-server-5.5 mysql-client-5.5
|
install-packages sysstat mytop percona-toolkit mysql-server-5.5 mysql-client-5.5
|
||||||
|
27
elements/mysql/install.d/mysql-set-server-id.upstart
Normal file
27
elements/mysql/install.d/mysql-set-server-id.upstart
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# vim: syntax=upstart
|
||||||
|
description "Set mysql server_id based on instance-id"
|
||||||
|
|
||||||
|
start on starting mysql
|
||||||
|
task
|
||||||
|
|
||||||
|
env INSTANCE_ID="/var/lib/cloud/data/instance-id"
|
||||||
|
env CONF_TARGET="/etc/mysql/conf.d/server_id.cnf"
|
||||||
|
|
||||||
|
pre-start script
|
||||||
|
if ! [ -e $INSTANCE_ID ] ; then
|
||||||
|
stop
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
end script
|
||||||
|
|
||||||
|
script
|
||||||
|
instance=$(cat $INSTANCE_ID)
|
||||||
|
server_id=$(python -c "print 0x${instance##i-}")
|
||||||
|
cat > $CONF_TARGET.new <<EOF
|
||||||
|
# Generated by mysql-set-server-id upstart job $(date)
|
||||||
|
# From $INSTANCE_ID ${instance}
|
||||||
|
[mysqld]
|
||||||
|
server_id = $server_id
|
||||||
|
EOF
|
||||||
|
mv -f $CONF_TARGET.new $CONF_TARGET
|
||||||
|
end script
|
Loading…
Reference in New Issue
Block a user