Minit

LNX-BBC 2.0 uses an initscript system called minit. Minit scripts reside in /etc/init.d and function like the initscripts of other GNU/Linux distributions with some notable differences.

Using minit scripts

A minit script in /etc/init.d honors the standard initscript parameters start, stop, restart, and reload. Minit also supports enable, disable, and status parameters.

Disable and enable make it possible to prevent a script from starting and allow a script to start again, respectively. A script which has been disabled will reject any attempt to start it until it has been enabled again. By default, a script is enabled.

The status parameter will show whether a script is currently running, enabled, or neither.

Writing minit scripts

Minit scripts are written in GNU Make. Every minit script starts with this line:

#!/bin/make -sSf

If you are debugging a minit script, you can make it more verbose by shortening it to this:

#!/bin/make -f

In general a minit script starts by setting variables and then includes the minit library, which is contained in the file /etc/init.d/init.mk. If the script needs custom targets, they should go last.

Required and Common variables

The required variables are INITNAME, START_SCRIPTS, and one of either NOSTOP or STOP_SCRIPTS. INITNAME should be set to the name of the script as it will appear in /etc/init.d. START_SCRIPTS and STOP_SCRIPTS provide a list of "scripts" that minit will use to start and stop the service. Scripts for some common tasks are provided by minit and controlled using additional variables. If a script is not stoppable, then it should set the variable NOSTOP. Any value is sufficient.

To declare dependencies, use the NEEDS and WANTS variables. A "needs" dependency is one that is required in order for the script or its service to function, and a "wants" dependency is one that is customarily used in conjunction with the script, but is not strictly necessary. For example, the script for a service which requires certain device nodes which are only available when devfsd is running should list "devfsd" in the value of the NEEDS variable. However, a network server is generally used in conjunction with networking, but may not strictly require it, in which case it should list another script which starts the network in its WANTS variable.

If a service is capable of "reloading" such as a daemon which can reread its configuration file when issued a particular signal, the minit script should set the RELOAD_SCRIPTS variable. In the case of daemons that react to a signal, simply specify the required signal, such as SIGUSR1 or SIGHUP. If a other processing is necessary, the RELOAD_SCRIPTS value may include arbitrary tokens, to which minit will prepend "reload-", and will search for a make target by the resulting name to perform the processing.

Scripts for daemons

The minit library provides scripts capable of starting and stopping most daemons.

Most daemons detach from their controlling terminal either automatically or when invoked with a particular command line option and create a pid file which contains the PID of the daemon. The "daemon" script is capable of starting this type of daemon. It will attempt to start the program specified by the DAEMON variable, which defaults to the value of INITNAME, giving it the parameters specified by the DAEMON_OPTIONS variable, which is empty by default.

For daemons which do not detach from their controlling terminal or create pid files, there is the "nohup" script. It will forcibly detach the daemon from the controlling terminal and create a pid file for it, specified by the PIDFILE variable, which defaults to /var/run/$(INITNAME).pid. The DAEMON and DAEMON_OPTIONS control nohup script the same way as they do the daemon script.

Most daemons stop when they are issued a particular signal, which when trapped, causes the daemon to go through a shutdown sequence and exit cleanly. Minit provides a generalized mechanism for sending any signal to the daemon, provided that there is a pid file. To use this mechanism, specify the signal which will shutdown the daemon, like SIGTERM or SIGHUP. The SIG% script expects to find the PID of the daemon in the file specified by the PIDFILE variable.

Scripts with custom targets

The START_SCRIPTS and STOP_SCRIPTS variables can specify any arbitrary "script" for starting and stopping the service. For minit scripts which must perform some custom processing to start a service, the targets which define those "scripts" must appear in the minit script. Minit will prepend "start-" to each of the entries in the START_SCRIPTS variable and attempt to execute the gmake target by the resulting name. Similarly, it will prepend "stop-" to each of the tokens in STOP_SCRIPTS and look for the resulting names as make targets.