diff options
author | Scott Moser <smoser@ubuntu.com> | 2015-03-04 09:47:17 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2015-03-04 09:47:17 -0500 |
commit | 30868baba637b45b654bd8a23719624a25b2a00b (patch) | |
tree | 9d63eb054648f0d6ed7cf6a878e57eefdfeb1666 /cloudinit/config/cc_emit_upstart.py | |
parent | 48297d2a5d5cd41286135e6c17b37e67fc1bc40d (diff) | |
download | vyos-cloud-init-30868baba637b45b654bd8a23719624a25b2a00b.tar.gz vyos-cloud-init-30868baba637b45b654bd8a23719624a25b2a00b.zip |
run emit_upstart only if upstart was init system
Diffstat (limited to 'cloudinit/config/cc_emit_upstart.py')
-rw-r--r-- | cloudinit/config/cc_emit_upstart.py | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/cloudinit/config/cc_emit_upstart.py b/cloudinit/config/cc_emit_upstart.py index 6d376184..e1b9a4c2 100644 --- a/cloudinit/config/cc_emit_upstart.py +++ b/cloudinit/config/cc_emit_upstart.py @@ -21,11 +21,32 @@ import os from cloudinit.settings import PER_ALWAYS +from cloudinit import log as logging from cloudinit import util frequency = PER_ALWAYS distros = ['ubuntu', 'debian'] +LOG = logging.getLogger(__name__) + + +def is_upstart_system(): + if not os.path.isfile("/sbin/initctl"): + LOG.debug(("Skipping module named %s," + " no /sbin/initctl located"), name) + return False + + myenv = os.environ.copy() + if 'UPSTART_SESSION' in myenv: + del myenv['UPSTART_SESSION'] + check_cmd = ['initctl', 'version'] + try: + (out, err) = util.subp(check_cmd, env=myenv) + return 'upstart' in out + except util.ProcessExecutionError as e: + LOG.debug("'%s' returned '%s', not using upstart", + ' '.join(check_cmd), e.exit_code) + return False def handle(name, _cfg, cloud, log, args): @@ -34,10 +55,11 @@ def handle(name, _cfg, cloud, log, args): # Default to the 'cloud-config' # event for backwards compat. event_names = ['cloud-config'] - if not os.path.isfile("/sbin/initctl"): - log.debug(("Skipping module named %s," - " no /sbin/initctl located"), name) + + if not is_upstart_system(): + log.debug("not upstart system, '%s' disabled") return + cfgpath = cloud.paths.get_ipath_cur("cloud_config") for n in event_names: cmd = ['initctl', 'emit', str(n), 'CLOUD_CFG=%s' % cfgpath] |