[CentOS] How rc-local.service works?

Yuri Kanivetsky yuri.kanivetsky at gmail.com
Sun Mar 12 15:18:39 UTC 2017


> It will be run according to the status of the rc-local service - i.e.
what does

>   systemctl status rc-local

> say. It's enabled by default, but it only runs if rc.local is
executable (as defined in the [Unit] section).

When booted with /etc/rc.d/rc.local being not executable, it says:

● rc-local.service - /etc/rc.d/rc.local Compatibility
   Loaded: loaded (/usr/lib/systemd/system/rc-local.service; static;
vendor preset: disabled)
   Active: inactive (dead)

After making it executable:

● rc-local.service - /etc/rc.d/rc.local Compatibility
   Loaded: loaded (/usr/lib/systemd/system/rc-local.service; static;
vendor preset: disabled)
   Active: active (exited) since Sun 2017-03-12 11:08:47 EDT; 10s ago
  Process: 1012 ExecStart=/etc/rc.d/rc.local start (code=exited,
status=0/SUCCESS)

Mar 12 11:08:47 localhost.localdomain systemd[1]: Starting
/etc/rc.d/rc.local Compatibility...
Mar 12 11:08:47 localhost.localdomain systemd[1]: Started
/etc/rc.d/rc.local Compatibility.

But I dug into it more, and it revealed that systemd introduces the
concept of generators:

https://www.freedesktop.org/software/systemd/man/systemd.generator.html

Which are run early in the boot process (before unit files are
processed). And their purpose is to dynamically generate dependencies.
Particularly, rc-local-generator dynamically makes rc-local service a
dependency of multi-user.target if /etc/rc.d/rc.local is executable:

https://github.com/systemd/systemd/blob/v233/src/rc-local-generator/rc-local-generator.c#L89

Regards,
Yuri



More information about the CentOS mailing list