aboutsummaryrefslogtreecommitdiffstats
path: root/bin/ec2-rewrite-conf
diff options
context:
space:
mode:
authorMark Longair <mhl@pobox.com>2012-09-26 14:48:08 +0100
committerMark Longair <mhl@pobox.com>2012-09-26 14:52:50 +0100
commit312c3b14fd1683973baca6dcf6b4f95e888064ab (patch)
treeec1522139ee35e73a82a871dabb1e9551a1cdbf1 /bin/ec2-rewrite-conf
parent4a9004283ce98a7c2fea615aa5968ea7ced921d4 (diff)
Add a script to write the EC2 hostname into general.yml
This is useful when added to /etc/rc.local of our FixMyStreet AMI, so that when a new EC2 instance is brought up, the correct hostname is set in BASE_URL and EMAIL_DOMAIN.
Diffstat (limited to 'bin/ec2-rewrite-conf')
-rwxr-xr-xbin/ec2-rewrite-conf20
1 files changed, 20 insertions, 0 deletions
diff --git a/bin/ec2-rewrite-conf b/bin/ec2-rewrite-conf
new file mode 100755
index 000000000..0163ef511
--- /dev/null
+++ b/bin/ec2-rewrite-conf
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+# This is a helper script for writing the current EC2 hostname into
+# the FixMyStreet configuration file. Its intended usage is for lines
+# like these to be added to /etc/rc.local:
+#
+# su -l -c /home/fms/fixmystreet/bin/ec2-rewrite-conf fms
+# /etc/init.d/apache2 restart
+
+set -e
+
+BIN_DIR=$(dirname $(readlink -f $0))
+CONF_DIR=$BIN_DIR/../conf
+
+HOST=`curl -s http://169.254.169.254/latest/meta-data/public-hostname`
+
+sed -i -r \
+ -e "s,^( *BASE_URL:).*,\\1 'http://$HOST'," \
+ -e "s,^( *EMAIL_DOMAIN:).*,\\1 '$HOST'," \
+ $CONF_DIR/general.yml