← Back to team overview

cloud-init-dev team mailing list archive

[Merge] lp:~smoser/cloud-init/trunk.disable-clouddinit into lp:cloud-init

 

Scott Moser has proposed merging lp:~smoser/cloud-init/trunk.disable-clouddinit into lp:cloud-init.

Requested reviews:
  cloud init development team (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~smoser/cloud-init/trunk.disable-clouddinit/+merge/287580
-- 
Your team cloud init development team is requested to review the proposed merge of lp:~smoser/cloud-init/trunk.disable-clouddinit into lp:cloud-init.
=== modified file 'setup.py'
--- setup.py	2015-07-21 12:06:11 +0000
+++ setup.py	2016-03-01 05:30:38 +0000
@@ -45,39 +45,50 @@
         stdout = None
         stderr = None
     sp = subprocess.Popen(cmd, stdout=stdout,
-                    stderr=stderr, stdin=None,
-                    universal_newlines=True)
+                          stderr=stderr, stdin=None,
+                          universal_newlines=True)
     (out, err) = sp.communicate()
     ret = sp.returncode
     if ret not in [0]:
-        raise RuntimeError("Failed running %s [rc=%s] (%s, %s)"
-                            % (cmd, ret, out, err))
+        raise RuntimeError("Failed running %s [rc=%s] (%s, %s)" %
+                           (cmd, ret, out, err))
     return (out, err)
 
 
-def systemd_unitdir():
-    cmd = ['pkg-config', '--variable=systemdsystemunitdir', 'systemd']
+def pkg_config_read(library, var):
+    fallbacks = {
+       'systemd': {
+           'systemdsystemunitdir': '/lib/systemd/system',
+           'systemdsystemgeneratordir': '/lib/systemd/system-generators',
+       }
+    }
+    cmd = ['pkg-config', '--variable=%s' % var, library]
     try:
         (path, err) = tiny_p(cmd)
     except:
-        return '/lib/systemd/system'
+        return fallbacks[library][var]
     return str(path).strip()
 
+
 INITSYS_FILES = {
     'sysvinit': [f for f in glob('sysvinit/redhat/*') if is_f(f)],
     'sysvinit_freebsd': [f for f in glob('sysvinit/freebsd/*') if is_f(f)],
     'sysvinit_deb': [f for f in glob('sysvinit/debian/*') if is_f(f)],
-    'systemd': [f for f in glob('systemd/*') if is_f(f)],
+    'systemd': [f for f in (glob('systemd/*.service') +
+                            glob('systemd/*.target')) if is_f(f)],
+    'systemd.generators': [f for f in glob('systemd/*-generator') if is_f(f)],
     'upstart': [f for f in glob('upstart/*') if is_f(f)],
 }
 INITSYS_ROOTS = {
     'sysvinit': '/etc/rc.d/init.d',
     'sysvinit_freebsd': '/usr/local/etc/rc.d',
     'sysvinit_deb': '/etc/init.d',
-    'systemd': systemd_unitdir(),
+    'systemd': pkg_config_read('systemd', 'systemdsystemunitdir'),
+    'systemd.generators': pkg_config_read('systemd',
+                                          'systemdsystemgeneratordir'),
     'upstart': '/etc/init/',
 }
-INITSYS_TYPES = sorted(list(INITSYS_ROOTS.keys()))
+INITSYS_TYPES = sorted([f.partition(".")[0] for f in INITSYS_ROOTS.keys()])
 
 # Install everything in the right location and take care of Linux (default) and
 # FreeBSD systems.
@@ -122,9 +133,8 @@
     user_options = install.user_options + [
         # This will magically show up in member variable 'init_sys'
         ('init-system=', None,
-            ('init system(s) to configure (%s) [default: None]') %
-                (", ".join(INITSYS_TYPES))
-        ),
+         ('init system(s) to configure (%s) [default: None]' %
+          (", ".join(INITSYS_TYPES)))),
     ]
 
     def initialize_options(self):
@@ -138,7 +148,8 @@
             self.init_system = self.init_system.split(",")
 
         if len(self.init_system) == 0:
-            raise DistutilsArgError(("You must specify one of (%s) when"
+            raise DistutilsArgError(
+                ("You must specify one of (%s) when"
                  " specifying init system(s)!") % (", ".join(INITSYS_TYPES)))
 
         bad = [f for f in self.init_system if f not in INITSYS_TYPES]
@@ -147,8 +158,12 @@
                 "Invalid --init-system: %s" % (','.join(bad)))
 
         for system in self.init_system:
-            self.distribution.data_files.append(
-                (INITSYS_ROOTS[system], INITSYS_FILES[system]))
+            # add data files for anything that starts with '<system>.'
+            datakeys = [k for k in INITSYS_ROOTS
+                        if k.partition(".")[0] == system]
+            for k in datakeys:
+                self.distribution.data_files.append(
+                    (INITSYS_ROOTS[k], INITSYS_FILES[k]))
         # Force that command to reinitalize (with new file list)
         self.distribution.reinitialize_command('install_data', True)
 
@@ -182,18 +197,18 @@
     requirements.append('cheetah')
 
 
-setuptools.setup(name='cloud-init',
-      version=get_version(),
-      description='EC2 initialisation magic',
-      author='Scott Moser',
-      author_email='scott.moser@xxxxxxxxxxxxx',
-      url='http://launchpad.net/cloud-init/',
-      packages=setuptools.find_packages(exclude=['tests']),
-      scripts=['bin/cloud-init',
-               'tools/cloud-init-per',
-               ],
-      license='GPLv3',
-      data_files=data_files,
-      install_requires=requirements,
-      cmdclass=cmdclass,
-      )
+setuptools.setup(
+    name='cloud-init',
+    version=get_version(),
+    description='EC2 initialisation magic',
+    author='Scott Moser',
+    author_email='scott.moser@xxxxxxxxxxxxx',
+    url='http://launchpad.net/cloud-init/',
+    packages=setuptools.find_packages(exclude=['tests']),
+    scripts=['bin/cloud-init',
+             'tools/cloud-init-per'],
+    license='GPLv3',
+    data_files=data_files,
+    install_requires=requirements,
+    cmdclass=cmdclass,
+    )

=== modified file 'systemd/cloud-config.service'
--- systemd/cloud-config.service	2015-04-09 15:54:01 +0000
+++ systemd/cloud-config.service	2016-03-01 05:30:38 +0000
@@ -13,4 +13,4 @@
 StandardOutput=journal+console
 
 [Install]
-WantedBy=multi-user.target
+WantedBy=cloud-init.target

=== modified file 'systemd/cloud-final.service'
--- systemd/cloud-final.service	2015-11-30 20:33:28 +0000
+++ systemd/cloud-final.service	2016-03-01 05:30:38 +0000
@@ -14,4 +14,4 @@
 StandardOutput=journal+console
 
 [Install]
-WantedBy=multi-user.target
+WantedBy=cloud-init.target

=== added file 'systemd/cloud-init-generator'
--- systemd/cloud-init-generator	1970-01-01 00:00:00 +0000
+++ systemd/cloud-init-generator	2016-03-01 05:30:38 +0000
@@ -0,0 +1,122 @@
+#!/bin/sh
+set -f
+
+LOG=""
+DEBUG_LEVEL=1
+LOG_D="/run"
+ENABLE="enabled"
+DISABLE="disabled"
+CLOUD_SYSTEM_TARGET="/lib/systemd/system/cloud-init.target"
+CLOUD_TARGET_NAME="cloud-init.target"
+
+debug() {
+    local lvl="$1"
+    shift
+    [ "$lvl" -gt "$DEBUG_LEVEL" ] && return
+    if [ -z "$LOG" ]; then
+        local log="$LOG_D/${0##*/}-generator.log"
+        { : > "$log"; } >/dev/null 2>&1 && LOG="$log" ||
+            LOG="/dev/kmsg"
+    fi
+    echo "$@" >> "$LOG"
+}
+
+etc_file() {
+    local pprefix="${1:-/etc/cloud/cloud-init.}"
+    _RET="unset"
+    [ -f "${pprefix}$ENABLE" ] && _RET="$ENABLE" && return 0
+    [ -f "${pprefix}$DISABLE" ] && _RET="$DISABLE" && return 0
+    return 0
+}
+
+read_proc_cmdline() {
+    if [ "$container" = "lxc" ]; then
+        _RET=""
+        return 0
+    fi
+
+    if systemd-detect-virt --container --quiet; then
+        _RET=""
+        return 0
+    fi
+
+    read _RET < /proc/cmdline
+}
+
+kernel_cmdline() {
+    local cmdline="" tok=""
+    if [ -n "${KERNEL_CMDLINE+$KERNEL_CMDLINE}" ]; then
+        cmdline=${KERNEL_CMDLINE}
+        debug 1 "kernel command line from env KERNEL_CMDLINE: $cmdline"
+    elif read_proc_cmdline; then
+        read_proc_cmdline && cmdline="$_RET"
+        debug 1 "kernel command line from /proc/cmdline: $cmdline"
+    fi
+    _RET="unset"
+    cmdline=" $cmdline "
+    tok=${cmdline##* cloud-init=}
+    [ "$tok" = "$cmdline" ] && _RET="unset"
+    tok=${tok%% *}
+    [ "$tok" = "$ENABLE" -o "$tok" = "$DISABLE" ] && _RET="$tok"
+    return 0
+}
+
+default() {
+    _RET="$ENABLE"
+}
+
+main() {
+    local normal_d="$1" early_d="$2" late_d="$3"
+    local target_name="multi-user.target" gen_d="$early_d"
+    local link_path="$gen_d/${target_name}.wants/${CLOUD_TARGET_NAME}"
+
+    debug 1 "$0 normal=$normal_d early=$early_d late=$late_d"
+    debug 2 "$0 $*"
+
+    local search result="error" ret=""
+    for search in kernel_cmdline etc_file default; do
+        if $search; then
+            debug 1 "$search found $_RET"
+            [ "$_RET" = "$ENABLE" -o "$_RET" = "$DISABLE" ] &&
+                result=$_RET && break
+        else
+            ret=$?
+            debug 0 "search $search returned $ret"
+        fi
+    done
+    
+    if [ "$result" = "$ENABLE" ]; then
+        if [ -e "$link_path" ]; then
+                debug 1 "already enabled: no change needed"
+        else
+            [ -d "${link_path%/*}" ] || mkdir -p "${link_path%/*}" ||
+                debug 0 "failed to make dir $link_path"
+            if ln -snf "$CLOUD_SYSTEM_TARGET" "$link_path"; then
+                debug 1 "enabled via $link_path -> $CLOUD_SYSTEM_TARGET"
+            else
+                ret=$?
+                debug 0 "[$ret] enable failed:" \
+                    "ln $CLOUD_SYSTEM_TARGET $link_path"
+            fi
+        fi
+    elif [ "$result" = "$DISABLE" ]; then
+        if [ -f "$link_path" ]; then
+            if rm -f "$link_path"; then
+                debug 1 "disabled. removed existing $link_path"
+            else
+                ret=$?
+                debug 0 "[$ret] disable failed, remove $link_path"
+            fi
+        else
+            debug 1 "already disabled: no change needed"
+        fi
+    else
+        debug 0 "unexpected result '$result'"
+        ret=3
+    fi
+    return $ret
+}
+
+main "$@"
+
+# vi: ts=4 expandtab

=== modified file 'systemd/cloud-init-local.service'
--- systemd/cloud-init-local.service	2013-09-20 23:04:49 +0000
+++ systemd/cloud-init-local.service	2016-03-01 05:30:38 +0000
@@ -13,4 +13,4 @@
 StandardOutput=journal+console
 
 [Install]
-WantedBy=multi-user.target
+WantedBy=cloud-init.target

=== modified file 'systemd/cloud-init.service'
--- systemd/cloud-init.service	2015-04-09 15:54:01 +0000
+++ systemd/cloud-init.service	2016-03-01 05:30:38 +0000
@@ -15,4 +15,4 @@
 StandardOutput=journal+console
 
 [Install]
-WantedBy=multi-user.target
+WantedBy=cloud-init.target

=== added file 'systemd/cloud-init.target'
--- systemd/cloud-init.target	1970-01-01 00:00:00 +0000
+++ systemd/cloud-init.target	2016-03-01 05:30:38 +0000
@@ -0,0 +1,16 @@
+# cloud-init target is enabled by cloud-init-generator
+# To disable it you can either:
+#  a.) boot with kernel cmdline of 'cloudinit=disabled'
+#  b.) touch a file /etc/cloud/cloud-init.disabled
+# cloud-init normally emits a "cloud-config" upstart event to inform third
+# parties that cloud-config is available, which does us no good when we're
+# using systemd.  cloud-config.target serves as this synchronization point
+# instead.  Services that would "start on cloud-config" with upstart can
+# instead use "After=cloud-config.target" and "Wants=cloud-config.target"
+# as appropriate.
+
+[Unit]
+Description=Cloud-init target
+Wants=cloud-init-local.service cloud-init.service
+After=cloud-init-local.service cloud-init.service
+


Follow ups