forked from riptano/ComboAMI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathds0_updater.py
executable file
·52 lines (43 loc) · 2.03 KB
/
ds0_updater.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
# Script provided by DataStax.
# Updating this script requires a rebake of the ami.
#
# The baked version of this script is launched in order to fetch updated ami
# startup code for subsequent phases. Python has already read the baked
# version from disk by the time updates start, with the result that post-bake
# updates to this file are ignored.
import time
import ds0_utils
import logger
import conf
# Wait for cloud-init to finish, it changes all sorts of fundamental
# things on startup (including apt-repo mirrors, but lots of other stuff too)
# and is known to continue doing work after ssh is up and running, and can
# cause all sorts of operations to fail in unexpected ways if it's not finished
logger.info("Waiting for cloud-init to finish...")
# Sleeping a fixed time of 10 seconds is a terrible hack. It would be much
# better to wait for cloud-init to signal that it's finished, which it does
# through the creation of /var/lib/cloud/instance/boot-finished. Unfortunately,
# in Upstart environments, the upstart job for cloud-init also waits for all
# the rc scripts at runlevel 2 to finish... which this file is one of.
# I'm sure it's possible to resolve this circular dependency if we take on
# maintaining upstart scripts, but I'm not ready for that at this point (though
# would welcome a clean pull-request)
time.sleep(10)
# Update the AMI codebase if it's its first boot
if not conf.get_config("AMI", "CompletedFirstBoot"):
(repository, commitish) = ds0_utils.repository()
logger.info('Repository: %s, Commit-ish: %s' % (repository, commitish))
# Reset the origin if a repository was specified
if repository:
logger.exe('git remote rm origin')
logger.exe('git remote add origin %s' % repository)
# update the repo
logger.exe('git fetch', expectError=True) # git fetch outputs to stderr
logger.exe('git reset --hard %s' % ds0_utils.get_git_reset_arg(commitish))
# Start AMI start code
try:
import ds1_launcher
ds1_launcher.run()
except:
logger.exception('ds0_updater.py')