/etc/local.d

Article description:: can contain small programs or light scripts to be run when the local service is started or stopped.

Scripts in with the suffix  will be executed at boot time, scripts with suffix  at shutdown time. Scripts should have the execute permission. Files are processed in lexical order.

A word of caution
This system is intended only for very light scripts that will terminate quickly, and are at no risk of hanging, e.g. to write a value to a file in.

The local service is not considered started or stopped until everything is processed, so if there is a or  process which takes some time to run, it can delay - possibly even freeze - boot or shutdown.

This infrastructure should not be used to start other scripts or programs in the background. If the service script is restarted several times, then those scripts or programs will be started in the background several times, possibly resulting in race conditions. A script for terminating background processes started this way would be needed, but may easily fail, e.g. if the  script had been executed several times.

To start a process in the background, write an OpenRC initscript file as described in the OpenRC Initscripts section of the Gentoo Handbook.

Configuration
Here is a script simply as an example of what can be put in. This script will set parameters for the cpu governor, it is a good candidate to be used with the local service as it simply writes to some files in proc and terminates:

Mark the script as executable:

Invocation
The local service will usually be started on boot by adding it to the default runlevel (see the next section), however it can be started explicitly:

If the local service is in the default runlevel, but stopped, it can be started by having OpenRC check for stopped services:

Add local service to default runlevel
To start the scripts at boot time, add it to the default runlevel:

Troubleshooting
By default, the local service will silence all output. Setting rc_verbose=yes will cause it to show which scripts were run and their output, if any: