6bf07b12d3
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
28 lines
609 B
Plaintext
28 lines
609 B
Plaintext
# 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
|