Tie in service and condition documents with README

This is a first effort at cleaning up and consolidating all information
about the new service state machine and how conditions control this
state machine.

Also, clarified and added sections for all documents regarding how
services and conditions relate.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2016-07-14 16:08:44 +02:00
1 parent 6ff9cb2ff3
commit 1c0776b818
3 files changed
+78 -44

No files matched your search

+21 -11
View File
@@ -162,20 +162,27 @@ Syntax:
N is the runlevel number 1-9, where 6 is reserved for reboot. N is the runlevel number 1-9, where 6 is reserved for reboot.
Default is 2. Default is 2.
* `run [LVLS] /path/to/cmd ARGS -- Optional description` * `run [LVLS] <COND> /path/to/cmd ARGS -- Optional description`
One-shot command to run in sequence when entering a runlevel, with One-shot command to run in sequence when entering a runlevel, with
optional arguments and description. This command is guaranteed to be optional arguments and description. This command is guaranteed to be
completed before running the next command. completed before running the next command.
* `task [LVLS] /path/to/cmd ARGS -- Optional description` * `task [LVLS] <COND> /path/to/cmd ARGS -- Optional description`
One-shot like 'run', but starts in parallel with the next command One-shot like 'run', but starts in parallel with the next command
* `service [LVLS] /path/to/daemon ARGS -- Optional description` * `service [LVLS] <COND> /path/to/daemon ARGS -- Optional description`
Service, or daemon, to be monitored and automatically restarted if it Service, or daemon, to be monitored and automatically restarted if it
exits prematurely. Please note that you often need to provide a exits prematurely. Please note that you often need to provide a
`--foreground` or `--no-background` argument to most daemons to `--foreground` or `--no-background` argument to most daemons to
prevent them from forking off a sub-process in the background. prevent them from forking off a sub-process in the background.
```shell
service [2345] <svc/sbin/zebra> /sbin/ospfd -- OSPF daemon
```
For a detailed description of conditions, and how to debug them,
see the [Finit Conditions](doc/conditions.md) document.
* `inetd service/proto[@iflist] <wait|nowait> [LVLS] /path/to/daemon args` * `inetd service/proto[@iflist] <wait|nowait> [LVLS] /path/to/daemon args`
Launch a daemon when a client initiates a connection on an Internet Launch a daemon when a client initiates a connection on an Internet
port. Available services are listed in the UNIX `/etc/services` file. port. Available services are listed in the UNIX `/etc/services` file.
@@ -227,7 +234,7 @@ Syntax:
sure to call the configure script with `--enable-embedded` if this sure to call the configure script with `--enable-embedded` if this
is what you want. is what you want.
* `console <DEV | /path/to/cmd [args]>` * `console <DEV | /path/to/cmd [args]`
Some embedded systems have a dedicated serial console/service port. Some embedded systems have a dedicated serial console/service port.
This command tells finit to not start getty directly, since there may This command tells finit to not start getty directly, since there may
not be anyone there. To save RAM and CPU finit instead displays a not be anyone there. To save RAM and CPU finit instead displays a
@@ -284,15 +291,18 @@ call `finit q`, but that has been deprecated with the `initctl` tool).
Any service read from this directory is flagged as a dynamic service, so Any service read from this directory is flagged as a dynamic service, so
changes to or removal of `/etc/finit.d/*.conf` files, is detected. changes to or removal of `/etc/finit.d/*.conf` files, is detected.
- If a service's `.conf` file has been removed, the service is stopped. On `initctl reload` the following is checked for all services:
- If the file is modified, the service is reloaded, stopped and started.
- If service 1 is reloaded, and service 2 depends on service 1, then - If a service's `.conf` file has been removed, or its conditions are no
service 2 will also be reloaded. Note: service dependencies must be longer satisifed, the service is stopped.
declared for each service for this to work. For more info on this, - If the file is modified, or a service it depends on has been reloaded,
see the separate document [Finit Conditions](doc/conditions.md). the service is reloaded (stopped and started).
- If a new service is added it is automatically started — respecting - If a new service is added it is automatically started — respecting
runlevels and return values from any callbacks. runlevels and return values from any callbacks.
For more info on the different states of a service, see the separate
document [Finit Services](doc/service.md).
The `/etc/finit.d` directory was previously the default Finit `runparts` The `/etc/finit.d` directory was previously the default Finit `runparts`
directory. Finit no longer has a default `runparts`, so make sure to directory. Finit no longer has a default `runparts`, so make sure to
update your setup, or the finit configuration, accordingly. update your setup, or the finit configuration, accordingly.
@@ -840,7 +850,7 @@ The default install does not setup finit as the system default
`/sbin/init`, neither does it setup an initial `/etc/finit.conf`. `/sbin/init`, neither does it setup an initial `/etc/finit.conf`.
It is assumed that users of finit are competent enough to either setup It is assumed that users of finit are competent enough to either setup
finit as their default `/sbin/init` or alter their respective Grub, finit as their default `/sbin/init` or alter their respective GRUB,
LOADLIN, LILO, U-Boot/Barebox or RedBoot boot loader configuration to LOADLIN, LILO, U-Boot/Barebox or RedBoot boot loader configuration to
give the kernel the following extra command line: give the kernel the following extra command line:
+37 -18
View File
@@ -1,7 +1,7 @@
Finit Conditions Finit Conditions
================ ================
![Condition state machine](../images/cond-statem.jpg "Condition state machine") ![The service state machine](svc-machine.png "The service state machine")
Table of Contents Table of Contents
@@ -17,11 +17,12 @@ Table of Contents
Introduction Introduction
------------ ------------
In addition to runlevels, services can declare user-defined conditions In addition to declaring allowed runlevels per service, it is also
as dependencies. Conditions are specified within angle brackets (<>) in possible to declare user-defined conditions as dependencies. Conditions
the service stanza. Multiple conditions may be specified separated by are specified within angle brackets (<>) in the service stanza.
comma. Conditions are AND'ed during evaluation, i.e. all conditions Multiple conditions may be specified separated by comma. Conditions are
must be satisfied in order for a service to run. AND'ed during evaluation, i.e. all conditions must be satisfied in order
for a service to run.
**Example:** **Example:**
@@ -39,8 +40,8 @@ service's pidfile being created.
Triggering Triggering
---------- ----------
Conditions are triggered by using the `emit` command of the `initctl` Conditions are triggered either by plugins or by using the `emit`
control tool. command of the `initctl` control tool.
* `initctl emit +your/cond/here` * `initctl emit +your/cond/here`
@@ -61,20 +62,38 @@ new (or possibly unchanged) state of it.
Built-in Conditions Built-in Conditions
------------------- -------------------
Finit is distributed with the `pidfile`-plugin. If enabled, it will Finit is distributed with a `pidfile` and `netlink` plugin. If enabled,
watch `/var/run/` for pidfiles created by services that it controls the `pidfile` plugin watches `/var/run/` for PID files created by
and set a corresponding condition in the `svc/` namespace. monitored services, and sets a corresponding condition in the `svc/`
namespace. Similarily, the `netlink` plugin provides basic conditions
for when an interface is brought up/down and when a default route
(gateway) is set.
For example, if Finit starts the `/sbin/netd` daemon and it creates the With the example listed above, finit does not start the `/sbin/netd`
file `/var/run/netd.pid`, the condition `svc/sbin/netd` is satisfied. daemon until `setupd` and `zebra` has started *and* created their PID
If the file is removed, the condition is cleared. files. Which they do when they completed their main tasks of setting up
VLANs, bridge, interfaces, etc. When `netd` in turn starts up it
creates the file `/var/run/netd.pid`, and the condition `svc/sbin/netd`
is satisfied. When the file is removed, the condition is cleared.
The full path to the dependency is needed by finit to match the PID file
to a monitored process.
Built-in conditions:
- `svc/<PATH>`
- `net/route/default`
- `net/<IFNAME>/exist`
- `net/<IFNAME>/up`
Note: `up` is administratively up, `IFF_UP`, not link up, `IFF_RUNNING`.
Debugging Debugging
--------- ---------
If a service is not being started as it should, the problem might be If a service is not being started as it should, the problem might be
that one of its conditions are not in the expected state. Use the that one of its conditions is not in the expected state. Use the
command `initctl status` to inspect service status. Services in the command `initctl status` to inspect service status. Services in the
`ready` state are pending a condition. `ready` state are pending a condition.
@@ -102,9 +121,9 @@ Internals
A condition is always in one of three states: A condition is always in one of three states:
* `on`: The condition is asserted. * `on` (+): The condition is asserted.
* `off`: The condition is deasserted. * `off` (-): The condition is deasserted.
* `flux`: The conditions state is unknown. * `flux` (~): The conditions state is unknown.
All conditions that have not explicitly been set are interpreted as All conditions that have not explicitly been set are interpreted as
being in the `off` state. being in the `off` state.
+20 -15
View File
@@ -1,29 +1,34 @@
# Services Finit Services
==============
## State Machine ![The service state machine](svc-machine.png "The service state machine")
![A service's state machine](svc-machine.png "A service's state machine") State Machine
-------------
A service is bound to a state machine that is in one of six (6) A service is bound to a state machine that is in one of six (6) states.
states. For `run`s and `task`s there is an additional end state called For `run`s and `task`s there is an additional end state called `DONE`,
`DONE`, not shown in the diagram for brevity. All services start in not shown in the diagram for brevity. Services start in the `HALTED`
the `HALTED` state. state.
The current state depends on the two following conditions: The current state depends on the two following conditions:
* `E`: Service enabled. In order for `E` to be satisfied, the service * `E`: Service enabled. In order for `E` to be satisfied, the service
must be allowed to run in the current runlevel and must not be must be allowed to run in the current runlevel and must not be
blocked. A service may be blocked for several reasons: blocked. A service may be blocked for several reasons:
- The user has manually stopped the service using `initctl stop
JOB`.
- The binary repeatedly dies after being started. I.e. keeps
crashing.
- The user has manually stopped the service using `initctl stop JOB`
- The binary repeatedly dies after being started. I.e. keeps crashing.
- The binary is missing in the filesystem. - The binary is missing in the filesystem.
* `C`: Service conditions are satisfied. * `C`: Service conditions are satisfied:
- `on` (+): The condition is asserted.
- `off` (-): The condition is deasserted.
- `flux` (~): The conditions state is unknown.
For a detailed description of conditions, and how to debug them,
see the [Finit Conditions](conditions.md) document.
<!-- <!--
-- Local Variables: -- Local Variables: