j8r / dockerfiles

Repository for my dockerfiles
https://hub.docker.com/u/jrei
ISC License
123 stars 46 forks source link

Ensure /sbin/init is a symlink to systemd #8

Closed jimeh closed 4 years ago

jimeh commented 4 years ago

The systemd-sysv package does not get installed along with systemd on some versions of Debian (9, 11) and Ubuntu (20.04). This simply brings those images in line with the others, and ensures /sbin/init is a symlink to systemd.

Looking at /sbin/init and where it symlinks to is one way to determine what init-system is used. Ansible's service_mgr module for example does just that:

https://github.com/ansible/ansible/blob/3acd8f6f7f61b72a42a017060c3a718bbbeaf854/lib/ansible/module_utils/facts/system/service_mgr.py#L61

j8r commented 4 years ago

Thanks @jimeh , sorry not to have responded earlier! Several questions:

j8r commented 4 years ago

Sorry, what is the issue by not having /sbin/init?

jimeh commented 4 years ago

@j8r sorry for the rather lacking explanation. I ran into issues when using your various systemd images in the test suite of my ansible-adguardhome role. I ended doing a similar hack here as to what I had originally submitted in this PR.

Without it Ansible's service_mgr module kept not correctly detecting the init system as being systemd.

And having a look now, I noticed that installing the systemd-sysv package creates the /sbin/init symlink, so I've rebased the PR and modified it to do that instead of manually creating the symlink :)

j8r commented 4 years ago

Great @jimeh , looks good to me! Is it possible to have also this fix on other Debian and Ubuntu images. They have likely this same issue, with the same easy fix to do :).

jimeh commented 4 years ago

I've just had a deeper look, and it seems to affect Debian 9 and 11, and Ubuntu 20.04. So I'm happy to do the same change against those images, or just do it against all debian/ubuntu images, as the others already have the systemd-sysv package installed, it shouldn't cause any harm :)

What do you prefer?

j8r commented 4 years ago

Ok, let's have it everywhere then :+1: It can also be useful when using legacy sysVinit scripts.

jimeh commented 4 years ago

All done :)

j8r commented 4 years ago

Love it, thank you @jimeh !

jimeh commented 4 years ago

No worries, I'm happy to help. And thank you for building these images in the first place. Without them I would have needed to build similar images myself to be able to test that my Ansible role can actually configure and run a systemd services :)