summaryrefslogtreecommitdiff
path: root/setup.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2016-03-04 00:41:52 -0500
committerScott Moser <smoser@ubuntu.com>2016-03-04 00:41:52 -0500
commit3400f839651d308e495d1d8a1d7c1c2b463ad98b (patch)
tree91bb7977e00c18d955c1b5a10a366bdb94422295 /setup.py
parent2231c45ac3712c5cb7c1b810c838d3f91f424bf2 (diff)
parent9b0cbf54a90d2434e2a93e34664646ee8638fc97 (diff)
downloadvyos-cloud-init-3400f839651d308e495d1d8a1d7c1c2b463ad98b.tar.gz
vyos-cloud-init-3400f839651d308e495d1d8a1d7c1c2b463ad98b.zip
systemd: support disabling cloud-init via file or kernel cmdline
This adds a systemd generator for a 'cloud-init.target'. That target will be WantedBy multi-user.target in the default case. If there is a file /etc/cloud/cloud-init.disabled or the kernel command line contains 'cloud-init=disabled' then cloud-init will not affect boot at all. There are some packages/debian changes to affect this: * postinst, preinst: these are necessary to remove some old target files for multi-user.target (LP: #1552999) * changes to include these files in the debian source package. * rules.in: supports DEB_BUILD_OPTIONS=nocheck to not run check setup.py: mostly changes to support installing the generator but also pep8 fixes along the way systemd/*: make each of the services 'WantedBy=cloud-init.target' rather than being wanted by multi-user.target
Diffstat (limited to 'setup.py')
-rwxr-xr-xsetup.py77
1 files changed, 46 insertions, 31 deletions
diff --git a/setup.py b/setup.py
index 5f61681b..0b261dfe 100755
--- a/setup.py
+++ b/setup.py
@@ -45,39 +45,50 @@ def tiny_p(cmd, capture=True):
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 @@ class InitsysInstallData(install):
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 @@ class InitsysInstallData(install):
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 @@ class InitsysInstallData(install):
"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 @@ if sys.version_info < (3,):
requirements.append('cheetah')
-setuptools.setup(name='cloud-init',
- version=get_version(),
- description='EC2 initialisation magic',
- author='Scott Moser',
- author_email='scott.moser@canonical.com',
- 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@canonical.com',
+ 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,
+ )