/etc/local.d

From Gentoo Wiki
(Redirected from Local.d)
Jump to: navigation, search

This article describes the setup of scripts in /etc/local.d/ which get executed once during boot or shutdown.

A word of caution

Warning
Any scripts in /etc/local.d/ are meant to execute a few commands (e.g. write some value to some file in /proc/) and terminate.

It is a bad idea to abuse this infrastructure to start any other scripts or programs in the background because:

  • If the /etc/init.d/local service script is restarted several times, those scripts or programs will be executed in the background several times, possibly resulting in race conditions.
  • A
  • .stop script for terminating those processes would have to be also present and may easily fail when e.g. the
  • .start script has been executed several times.

For these reasons, it is much more convenient to write a real OpenRC initscript file as described in the OpenRC Initscripts section of the Gentoo Handbook.

Configuration

All scripts in /etc/local.d/ with the suffix .start will be executed at boot time, all scripts with suffix .stop at shutdown time.

To e.g. output the text Hello world! at boot time, create the new file /etc/local.d/HelloWorld.start:

FILE /etc/local.d/HelloWorld.start
#!/bin/sh
echo "Hello world!"

Afterwards mark the script as executable:

root #chmod +x /etc/local.d/HelloWorld.start

To start the local.d scripts at boot time, add its init.d script to the default runlevel:

root #rc-update add local default

Now start the service by making OpenRC check for stopped services in the default runlevel:

root #rc

Or start it explicitly:

root #rc-service local start

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.

FILE /etc/conf.d/local
rc_verbose=yes