User Tools

Site Tools


inbox:techref:taskinit_discussion

Hotplug/Init Discussion

The Problem

During OpenWRT boot preinit sets up the initial rootfs and starts init. Init starts tasks in /etc/rc.d (basically ordered /etc/init.d). The first of these scripts that executes is /etc/init.d/boot which sets up some essential things not already done in preinit, including hotplug.

Hotplug is asynchonous. It executes rules in response to events, however some hotplug rules depend on certain things in /etc/rc.d having been executed, but those rules may fire before the needed rc.d script has executed. Furthermore some scripts in /etc/rc.d depend on certain things, like the network, having been setup, however because hotplug is asynchronous there is no guarantee the rules will have fired prior to the script.

A Possible Solution

  1. Initialize everything the [new, improved] hotplug rules need.
  2. For hotplug rules that can be statically initialized this, have them detect this and generated a task that will be executed once the necessary conditions are met.
  3. For init.d scripts that depend on hotplug events (e.g. an interface or set of interfaces having been brought up), move them into tasks that are executed once the necessary conditions are met.

Some developers have discussed achieving this by having relevant hotplug events use a common infrastructure to query a task and see if, with this hotplug event, the task is now ready to execute, and if so to execute it.

[edit] This should also apply to init.d scripts so that tasks generated by hotplug rules can execute when sufficient initialization has been, for rules that couldn't execute prior to this.

Outline

  • We suggest an UCI configuration framework that operates in parallel with the regular UCI configuration files. That is we use a different configuration directory (e.g. /etc/inittask/config) and state (e.g. /var/state/inittask).
  • One task would be defined per UCI section.
  • Each task would define
    • The action to perform when conditions are met
    • The conditions to be met
    • hotplug rules which may affect this task
    • init.d scripts or other tasks which may affect this task
  • A task can have a associated fail task, which, if it's conditions are met before the original task, removes the original task and executes the fail action
  • An action is simply a shell function
  • Conditions are also shell functions
  • We propose to create shell function library for common conditions, and functions commonly needed by the task scripts and the hotplug rules

Shell functions

  • ip2iface, iface2network, ip2network, etc
  • is_up ip|iface|network [ip|iface|network] …
  • is_mounted
  • service_started service
inbox/techref/taskinit_discussion.txt · Last modified: 2010/02/05 12:29 (external edit)