| 1 | Files & Layout |
| 2 | ============== |
| 3 | |
| 4 | Originally Finit was configured using a single file, `/etc/finit.conf`, |
| 5 | and although still possible to use a single configuration file, today |
| 6 | the following layout is recommended: |
| 7 | |
| 8 | / |
| 9 | |- etc/ |
| 10 | | |- finit.d/ |
| 11 | | | |- available/ |
| 12 | | | | `- my-service.conf |
| 13 | | : |- enabled/ |
| 14 | | : | `- my-service.conf -> ../available/my-service.conf |
| 15 | | : : |
| 16 | | : |- static-service.conf |
| 17 | | : `- another-static.conf |
| 18 | | : |
| 19 | | `- finit.conf |
| 20 | |- lib |
| 21 | | `- finit/ |
| 22 | | `- system/ |
| 23 | | |- 10-hotplug.conf |
| 24 | | `- ... |
| 25 | `- run/ |
| 26 | `- finit/ |
| 27 | `- system/ |
| 28 | |- dbus.conf |
| 29 | |- keventd.conf |
| 30 | |- runparts.conf |
| 31 | |- watchdogd.conf |
| 32 | `- ... |
| 33 | |
| 34 | Configuration files in `/etc` are provided by the user, or projects like |
| 35 | [finit-skel](https://github.com/troglobit/finit-skel) and extended by |
| 36 | the user. |
| 37 | |
| 38 | The files in `/lib/finit/system/*.conf` are system critical services and |
| 39 | setup provided by Finit, e.g. udev/mdev that must run very early at system |
| 40 | bootstrap. This system directory was introduced in Finit v4.4 to replace |
| 41 | the hard-coded services provided by plugins before. All .conf files in this |
| 42 | directory be either replaced by a system administrator or overridden by a |
| 43 | file with the same name in `/etc/finit.d/`. |
| 44 | |
| 45 | The files in `/run/finit/system/*.conf` are created by plugins and Finit |
| 46 | bundled services like runparts, [watchdog](../watchdog.md), and |
| 47 | [`keventd`](../keventd.md) if they are enabled. Like |
| 48 | `/lib/finit/system/*.conf`, these files can be overridden by file with |
| 49 | the same name in `/etc/finit.d/`. |
| 50 | |
| 51 | Services in the `available/` and `enabled/` sub-directories are called |
| 52 | dynamic services, in contrast to static services -- the only difference |
| 53 | being where they are installed and if the `initctl` tool can manage them |
| 54 | with the `enable` and `disable` commands. An administrator can always |
| 55 | create files and symlinks manually. |
| 56 | |
| 57 | At bootstrap, and `initctl reload`, all .conf files are read, starting |
| 58 | with `finit.conf`, then `/lib/finit/system/*.conf`, `finit.d/*.conf`, |
| 59 | and finally all `finit.d/enabled/*.conf` files. Each directory is a |
| 60 | unique group, where files within each group are sorted alphabetically. |
| 61 | |
| 62 | **Example:** |
| 63 | |
| 64 | /lib/finit/system/10-hotplug.conf |
| 65 | /lib/finit/system/90-testserv.conf |
| 66 | /run/finit/system/dbus.conf |
| 67 | /run/finit/system/runparts.conf |
| 68 | /etc/finit.d/10-abc.conf |
| 69 | /etc/finit.d/20-abc.conf |
| 70 | /etc/finit.d/enabled/1-aaa.conf |
| 71 | /etc/finit.d/enabled/1-abc.conf |
| 72 | |
| 73 | The resulting combined configuration is read line by line, each `run`, |
| 74 | `task`, and `service` added to an ordered list that ensures they are |
| 75 | started in the same order. This is important because of the blocking |
| 76 | properties of the `run` statement. For an example on the relation of |
| 77 | `service` and `run` statements, and dependency handling between them, |
| 78 | see [Conditional Loading](services.md#conditional-loading), below. |
| 79 | |
| 80 | > [!NOTE] |
| 81 | > The names `finit.conf` and `finit.d/` are only defaults. They can be |
| 82 | > changed at compile-time with two `configure` options: |
| 83 | > `--with-config=/etc/foo.conf` and `--with-rcsd=/var/foo.d`. |
| 84 | > |
| 85 | > They can also be overridden from the [kernel command line](../cmdline.md) |
| 86 | > using: `-- finit.config=/etc/bar.conf` and in that file use the |
| 87 | > top-level configuration directive `rcsd /path/to/finit.d`. |
| 88 | |
| 89 | Filesystem Layout |
| 90 | ----------------- |
| 91 | |
| 92 | Finit is most comfortable with a traditional style Linux filesystem |
| 93 | layout, as specified in the [FHS][]: |
| 94 | |
| 95 | /. |
| 96 | |- bin/ |
| 97 | |- dev/ # Mounted automatically if devtmpfs is available |
| 98 | | |- pts/ # Mounted automatically by Finit if it exists |
| 99 | | `- shm/ # Mounted automatically by Finit if it exists |
| 100 | |- etc/ |
| 101 | | |- finit.d/ |
| 102 | | | |- available/ |
| 103 | | | `- enabled/ |
| 104 | | `- finit.conf |
| 105 | |- home/ |
| 106 | |- lib/ |
| 107 | |- libexec/ |
| 108 | |- mnt/ |
| 109 | |- proc/ # Mounted automatically by Finit if it exists |
| 110 | |- root/ |
| 111 | |- run/ # Mounted automatically by Finit if it exists |
| 112 | | `- lock/ # Created automatically if Finit mounts /run |
| 113 | |- sbin/ |
| 114 | |- sys/ # Mounted automatically by Finit if it exists |
| 115 | |- tmp/ # Mounted automatically by Finit if it exists |
| 116 | |- usr/ |
| 117 | `- var/ |
| 118 | |- cache/ |
| 119 | |- db/ |
| 120 | |- lib/ |
| 121 | | `- misc/ |
| 122 | |- lock/ |
| 123 | |- log/ |
| 124 | |- run -> ../run |
| 125 | |- spool/ |
| 126 | `- tmp/ |
| 127 | |
| 128 | Finit starts by mounting the critical file systems `/dev`, `/proc/`, and |
| 129 | `/sys`, unless they are already mounted. When all plugins and other, |
| 130 | core Finit functions, have been set up, all relevant filesystems (where |
| 131 | `PASS > 0`) are checked and mounted from the selected `fstab`, either |
| 132 | the default `/etc/fstab`, or any custom one selected from the command |
| 133 | line, or at build time. |
| 134 | |
| 135 | To provide a smooth ride, file system not listed in the given `fstab`, |
| 136 | e.g. `/tmp` and `/run`, are automatically mounted by Finit, as listed |
| 137 | above, provided their respective mount point exists. |
| 138 | |
| 139 | With all filesystems mounted, Finit calls `swapon`. |
| 140 | |
| 141 | > [!TIP] |
| 142 | > To see what happens when all filesystems are mounted, have a look at |
| 143 | > the [`bootmisc.so` plugin](../plugins.md). |
| 144 | |
| 145 | At shutdown, and after having stopped all services and other lingering |
| 146 | processes have been killed, filesystems are unmounted in the reverse |
| 147 | order, and `swapoff` is called. |
| 148 | |
| 149 | [FHS]: https://refspecs.linuxfoundation.org/FHS_3.0/fhs/index.html |
| 150 | |
| 151 | Managing Services |
| 152 | ----------------- |
| 153 | |
| 154 | Using `initctl disable my-service` the symlink (above) is removed and |
| 155 | the service is queued for removal. Several changes can be made to the |
| 156 | system, but it is not until `initctl reload` is called that the changes |
| 157 | are activated. |
| 158 | |
| 159 | To add a new static service, drop a `.conf` file in `/etc/finit.d/` and |
| 160 | run `initctl reload`. (It is also possible to `SIGHUP` PID 1, or call |
| 161 | `finit q`, but that has been deprecated with the `initctl` tool). Finit |
| 162 | monitors all known active `.conf` files, so if you want to force a |
| 163 | restart of any service you can touch its corresponding `.conf` file in |
| 164 | `/etc/finit.d` and call `initctl reload`. Finit handles all conditions |
| 165 | and dependencies between services automatically, see the section on |
| 166 | [Service Synchronization](service-sync.md) for more details. |
| 167 | |
| 168 | On `initctl reload` the following is checked for all services: |
| 169 | |
| 170 | - If a service's `.conf` file has been removed, or its conditions are no |
| 171 | longer satisfied, the service is stopped. |
| 172 | - If the file is modified, or a service it depends on has been reloaded, |
| 173 | the service is reloaded (stopped and started). |
| 174 | - If a new service is added it is automatically started — respecting |
| 175 | runlevels and return values from any callbacks. |
| 176 | |
| 177 | For more info on the different states of a service, see the separate |
| 178 | document [Finit Services](../service.md). |
| 179 | |
| 180 | Alternate finit.d/ |
| 181 | ------------------ |
| 182 | |
| 183 | **Syntax:** `rcsd /path/to/finit.d` |
| 184 | |
| 185 | The Finit rcS.d directory is set at compile time with: |
| 186 | |
| 187 | ./configure --with-rcsd=/etc/finit.d |
| 188 | |
| 189 | A system with multiple use-cases may be bootstrapped with different |
| 190 | configurations, starting with the kernel command line option: |
| 191 | |
| 192 | -- finit.config=/etc/factory.conf |
| 193 | |
| 194 | This file in turn can use the `rcsd` directive to tell Finit to use |
| 195 | another set of .conf files, e.g.: |
| 196 | |
| 197 | rcsd /etc/factory.d |
| 198 | |
| 199 | > [!NOTE] |
| 200 | > This directive is only available from the top-level bootstrap .conf |
| 201 | > file, usually `/etc/finit.conf`. |
| 202 | |
| 203 | Including Finit Configs |
| 204 | ------------------------ |
| 205 | |
| 206 | **Syntax:** `include <CONF>` |
| 207 | |
| 208 | Include another configuration file. Absolute path required. |