[CentOS] doing something before everything else

Sat Jul 22 13:06:05 UTC 2017
Jonathan Billings <billings at negate.org>

On Jul 22, 2017, at 8:28 AM, Andrew Holway <andrew.holway at gmail.com> wrote:
> I want to run a script before systemd starts doing stuff but I cant find
> anything online about how that could happen. It seems /etc/rc.local is
> depreciated now?

You can’t run anything before systemd starts, since it is started by the kernel before the local filesystems have been mounted.

/etc/rc.d/rc.local still runs, but it is a systemd service run as rc-local.service, contingent on /etc/rc.d/rc.local existing and being executable.

Now, if you want to run something before systemd starts other services, you need to create your own systemd unit, and set up dependencies such that the service starts before those services.  For example, you’d put "Before=network-pre.target” in the [Unit] section if you wanted your service to start before the network was brought up.  For what it’s worth, rc-local.service has a dependency that actually starts it *after* the network service comes up, so it starts later in the startup anyway.


--
Jonathan Billings <billings at negate.org>