Skip to content

Commit

Permalink
systemd and config: align rhel custom files with upstream
Browse files Browse the repository at this point in the history
So far RHEL had its own custom .service and cloud.cfg files,
that diverged from upstream. We always replaced the generated files
with the ones we had.

This caused only confusion and made it harder to rebase and backport
patches targeting these files.
Hopefully this brings some alignment with upstream.
At the same time, we are going to delete our custom downstream-only files
and use the ones generated by .tmpl.

The mapping is
config/cloud.cfg.tmpl -> rhel/cloud.cfg
systemd/* -> rhel/systemd/*

Such rhel-specific files are open and available in the Centos repo:
https://gitlab.com/redhat/centos-stream/src/cloud-init

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  • Loading branch information
esposem committed May 5, 2022
1 parent 558f037 commit 36a1e8b
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 8 deletions.
39 changes: 32 additions & 7 deletions config/cloud.cfg.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ disable_root: true

{% if variant in ["almalinux", "alpine", "amazon", "centos", "cloudlinux", "eurolinux",
"fedora", "miraclelinux", "openEuler", "rhel", "rocky", "virtuozzo"] %}
{% if variant == "rhel" %}
mount_default_fields: [~, ~, 'auto', 'defaults,nofail,x-systemd.requires=cloud-init.service,_netdev', '0', '2']
{% else %}
mount_default_fields: [~, ~, 'auto', 'defaults,nofail', '0', '2']
{% endif %}
{% if variant == "amazon" %}
resize_rootfs: noblock
{% endif %}
Expand Down Expand Up @@ -66,6 +70,14 @@ network:
config: disabled
{% endif %}

{% if variant == "rhel" %}
# Default redhat settings:
ssh_deletekeys: 1
ssh_genkeytypes: ['rsa', 'ecdsa', 'ed25519']
syslog_fix_perms: ~
disable_vmware_customization: false
{% endif %}

# The modules that run in the 'init' stage
cloud_init_modules:
- migrator
Expand All @@ -89,7 +101,7 @@ cloud_init_modules:
- resolv_conf
{% endif %}
{% if not variant.endswith("bsd") %}
{% if variant not in ["photon"] %}
{% if variant not in ["photon", "rhel"] %}
- ca-certs
{% endif %}
- rsyslog
Expand All @@ -106,13 +118,18 @@ cloud_config_modules:
- snap
{% endif %}
{% if variant not in ["photon"] %}
{% if variant not in ["rhel"] %}
- ssh-import-id
- keyboard
{% endif %}
- locale
{% endif %}
- set-passwords
{% if variant in ["rhel"] %}
- rh_subscription
{% endif %}
{% if variant in ["rhel", "fedora", "photon"] %}
{% if variant not in ["photon"] %}
{% if variant not in ["photon", "rhel"] %}
- spacewalk
{% endif %}
- yum-add-repo
Expand All @@ -131,7 +148,7 @@ cloud_config_modules:
{% if variant in ["alpine"] %}
- apk-configure
{% endif %}
{% if variant not in ["freebsd", "netbsd"] %}
{% if variant not in ["freebsd", "netbsd", "rhel" ] %}
- ntp
{% endif %}
- timezone
Expand All @@ -152,22 +169,24 @@ cloud_final_modules:
{% if variant in ["ubuntu", "unknown"] %}
- ubuntu-drivers
{% endif %}
{% if variant not in ["rhel"] %}
- write-files-deferred
- reset_rmc
- refresh_rmc_and_interface
- scripts-vendor
- install-hotplug
{% endif %}
- puppet
- chef
- mcollective
- salt-minion
- reset_rmc
- refresh_rmc_and_interface
- rightscale_userdata
- scripts-vendor
- scripts-per-once
- scripts-per-boot
- scripts-per-instance
- scripts-user
- ssh-authkey-fingerprints
- keys-to-console
- install-hotplug
- phone-home
- final-message
- power-state-change
Expand Down Expand Up @@ -239,6 +258,10 @@ system_info:
name: ec2-user
lock_passwd: True
gecos: EC2 Default User
{% elif variant == "rhel" %}
name: cloud-user
lock_passwd: true
gecos: Cloud User
{% else %}
name: {{ variant }}
lock_passwd: True
Expand All @@ -254,6 +277,8 @@ system_info:
groups: [adm, sudo]
{% elif variant == "arch" %}
groups: [wheel, users]
{% elif variant == "rhel" %}
groups: [adm, systemd-journal]
{% else %}
groups: [wheel, adm, systemd-journal]
{% endif %}
Expand Down
6 changes: 6 additions & 0 deletions systemd/cloud-config.service.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
[Unit]
Description=Apply the settings specified in cloud-config
After=network-online.target cloud-config.target
{% if variant not in ["rhel"] %}
After=snapd.seeded.service
{% endif %}
Wants=network-online.target cloud-config.target
{% if variant == "rhel" %}
ConditionPathExists=!/etc/cloud/cloud-init.disabled
ConditionKernelCommandLine=!cloud-init=disabled
{% endif %}

[Service]
Type=oneshot
Expand Down
13 changes: 13 additions & 0 deletions systemd/cloud-final.service.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ After=multi-user.target
Before=apt-daily.service
{% endif %}
Wants=network-online.target cloud-config.service
{% if variant == "rhel" %}
ConditionPathExists=!/etc/cloud/cloud-init.disabled
ConditionKernelCommandLine=!cloud-init=disabled
{% endif %}


[Service]
Expand All @@ -15,7 +19,16 @@ ExecStart=/usr/bin/cloud-init modules --mode=final
RemainAfterExit=yes
TimeoutSec=0
KillMode=process
{% if variant == "rhel" %}
# Restart NetworkManager if it is present and running.
ExecStartPost=/bin/sh -c 'u=NetworkManager.service; \
out=$(systemctl show --property=SubState $u) || exit; \
[ "$out" = "SubState=running" ] || exit 0; \
systemctl reload-or-try-restart $u'
{% else %}
TasksMax=infinity
{% endif %}


# Output needs to appear in instance console output
StandardOutput=journal+console
Expand Down
25 changes: 24 additions & 1 deletion systemd/cloud-init-local.service.tmpl
Original file line number Diff line number Diff line change
@@ -1,23 +1,46 @@
## template:jinja
[Unit]
Description=Initial cloud-init job (pre-networking)
{% if variant in ["ubuntu", "unknown", "debian"] %}
{% if variant in ["ubuntu", "unknown", "debian", "rhel" ] %}
DefaultDependencies=no
{% endif %}
Wants=network-pre.target
{% if variant not in ["rhel"] %}
After=hv_kvp_daemon.service
{% endif %}
After=systemd-remount-fs.service
{% if variant == "rhel" %}
Requires=dbus.socket
After=dbus.socket
{% endif %}
{% if variant == "rhel" %}
Before=NetworkManager.service network.service
{% else %}
Before=NetworkManager.service
{% endif %}
Before=network-pre.target
Before=shutdown.target
{% if variant == "rhel" %}
Before=firewalld.target
Conflicts=shutdown.target
{% endif %}
{% if variant in ["ubuntu", "unknown", "debian"] %}
Before=sysinit.target
Conflicts=shutdown.target
{% endif %}
RequiresMountsFor=/var/lib/cloud
{% if variant == "rhel" %}
ConditionPathExists=!/etc/cloud/cloud-init.disabled
ConditionKernelCommandLine=!cloud-init=disabled
{% endif %}

[Service]
Type=oneshot
{% if variant == "rhel" %}
ExecStartPre=/bin/mkdir -p /run/cloud-init
ExecStartPre=/sbin/restorecon /run/cloud-init
ExecStartPre=/usr/bin/touch /run/cloud-init/enabled
{% endif %}
ExecStart=/usr/bin/cloud-init init --local
RemainAfterExit=yes
TimeoutSec=0
Expand Down
4 changes: 4 additions & 0 deletions systemd/cloud-init.service.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ Before=shutdown.target
Conflicts=shutdown.target
{% endif %}
Before=systemd-user-sessions.service
{% if variant == "rhel" %}
ConditionPathExists=!/etc/cloud/cloud-init.disabled
ConditionKernelCommandLine=!cloud-init=disabled
{% endif %}

[Service]
Type=oneshot
Expand Down

0 comments on commit 36a1e8b

Please sign in to comment.