CentOS 7 should be treated like RHEL 7 in dist/rhel.py

Bug #1411829 reported by Lars Kellogg-Stedman
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cloud-init
Fix Released
Undecided
Unassigned

Bug Description

cloudinit/dists/rhel.py contains the follow code to determine if systemd is in use:

    def uses_systemd(self):
        # Fedora 18 and RHEL 7 were the first adopters in their series
        (dist, vers) = util.system_info()['dist'][:2]
        major = (int)(vers.split('.')[0])
        return ((dist.startswith('Red Hat Enterprise Linux') and major >= 7)
                or (dist.startswith('Fedora') and major >= 18))

This will not produce the correct behavior on CentOS 7, Scientific LInux 7, or any other RHEL-based distribution. Among other issues, this will prevent cloud-init from setting the system hostname correctly. Because these distributions are treated like RHEL6 and earlier, cloud-init writes the persistent hostname into /etc/sysconfig/network, but the hostname is not read from this file when the system boots.

I propose that we replace uses_systemd with the following:

    def uses_systemd(self):
        return os.path.isfile('/usr/bin/systemctl')

Revision history for this message
Lars Kellogg-Stedman (larsks) wrote :

The attach patch replaces the distribution-name heuristics in uses_systemd with a check for the systemctl binary.

Revision history for this message
Ben Howard (darkmuggle-deactivatedaccount) wrote : Re: [Bug 1411829] Re: CentOS 7 should be treated like RHEL 7 in dist/rhel.py

On Fri, Jan 16, 2015 at 09:13:58PM -0000, Lars Kellogg-Stedman wrote:
> The attach patch replaces the distribution-name heuristics in
> uses_systemd with a check for the systemctl binary.
>
> ** Patch added: "0001-fix-check-for-systemd.patch"
> https://bugs.launchpad.net/cloud-init/+bug/1411829/+attachment/4300219/+files/0001-fix-check-for-systemd.patch
>
> --
> You received this bug notification because you are a member of Canonical
> Cloudware, which is subscribed to cloud-init.
> Matching subscriptions: cloud-init bugs
> https://bugs.launchpad.net/bugs/1411829
>
> Title:
> CentOS 7 should be treated like RHEL 7 in dist/rhel.py
>
> Status in Init scripts for use on cloud images:
> New
>
> Bug description:
> cloudinit/dists/rhel.py contains the follow code to determine if
> systemd is in use:
>
> def uses_systemd(self):
> # Fedora 18 and RHEL 7 were the first adopters in their series
> (dist, vers) = util.system_info()['dist'][:2]
> major = (int)(vers.split('.')[0])
> return ((dist.startswith('Red Hat Enterprise Linux') and major >= 7)
> or (dist.startswith('Fedora') and major >= 18))
>
>
> This will not produce the correct behavior on CentOS 7, Scientific LInux 7, or any other RHEL-based distribution. Among other issues, this will prevent cloud-init from setting the system hostname correctly. Because these distributions are treated like RHEL6 and earlier, cloud-init writes the persistent hostname into /etc/sysconfig/network, but the hostname is not read from this file when the system boots.
>
> I propose that we replace uses_systemd with the following:
>
> def uses_systemd(self):
> return os.path.isfile('/usr/bin/systemctl')

It might make sense to figure out if systemd is really running. There are
cases where you could have different init systems running:

    def uses_systemd(self):
        return 'systemctl' in os.readlink('/proc/1/exe')

>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/cloud-init/+bug/1411829/+subscriptions
>

Revision history for this message
Lars Kellogg-Stedman (larsks) wrote :

I guess the "correct" way of doing it would be to use the "booted" method of "systemd.daemon":

    import systemd.daemon
    if systemd.daemon.booted():
        print 'using systemd'

...which, it turns out, is really just calling lstat("/run/systemd/system"). So I guess that would in fact be the correct test:

    if os.path.isdir('/run/systemd/system'):
        print 'using systemd'

For reference:

https://github.com/systemd/systemd/blob/master/src/libsystemd/sd-daemon/sd-daemon.c#L510

Revision history for this message
Lars Kellogg-Stedman (larsks) wrote :

This patch modifies uses_systemd() to mimic the behavior of systemd's own sd_booted() function. This is much more robust than trying to chase distribution/version information.

Revision history for this message
Joshua Powers (powersj) wrote :

I believe this should be marked as fixed as the uses_systemd function was updated previous:

https://github.com/cloud-init/cloud-init/blob/master/cloudinit/distros/__init__.py#L100

Changed in cloud-init:
status: New → Fix Released
Revision history for this message
James Falcon (falcojr) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.