Init Script Overview
--------------------

[Warning: this is preliminary documentation, will be expanded in the future]

Midori Linux uses its own quickinit program, which was inspired by the
util-linux simpleinit program written by Richard Gooch.  It runs init scripts
in parallel, and leaves it to the init scripts to make sure that they run in
the correct order.  To achieve this each init script tells quickinit which
service it needs and the "need" program will block until the services become
available and the script can continue.

There are currently three different directories to store init scripts.

        /etc/init.d        for all init scripts that depend
                           only on code on the root partition

        /usr/init.d        for all init scripts that depend on files
                           in the /usr partition

        /usr/X11R6/init.d  for X related stuff

Init Script Actions
-------------------

Init scripts accept one argument that specifies the action to be taken:

 start
            start the service
 stop
            stop the service
 suspend
            place the service into a low-power suspend mode
            (run before the system enters a low-power suspend mode)
 resume
            restore the service from a low-power suspend mode
            (run after the system leaves a low-power suspend mode)

Dependencies
------------

If a script depends on another service being run, it needs to call 'need' and
the service name.  Example:

        need x || exit 1

will block the script until X becomes available, but should X fail, it will
exit with 1.  You can also say

        need usr thaw

which waits until both services are available (thaw makes the /tmp/config and
/config directory available).

In order to make sure that restarts and shutdowns work correctly, every script
in /usr/init.d must execute a 'need usr', and every script in usr/X11R6/init.d
must execute a 'need x'.  Also: resume and start MUST call the same 'need'
commands for the system to work correctly!  Never try to run 'need' while
stopping or suspending a service!

Init Script Exit Status
-----------------------

Init scripts should exit with a non-zero exit status if the action
failed.  For example if the argument was "start" and the service was
not able to be started.

Init Scripts in Packages
------------------------

By convention you should store your init scripts inside your package in a
directory called 'init.d'.  To install an init script use

        ml_transpose init.d/spawn $ROOT/etc/init.d/spawn 755

ml_transpose allows you to use some of the config file variables in the
script.  Those variables must be written as @VARNAME@.  The complete list of
variables supported by ml_transpose can be found in the mlbuild package in
scripts/functions.sh.  Search for 'ml_transpose'.  Eventually all config file
variables will be supported automatically.

To find examples scripts execute (after running make) from your top midori
tree

        ls cache/build/*/init.d

Example Script
--------------

Here a simple example that spawns some shells (the 'export' and 'set x' makes
sure that on a verbose bootup (controlled by the VERBOSE_SCRIPTS config
variable) you see exactly what this script is doing.  If VERBOSE_SCRIPTS is
set to 'no' that line will be removed).

#!/bin/sh

export PS4="$0: " ; set -x

case "$1" in

  start)
    need mounts || exit 1
    for i in @SPAWN_SHELL@
    do
        spawn /dev/tty$i 0 0 /bin/sh -il &
    done
    ;;

  resume)
    need mounts || exit 1
    ;;

  stop|suspend)
    ;;

esac

exit 0
