How Rc-local.service Works?
Hi,
Let me cite the service file here:
[Unit]
Description=/etc/rc.d/rc.local Compatibility ConditionFileIsExecutable=/etc/rc.d/rc.local After=network.target
[Service]
Type=forking ExecStart=/etc/rc.d/rc.local start TimeoutSec=0
RemainAfterExit=yes
I basically don’t understand two things here:
1. What makes it run? Sure, when I make /etc/rc.d/rc.local executable, it runs. But for all I know, for it to run some other service must pull in it as a dependency. Am I wrong?
2. Why Type=forking?
Thanks in advance.
Regards, Yuri
2 thoughts on - How Rc-local.service Works?
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).
Err, because it forks! (i.e. it can leave processes running after the script has finished executing.)
P.
what does
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