- Bootstrapping the system after the kernel hands off control
- Starting and supervising services defined in
/etc/init.d/ - Restarting crashed services automatically
- Dispatching hotplug events (USB, network interfaces, etc.)
- Communicating with other system components over ubus
Init Scripts: /etc/init.d/
Each service on the system has an init script in /etc/init.d/. These scripts use the rc.common framework — sourced via the shebang line #!/bin/sh /etc/rc.common — which provides the standard start, stop, restart, enable, and disable actions.
Anatomy of an Init Script
A minimal procd-style init script looks like this:| Variable / Function | Purpose |
|---|---|
START=<n> | Boot priority. Services with lower numbers start first. |
STOP=<n> | Shutdown priority. Lower numbers stop first. |
USE_PROCD=1 | Enables procd-native service management (supervised processes). |
start_service() | Called by procd to launch the service. Uses procd_open_instance / procd_close_instance. |
stop_service() | Called when stopping the service (optional; procd handles SIGTERM by default). |
service_triggers() | Declares which UCI config changes should trigger a service reload. |
reload_service() | Called on reload (if defined); otherwise falls back to restart. |
Boot Script Example: /etc/init.d/boot
The built-in boot script (START=10) runs early in the boot sequence and is responsible for:
- Mounting filesystems (
/proc/mountscheck, OverlayFS) - Creating runtime directories (
/var/lock,/var/run,/tmp/.uci) - Loading kernel modules via
kmodloader - Applying UCI defaults from
/etc/uci-defaults/ - Generating initial network configuration
Boot Order
Theenable command creates symlinks in /etc/rc.d/ with S<priority><name> naming. rcS walks these symlinks in alphanumeric order at boot:
inittab triggers this via:
Service Management Commands
Using init scripts directly
Enable / disable autostart
Using the service command
procd installs a convenience wrapper at /sbin/service:
Inspecting running services via ubus
procd exposes service state over ubus:Hotplug: /etc/hotplug.d/
Hotplug events (such as a network interface coming up or a USB device being inserted) are dispatched by procd to shell scripts in /etc/hotplug.d/. Scripts are organized into subdirectories by event subsystem:
$ACTION set to the event type (e.g., add, remove, ifup, ifdown) and $INTERFACE or $DEVPATH identifying the affected device.