From 27c079bb14667fda52937ee198b72c80823f3a4f Mon Sep 17 00:00:00 2001 From: Chen-Han Hsiao Date: Mon, 5 Jun 2017 17:55:50 -0600 Subject: systemd: Fix typo in comment in cloud-init.target. Simply fix a typo in a comment. No functional change. --- systemd/cloud-init.target | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'systemd') diff --git a/systemd/cloud-init.target b/systemd/cloud-init.target index d5684582..083c3b6f 100644 --- a/systemd/cloud-init.target +++ b/systemd/cloud-init.target @@ -1,6 +1,6 @@ # cloud-init target is enabled by cloud-init-generator # To disable it you can either: -# a.) boot with kernel cmdline of 'cloudinit=disabled' +# a.) boot with kernel cmdline of 'cloud-init=disabled' # b.) touch a file /etc/cloud/cloud-init.disabled [Unit] Description=Cloud-init target -- cgit v1.2.3 From 11121fe4d5af0554140d88685029fa248fa0c7c9 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Mon, 12 Jun 2017 14:10:58 -0400 Subject: systemd: make cloud-final.service run before apt daily services. This changes all cloud-init systemd units to run 'Before' the apt processes that run daily and may cause a lock on the apt database. apt-daily-upgrade.service contains 'After=apt-daily.service'. Thus following order is enforced, so we can just be 'Before' the first. apt-daily.service apt-daily-upgrade.service Note that this means only that apt-daily* will not run until cloud-init has entirely finished. Any other processes running apt-get operations are still affected by the global lock. LP: #1693361 --- systemd/cloud-final.service | 1 + 1 file changed, 1 insertion(+) (limited to 'systemd') diff --git a/systemd/cloud-final.service b/systemd/cloud-final.service index b8f69b78..66f5b8fc 100644 --- a/systemd/cloud-final.service +++ b/systemd/cloud-final.service @@ -2,6 +2,7 @@ Description=Execute cloud user/final scripts After=network-online.target cloud-config.service rc-local.service multi-user.target Wants=network-online.target cloud-config.service +Before=apt-daily.service [Service] Type=oneshot -- cgit v1.2.3 From dcbe479575fac9f293c5c4089f4bcb46ab887206 Mon Sep 17 00:00:00 2001 From: Ryan Harper Date: Tue, 13 Jun 2017 09:06:41 -0500 Subject: Templatize systemd unit files for cross distro deltas. Under el7, cloud-init systemd files need some unit tweaks to ensure they run at the right time. Pull in current el7 downstream systemd unit changes. --- packages/redhat/cloud-init.spec.in | 5 ----- setup.py | 31 +++++++++++++++++++------------ systemd/cloud-config.service | 16 ---------------- systemd/cloud-config.service.tmpl | 17 +++++++++++++++++ systemd/cloud-final.service | 18 ------------------ systemd/cloud-final.service.tmpl | 22 ++++++++++++++++++++++ systemd/cloud-init-local.service | 24 ------------------------ systemd/cloud-init-local.service.tmpl | 29 +++++++++++++++++++++++++++++ systemd/cloud-init.service | 27 --------------------------- systemd/cloud-init.service.tmpl | 35 +++++++++++++++++++++++++++++++++++ 10 files changed, 122 insertions(+), 102 deletions(-) delete mode 100644 systemd/cloud-config.service create mode 100644 systemd/cloud-config.service.tmpl delete mode 100644 systemd/cloud-final.service create mode 100644 systemd/cloud-final.service.tmpl delete mode 100644 systemd/cloud-init-local.service create mode 100644 systemd/cloud-init-local.service.tmpl delete mode 100644 systemd/cloud-init.service create mode 100644 systemd/cloud-init.service.tmpl (limited to 'systemd') diff --git a/packages/redhat/cloud-init.spec.in b/packages/redhat/cloud-init.spec.in index 9f75c4b8..6ab0d20b 100644 --- a/packages/redhat/cloud-init.spec.in +++ b/packages/redhat/cloud-init.spec.in @@ -115,11 +115,6 @@ rm -rf $RPM_BUILD_ROOT%{python_sitelib}/tests mkdir -p $RPM_BUILD_ROOT/%{_sharedstatedir}/cloud mkdir -p $RPM_BUILD_ROOT/%{_libexecdir}/%{name} -%if "%{init_system}" == "systemd" -mkdir -p $RPM_BUILD_ROOT/%{_unitdir} -cp -p systemd/* $RPM_BUILD_ROOT/%{_unitdir} -%endif - %clean rm -rf $RPM_BUILD_ROOT diff --git a/setup.py b/setup.py index bce06ad9..1197eceb 100755 --- a/setup.py +++ b/setup.py @@ -87,8 +87,8 @@ def read_requires(): return str(deps).splitlines() -def render_cloud_cfg(): - """render cloud.cfg into a tmpdir under same dir as setup.py +def render_tmpl(template): + """render template into a tmpdir under same dir as setup.py This is rendered to a temporary directory under the top level directory with the name 'cloud.cfg'. The reason for not just rendering @@ -99,16 +99,21 @@ def render_cloud_cfg(): # older versions of tox use bdist (xenial), and then install from there. # newer versions just use install. if not (sys.argv[1] == 'install' or sys.argv[1].startswith('bdist*')): - return 'config/cloud.cfg.tmpl' + return template + + tmpl_ext = ".tmpl" + # we may get passed a non-template file, just pass it back + if not template.endswith(tmpl_ext): + return template + topdir = os.path.dirname(sys.argv[0]) tmpd = tempfile.mkdtemp(dir=topdir) atexit.register(shutil.rmtree, tmpd) - fpath = os.path.join(tmpd, 'cloud.cfg') - tiny_p([sys.executable, './tools/render-cloudcfg', - 'config/cloud.cfg.tmpl', fpath]) - # relpath is relative to setup.py - relpath = os.path.join(os.path.basename(tmpd), 'cloud.cfg') - return relpath + bname = os.path.basename(template).rstrip(tmpl_ext) + fpath = os.path.join(tmpd, bname) + tiny_p([sys.executable, './tools/render-cloudcfg', template, fpath]) + # return path relative to setup.py + return os.path.join(os.path.basename(tmpd), bname) INITSYS_FILES = { @@ -116,8 +121,10 @@ INITSYS_FILES = { '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)], 'sysvinit_openrc': [f for f in glob('sysvinit/gentoo/*') if is_f(f)], - 'systemd': [f for f in (glob('systemd/*.service') + - glob('systemd/*.target')) if is_f(f)], + 'systemd': [render_tmpl(f) + for f in (glob('systemd/*.tmpl') + + 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)], } @@ -195,7 +202,7 @@ if not in_virtualenv(): INITSYS_ROOTS[k] = "/" + INITSYS_ROOTS[k] data_files = [ - (ETC + '/cloud', [render_cloud_cfg()]), + (ETC + '/cloud', [render_tmpl("config/cloud.cfg.tmpl")]), (ETC + '/cloud/cloud.cfg.d', glob('config/cloud.cfg.d/*')), (ETC + '/cloud/templates', glob('templates/*')), (USR_LIB_EXEC + '/cloud-init', ['tools/ds-identify', diff --git a/systemd/cloud-config.service b/systemd/cloud-config.service deleted file mode 100644 index 3309e08a..00000000 --- a/systemd/cloud-config.service +++ /dev/null @@ -1,16 +0,0 @@ -[Unit] -Description=Apply the settings specified in cloud-config -After=network-online.target cloud-config.target -Wants=network-online.target cloud-config.target - -[Service] -Type=oneshot -ExecStart=/usr/bin/cloud-init modules --mode=config -RemainAfterExit=yes -TimeoutSec=0 - -# Output needs to appear in instance console output -StandardOutput=journal+console - -[Install] -WantedBy=cloud-init.target diff --git a/systemd/cloud-config.service.tmpl b/systemd/cloud-config.service.tmpl new file mode 100644 index 00000000..bdee3ce0 --- /dev/null +++ b/systemd/cloud-config.service.tmpl @@ -0,0 +1,17 @@ +## template:jinja +[Unit] +Description=Apply the settings specified in cloud-config +After=network-online.target cloud-config.target +Wants=network-online.target cloud-config.target + +[Service] +Type=oneshot +ExecStart=/usr/bin/cloud-init modules --mode=config +RemainAfterExit=yes +TimeoutSec=0 + +# Output needs to appear in instance console output +StandardOutput=journal+console + +[Install] +WantedBy=cloud-init.target diff --git a/systemd/cloud-final.service b/systemd/cloud-final.service deleted file mode 100644 index 66f5b8fc..00000000 --- a/systemd/cloud-final.service +++ /dev/null @@ -1,18 +0,0 @@ -[Unit] -Description=Execute cloud user/final scripts -After=network-online.target cloud-config.service rc-local.service multi-user.target -Wants=network-online.target cloud-config.service -Before=apt-daily.service - -[Service] -Type=oneshot -ExecStart=/usr/bin/cloud-init modules --mode=final -RemainAfterExit=yes -TimeoutSec=0 -KillMode=process - -# Output needs to appear in instance console output -StandardOutput=journal+console - -[Install] -WantedBy=cloud-init.target diff --git a/systemd/cloud-final.service.tmpl b/systemd/cloud-final.service.tmpl new file mode 100644 index 00000000..fc01b891 --- /dev/null +++ b/systemd/cloud-final.service.tmpl @@ -0,0 +1,22 @@ +## template:jinja +[Unit] +Description=Execute cloud user/final scripts +After=network-online.target cloud-config.service rc-local.service +{% if variant in ["ubuntu", "unknown", "debian"] %} +After=multi-user.target +{% endif %} +Wants=network-online.target cloud-config.service +Before=apt-daily.service + +[Service] +Type=oneshot +ExecStart=/usr/bin/cloud-init modules --mode=final +RemainAfterExit=yes +TimeoutSec=0 +KillMode=process + +# Output needs to appear in instance console output +StandardOutput=journal+console + +[Install] +WantedBy=cloud-init.target diff --git a/systemd/cloud-init-local.service b/systemd/cloud-init-local.service deleted file mode 100644 index 7ee43eda..00000000 --- a/systemd/cloud-init-local.service +++ /dev/null @@ -1,24 +0,0 @@ -[Unit] -Description=Initial cloud-init job (pre-networking) -DefaultDependencies=no -Wants=network-pre.target -After=systemd-remount-fs.service -Before=NetworkManager.service -Before=network-pre.target -Before=shutdown.target -Before=sysinit.target -Conflicts=shutdown.target -RequiresMountsFor=/var/lib/cloud - -[Service] -Type=oneshot -ExecStart=/usr/bin/cloud-init init --local -ExecStart=/bin/touch /run/cloud-init/network-config-ready -RemainAfterExit=yes -TimeoutSec=0 - -# Output needs to appear in instance console output -StandardOutput=journal+console - -[Install] -WantedBy=cloud-init.target diff --git a/systemd/cloud-init-local.service.tmpl b/systemd/cloud-init-local.service.tmpl new file mode 100644 index 00000000..ff9c644d --- /dev/null +++ b/systemd/cloud-init-local.service.tmpl @@ -0,0 +1,29 @@ +## template:jinja +[Unit] +Description=Initial cloud-init job (pre-networking) +{% if variant in ["ubuntu", "unknown", "debian"] %} +DefaultDependencies=no +{% endif %} +Wants=network-pre.target +After=systemd-remount-fs.service +Before=NetworkManager.service +Before=network-pre.target +Before=shutdown.target +{% if variant in ["ubuntu", "unknown", "debian"] %} +Before=sysinit.target +Conflicts=shutdown.target +{% endif %} +RequiresMountsFor=/var/lib/cloud + +[Service] +Type=oneshot +ExecStart=/usr/bin/cloud-init init --local +ExecStart=/bin/touch /run/cloud-init/network-config-ready +RemainAfterExit=yes +TimeoutSec=0 + +# Output needs to appear in instance console output +StandardOutput=journal+console + +[Install] +WantedBy=cloud-init.target diff --git a/systemd/cloud-init.service b/systemd/cloud-init.service deleted file mode 100644 index 39acc20a..00000000 --- a/systemd/cloud-init.service +++ /dev/null @@ -1,27 +0,0 @@ -[Unit] -Description=Initial cloud-init job (metadata service crawler) -DefaultDependencies=no -Wants=cloud-init-local.service -Wants=sshd-keygen.service -Wants=sshd.service -After=cloud-init-local.service -After=systemd-networkd-wait-online.service -After=networking.service -Before=network-online.target -Before=sshd-keygen.service -Before=sshd.service -Before=sysinit.target -Before=systemd-user-sessions.service -Conflicts=shutdown.target - -[Service] -Type=oneshot -ExecStart=/usr/bin/cloud-init init -RemainAfterExit=yes -TimeoutSec=0 - -# Output needs to appear in instance console output -StandardOutput=journal+console - -[Install] -WantedBy=cloud-init.target diff --git a/systemd/cloud-init.service.tmpl b/systemd/cloud-init.service.tmpl new file mode 100644 index 00000000..2c71889d --- /dev/null +++ b/systemd/cloud-init.service.tmpl @@ -0,0 +1,35 @@ +## template:jinja +[Unit] +Description=Initial cloud-init job (metadata service crawler) +DefaultDependencies=no +Wants=cloud-init-local.service +Wants=sshd-keygen.service +Wants=sshd.service +After=cloud-init-local.service +After=systemd-networkd-wait-online.service +{% if variant in ["ubuntu", "unknown", "debian"] %} +After=networking.service +{% endif %} +{% if variant in ["centos", "fedora", "redhat"] %} +After=network.service +{% endif %} +Before=network-online.target +Before=sshd-keygen.service +Before=sshd.service +{% if variant in ["ubuntu", "unknown", "debian"] %} +Before=sysinit.target +Conflicts=shutdown.target +{% endif %} +Before=systemd-user-sessions.service + +[Service] +Type=oneshot +ExecStart=/usr/bin/cloud-init init +RemainAfterExit=yes +TimeoutSec=0 + +# Output needs to appear in instance console output +StandardOutput=journal+console + +[Install] +WantedBy=cloud-init.target -- cgit v1.2.3 From 1f5489c258a26f4e26261c40786537951d67df1e Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Thu, 8 Dec 2016 13:27:53 +0100 Subject: systemd: make systemd-fsck run after cloud-init.service cloud-init.service may write filesystems (fs_setup) or re-partition (disk_setup) disks. If systemd-fsck is running on a device while that is occuring then the partitioning or mkfs might fail due to the device being busy. Alternatively, the fsck might fail and cause subsequent mount to fail. LP: #1691489 --- setup.py | 4 ++++ systemd/systemd-fsck@.service.d/cloud-init.conf | 2 ++ 2 files changed, 6 insertions(+) create mode 100644 systemd/systemd-fsck@.service.d/cloud-init.conf (limited to 'systemd') diff --git a/setup.py b/setup.py index 1197eceb..b1bde43b 100755 --- a/setup.py +++ b/setup.py @@ -125,6 +125,7 @@ INITSYS_FILES = { for f in (glob('systemd/*.tmpl') + glob('systemd/*.service') + glob('systemd/*.target')) if is_f(f)], + 'systemd.fsck-dropin': ['systemd/systemd-fsck@.service.d/cloud-init.conf'], 'systemd.generators': [f for f in glob('systemd/*-generator') if is_f(f)], 'upstart': [f for f in glob('upstart/*') if is_f(f)], } @@ -134,6 +135,9 @@ INITSYS_ROOTS = { 'sysvinit_deb': 'etc/init.d', 'sysvinit_openrc': 'etc/init.d', 'systemd': pkg_config_read('systemd', 'systemdsystemunitdir'), + 'systemd.fsck-dropin': ( + os.path.sep.join([pkg_config_read('systemd', 'systemdsystemunitdir'), + 'systemd-fsck@.service.d'])), 'systemd.generators': pkg_config_read('systemd', 'systemdsystemgeneratordir'), 'upstart': 'etc/init/', diff --git a/systemd/systemd-fsck@.service.d/cloud-init.conf b/systemd/systemd-fsck@.service.d/cloud-init.conf new file mode 100644 index 00000000..0bfa465b --- /dev/null +++ b/systemd/systemd-fsck@.service.d/cloud-init.conf @@ -0,0 +1,2 @@ +[Unit] +After=cloud-init.service -- cgit v1.2.3