| 1 | Service Synchronization |
| 2 | ======================= |
| 3 | |
| 4 | Finit was created for fast booting systems. Faster than a regular SysV |
| 5 | Init based system at the time. Early on the need for a guaranteed start |
| 6 | order of services (daemons) arose. I.e., service `A` must be guaranteed |
| 7 | to have started (and be ready!) before `B`. The model that was chosen |
| 8 | to determine this was very simple: PID files. |
| 9 | |
| 10 | Early on in UNIX daemons were controlled with basic IPC like signals, |
| 11 | and the way for a user to know that a daemon was ready to respond to |
| 12 | signals (minimally having set up its signal handler), was to tell the |
| 13 | user; |
| 14 | |
| 15 | > "Hey, you can send signals to me using the PID in this file: |
| 16 | > `/var/run/daemon.pid`". |
| 17 | |
| 18 | Since most systems run fairly unchanged after boot, Finit could rely on |
| 19 | the PID file for `A` being created before launching `B`. This method |
| 20 | has worked well for a long time, and for systems based on Open Source it |
| 21 | was easy to either add PID file support to a daemon without support for |
| 22 | it, or fix ordering issues (PID file created before signal handler is |
| 23 | set up) in existing daemons. |
| 24 | |
| 25 | However, with the advent of other Init systems (Finit is rather old), |
| 26 | most notably systemd and s6, other methods for signaling "readiness" |
| 27 | arrived and daemons were adapted to these new schemes to a larger |
| 28 | extent. |
| 29 | |
| 30 | As of Finit v4.4 partial support for systemd and s6 style readiness |
| 31 | notification is available, and the native PID file mode of operation is, |
| 32 | as of Finit v4.6 optional, by default it is still enabled, but this can |
| 33 | be changed in `finit.conf`: |
| 34 | |
| 35 | readiness none |
| 36 | |
| 37 | This will be made the default in Finit 5.0. In this mode of operation, |
| 38 | every service needs to explicitly declare their readiness notification, |
| 39 | like this: |
| 40 | |
| 41 | service notify:pid watchdogd |
| 42 | service notify:systemd foo |
| 43 | service notify:s6 bar |
| 44 | service notify:none qux |
| 45 | |
| 46 | The `notify:none` syntax is for completeness in systems which run in |
| 47 | `readiness pid` mode (default). Services declared with `notify:none` |
| 48 | will transition to ready as soon as Finit has started them, e.g., |
| 49 | `service/qux/ready`. |
| 50 | |
| 51 | To synchronize two services the following condition can be used: |
| 52 | |
| 53 | service notify:pid watchdogd |
| 54 | service <service/watchdogd/ready> stress-ng --cpu 8 |
| 55 | |
| 56 | For details on the syntax and options, see below. |
| 57 | |
| 58 | > [!NOTE] |
| 59 | > On `initctl reload` conditions are set in "flux", while figuring out |
| 60 | > which services to stop, start or restart. Services that need to be |
| 61 | > restarted have their `ready` condition removed before Finit issue a |
| 62 | > SIGHUP (if they support that), or stop-starting them. A daemon is |
| 63 | > expected to reassert its readiness, e.g. systemd style daemons to |
| 64 | > write `READY=1\n`. |
| 65 | > |
| 66 | > However, the s6 notify mode does not support this because in s6 you |
| 67 | > are expected to close your notify descriptor after having written |
| 68 | > `\n`. This means s6 style daemons currently must be stop-started. |
| 69 | > (Declare the service with `<!>` in its condition statement.) |
| 70 | > |
| 71 | > For default, PID file style readiness notification, daemons are |
| 72 | > expected to either create their PID files, or touch it using |
| 73 | > `utimensat()` to reassert readiness. Triggering both the `<pid/>` |
| 74 | > and `<.../ready>` conditions. |