Skip to content

Init Scripts

Calin Crisan edited this page Dec 27, 2019 · 11 revisions

Naming

Init scripts are simple shell scripts that live in /etc/init.d. There's no dependency management, they are just run in alphabetical order. Naming of these scripts is therefore, important.

The scripts have the following naming convention:

S<XY><service_name>

S is a fixed letter, XY is a number of two digits (from 00 to 99) that dictates the order and service_name is the name given to the service. For example, S35wifi will start the WiFi service before S43firewall will start the firewall.

Internal Commands

Init scripts work with a command line argument, which represents the internal command supplied to the script. The following commands are supported by most scripts:

* `start` - mandatory for all init scripts, starts the corresponding service
* `stop` - supported by most init scripts, stops the corresponding service
* `restart` - supported by init scripts that have a `stop` command, internally runs a `stop` followed by a `start`
* `reload` - supported by some init scripts, tries to reload the service configuration without a full restart

Running an init script without arguments should simply print its usage, along with supported commands.

At startup, /etc/init.d/rcS runs each of these scripts in order, with the start command. At shutdown, /etc/init.d/rcK runs each of these scripts in reverse order, with the stop command. See Boot Process for more details.

Automatic Functionality Detection

A thingOS system can include a relatively large number of init scripts. Some of them may however not be used due to the fact that their underlying functionality has not been configured. For example, S35wifi won't do anything unless there's a configured WiFi network in wpa_supplicant.conf.

Init scripts whose functionality is optional will check for a proper configuration at their beginning and will silently exit unless they find one. This allows shipping an OS with many optional services, allowing the user to configure them individually, as per their needs.

Manual Control

Init scripts can be manually run using commands such as /etc.init.d/<script> restart. There is however a more convenient way to control them, using the service helper command. For example, restarting the WiFi service can be done running:

service wifi restart

User Disabled Scripts

Given the purpose of thingOS, users probably shouldn't manually disable scripts on their systems. If however one wants a script to be disabled on a particular setup, the presence of a simple, empty file called /data/etc/no_<script> will prevent the automatic init script execution. For example, the presence of the following file will prevent the WiFi service from starting at boot:

/data/etc/no_S35wifi

Writing An Init Script

Needles to say that init scripts must be executable.

Clone this wiki locally