summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSoren Hansen <soren@canonical.com>2009-08-10 14:00:22 +0200
committerSoren Hansen <soren@canonical.com>2009-08-10 14:00:22 +0200
commit19023c5df38964a53b63f77943e3ac1d02d95d6c (patch)
treedc06003c10b15e47c622cb137c517f02e235fb89
parent157e808dce7cca6c1ef310bae0e827c65472fdff (diff)
downloadvyos-cloud-init-19023c5df38964a53b63f77943e3ac1d02d95d6c.tar.gz
vyos-cloud-init-19023c5df38964a53b63f77943e3ac1d02d95d6c.zip
Add new script: ec2-wait-for-meta-data-service.py
It will wait for around half an hour for the ec2 meta data service to turn up and eventually execute the configured bailout command (if any) if it never shows up. Call this as the first thing in the init script.
-rw-r--r--debian/init10
-rwxr-xr-xec2-wait-for-meta-data-service.py33
-rwxr-xr-xsetup.py3
3 files changed, 45 insertions, 1 deletions
diff --git a/debian/init b/debian/init
index 2fc4b822..608db7a2 100644
--- a/debian/init
+++ b/debian/init
@@ -70,10 +70,20 @@ regenerate_ssh_host_keys() {
case "$1" in
start)
+ log_daemon_msg "Waiting for EC2 meta-data service"
+ if ec2-wait-for-meta-data-service
+ then
+ log_end_msg 0
+ else
+ log_end_msg 1
+ exit 1
+ fi
+
if run_once_per_ami ssh_host_key_regeneration
then
regenerate_ssh_host_keys
fi
+
update-motd
if run_once_ever ec2-defaults
diff --git a/ec2-wait-for-meta-data-service.py b/ec2-wait-for-meta-data-service.py
new file mode 100755
index 00000000..a2759f37
--- /dev/null
+++ b/ec2-wait-for-meta-data-service.py
@@ -0,0 +1,33 @@
+#!/usr/bin/python
+#
+# Wait for the meta-data service to turn up. If it never does, execute
+# the configured bailout
+# Copyright (C) 2009 Canonical Ltd.
+#
+# Author: Soren Hansen <soren@canonical.com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 3, as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+import sys
+
+import ec2init
+
+def main():
+ ec2 = ec2init.EC2Init()
+ if ec2.wait_or_bail():
+ sys.exit(0)
+ else:
+ sys.exit(1)
+
+if __name__ == '__main__':
+ main()
diff --git a/setup.py b/setup.py
index a957f8ae..9d9e5d50 100755
--- a/setup.py
+++ b/setup.py
@@ -34,7 +34,8 @@ setup(name='EC2-init',
'ec2-run-user-data.py',
'ec2-set-apt-sources.py',
'ec2-set-defaults.py',
- 'ec2-set-hostname.py'],
+ 'ec2-set-hostname.py',
+ 'ec2-wait-for-meta-data-service.py'],
data_files=[('/etc/ec2-init', ['debian/ec2-config.cfg']),
('/etc/ec2-init/templates', glob('templates/*'))],
)