summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog2
-rwxr-xr-xbin/cloud-init4
-rw-r--r--cloudinit/distros/debian.py3
-rw-r--r--cloudinit/distros/rhel.py28
-rw-r--r--cloudinit/signal_handler.py71
-rw-r--r--doc/examples/cloud-config-landscape.txt4
6 files changed, 108 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index aca34d6e..c5dcd418 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,6 @@
0.7.0:
+ - catch signals and exit rather than stack tracing
+ - if logging fails, enable a fallback logger by patching the logging module
- do not 'start networking' in cloud-init-nonet, but add
cloud-init-container job that runs only if in container and emits
net-device-added (LP: #1031065)
diff --git a/bin/cloud-init b/bin/cloud-init
index b2a6c3ea..c5a5b949 100755
--- a/bin/cloud-init
+++ b/bin/cloud-init
@@ -38,6 +38,7 @@ patcher.patch()
from cloudinit import log as logging
from cloudinit import netinfo
+from cloudinit import signal_handler
from cloudinit import sources
from cloudinit import stages
from cloudinit import templater
@@ -497,6 +498,9 @@ def main():
if args.debug:
logging.setupBasicLogging()
+ # Setup signal handlers before running
+ signal_handler.attach_handlers()
+
(name, functor) = args.action
return functor(name, args)
diff --git a/cloudinit/distros/debian.py b/cloudinit/distros/debian.py
index da27f780..5b4aa9f8 100644
--- a/cloudinit/distros/debian.py
+++ b/cloudinit/distros/debian.py
@@ -67,8 +67,7 @@ class Distro(distros.Distro):
def _write_hostname(self, hostname, out_fn):
# "" gives trailing newline.
- lines = ["# Created by cloud-init", str(hostname), ""]
- util.write_file(out_fn, '\n'.join(lines), 0644)
+ util.write_file(out_fn, "%s\n" % str(hostname), 0644)
def update_hostname(self, hostname, prev_fn):
hostname_prev = self._read_hostname(prev_fn)
diff --git a/cloudinit/distros/rhel.py b/cloudinit/distros/rhel.py
index d81ee5fb..ec4dc2cc 100644
--- a/cloudinit/distros/rhel.py
+++ b/cloudinit/distros/rhel.py
@@ -68,12 +68,26 @@ class Distro(distros.Distro):
def install_packages(self, pkglist):
self.package_command('install', pkglist)
+ def _write_resolve(self, dns_servers, search_servers):
+ contents = []
+ if dns_servers:
+ for s in dns_servers:
+ contents.append("nameserver %s" % (s))
+ if search_servers:
+ contents.append("search %s" % (" ".join(search_servers)))
+ if contents:
+ resolve_rw_fn = self._paths.join(False, "/etc/resolv.conf")
+ contents.insert(0, '# Created by cloud-init')
+ util.write_file(resolve_rw_fn, "\n".join(contents), 0644)
+
def _write_network(self, settings):
# TODO(harlowja) fix this... since this is the ubuntu format
entries = translate_network(settings)
LOG.debug("Translated ubuntu style network settings %s into %s",
settings, entries)
# Make the intermediate format as the rhel format...
+ nameservers = []
+ searchservers = []
for (dev, info) in entries.iteritems():
net_fn = NETWORK_FN_TPL % (dev)
net_ro_fn = self._paths.join(True, net_fn)
@@ -102,11 +116,17 @@ class Distro(distros.Distro):
if mac_addr:
net_cfg["MACADDR"] = mac_addr
lines = net_cfg.write()
+ if 'dns-nameservers' in info:
+ nameservers.extend(info['dns-nameservers'])
+ if 'dns-search' in info:
+ searchservers.extend(info['dns-search'])
if not prev_exist:
lines.insert(0, '# Created by cloud-init')
w_contents = "\n".join(lines)
net_rw_fn = self._paths.join(False, net_fn)
util.write_file(net_rw_fn, w_contents, 0644)
+ if nameservers or searchservers:
+ self._write_resolve(nameservers, searchservers)
def set_hostname(self, hostname):
out_fn = self._paths.join(False, '/etc/sysconfig/network')
@@ -208,7 +228,7 @@ class Distro(distros.Distro):
def update_package_sources(self):
self._runner.run("update-sources", self.package_command,
- ["update"], freq=PER_INSTANCE)
+ ["makecache"], freq=PER_INSTANCE)
# This class helps adjust the configobj
@@ -314,6 +334,12 @@ def translate_network(settings):
val = info[k].strip().lower()
if val:
iface_info[k] = val
+ # Name server info provided??
+ if 'dns-nameservers' in info:
+ iface_info['dns-nameservers'] = info['dns-nameservers'].split()
+ # Name server search info provided??
+ if 'dns-search' in info:
+ iface_info['dns-search'] = info['dns-search'].split()
# Is any mac address spoofing going on??
if 'hwaddress' in info:
hw_info = info['hwaddress'].lower().strip()
diff --git a/cloudinit/signal_handler.py b/cloudinit/signal_handler.py
new file mode 100644
index 00000000..40b0c94c
--- /dev/null
+++ b/cloudinit/signal_handler.py
@@ -0,0 +1,71 @@
+# vi: ts=4 expandtab
+#
+# Copyright (C) 2012 Canonical Ltd.
+# Copyright (C) 2012 Yahoo! Inc.
+#
+# Author: Scott Moser <scott.moser@canonical.com>
+# Author: Joshua Harlow <harlowja@yahoo-inc.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 inspect
+import signal
+import sys
+
+from StringIO import StringIO
+
+from cloudinit import log as logging
+from cloudinit import util
+from cloudinit import version as vr
+
+LOG = logging.getLogger(__name__)
+
+
+BACK_FRAME_TRACE_DEPTH = 3
+EXIT_FOR = {
+ signal.SIGINT: ('Cloud-init %(version)s received SIGINT, exiting...', 1),
+ signal.SIGTERM: ('Cloud-init %(version)s received SIGTERM, exiting...', 1),
+ # Can't be caught...
+ # signal.SIGKILL: ('Cloud-init killed, exiting...', 1),
+ signal.SIGABRT: ('Cloud-init %(version)s received SIGABRT, exiting...', 1),
+}
+
+
+def _pprint_frame(frame, depth, max_depth, contents):
+ if depth > max_depth or not frame:
+ return
+ frame_info = inspect.getframeinfo(frame)
+ prefix = " " * (depth * 2)
+ contents.write("%sFilename: %s\n" % (prefix, frame_info.filename))
+ contents.write("%sFunction: %s\n" % (prefix, frame_info.function))
+ contents.write("%sLine number: %s\n" % (prefix, frame_info.lineno))
+ _pprint_frame(frame.f_back, depth + 1, max_depth, contents)
+
+
+def _handle_exit(signum, frame):
+ (msg, rc) = EXIT_FOR[signum]
+ msg = msg % ({'version': vr.version()})
+ contents = StringIO()
+ contents.write("%s\n" % (msg))
+ _pprint_frame(frame, 1, BACK_FRAME_TRACE_DEPTH, contents)
+ util.multi_log(contents.getvalue(),
+ console=True, stderr=False, log=LOG)
+ sys.exit(rc)
+
+
+def attach_handlers():
+ sigs_attached = 0
+ for signum in EXIT_FOR.keys():
+ signal.signal(signum, _handle_exit)
+ sigs_attached += len(EXIT_FOR)
+ return sigs_attached
diff --git a/doc/examples/cloud-config-landscape.txt b/doc/examples/cloud-config-landscape.txt
index 12c8101f..e4d23cc9 100644
--- a/doc/examples/cloud-config-landscape.txt
+++ b/doc/examples/cloud-config-landscape.txt
@@ -4,10 +4,12 @@
# will be basically rendered into a ConfigObj formated file
# under the '[client]' section of /etc/landscape/client.conf
#
+# Note: 'tags' should be specified as a comma delimited string
+# rather than a list.
landscape:
client:
url: "https://landscape.canonical.com/message-system"
ping_url: "http://landscape.canonical.com/ping"
data_path: "/var/lib/landscape/client"
http_proxy: "http://my.proxy.com/foobar"
- tags: [ server, cloud ]
+ tags: "server,cloud"