fedora-sysv / initscripts

📜 Scripts to bring up network interfaces and legacy utilities in Fedora.
GNU General Public License v2.0
45 stars 51 forks source link

Why does `service` do not always redirect to `systemctl`? #462

Closed marcosfrm closed 8 months ago

marcosfrm commented 8 months ago

Consider a test init script /etc/rc.d/init.d/AwesomeDaemon. After chkconfig --add AwesomeDaemon we get the generated unit (once fixed: https://github.com/fedora-sysv/chkconfig/pull/117):

$ systemctl status AwesomeDaemon
* AwesomeDaemon.service
     Loaded: loaded (/etc/rc.d/init.d/AwesomeDaemon; generated)
     Active: inactive (dead)
       Docs: man:systemd-sysv-generator(8)

Here is the catch... if I call service AwesomeDaemon start, it does not go through systemd:

$ systemctl status AwesomeDaemon.service
* AwesomeDaemon.service
     Loaded: loaded (/etc/rc.d/init.d/AwesomeDaemon; generated)
     Active: inactive (dead)
       Docs: man:systemd-sysv-generator(8)

The daemon is running, but without systemd supervision. Why is that? Debian's equivalent, invoke-rc.d, calls systemctl <action> <daemon> is this case.

CentOS Stream 9, initscripts-10.11.5-1.el9.x86_64.

lnykryn commented 8 months ago

Unfortunately, we rely on the initscript will source init.d/function There we hijack the script and call systemctl which will tell systemd to actually run the initscript https://github.com/fedora-sysv/initscripts/blob/main/etc/rc.d/init.d/functions#L681

This was done due to reasons already forgotten by history. But one example is that we also wanted to start the initrscripts through systemd if it is called directly. So please source the init.d/functions in your initscript.

marcosfrm commented 8 months ago

Ok, that works. Thank you.