From 6bf07b12d385560d87ce651b070284548c939f09 Mon Sep 17 00:00:00 2001 From: Clint Byrum Date: Thu, 21 Mar 2013 16:28:17 -0700 Subject: [PATCH] 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 --- elements/mysql/install.d/10-mysql | 1 + .../install.d/mysql-set-server-id.upstart | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 elements/mysql/install.d/mysql-set-server-id.upstart diff --git a/elements/mysql/install.d/10-mysql b/elements/mysql/install.d/10-mysql index 4bb3d474a..2593ff36d 100755 --- a/elements/mysql/install.d/10-mysql +++ b/elements/mysql/install.d/10-mysql @@ -6,5 +6,6 @@ set -e set -o xtrace 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 diff --git a/elements/mysql/install.d/mysql-set-server-id.upstart b/elements/mysql/install.d/mysql-set-server-id.upstart new file mode 100644 index 000000000..78454e2d5 --- /dev/null +++ b/elements/mysql/install.d/mysql-set-server-id.upstart @@ -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 <