Commit Graph
1278 Commits
Author SHA1 Message Date
Joachim Wiberg e4e54a88d9 Adjust boundaries for when conditions are allowed
Not until fs_mount_all() has completed do we have /run, or /var/run, and
never after shutdown has been initiated.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-01-09 09:00:35 +01:00
Joachim Wiberg 308b7c5197 Follow-up to #338: return early if conditions are not available
As pointed out by Jack Newman in issue #338, when conditions are not
available (at boot before cond_init(), or shutdown when /var or /var/run
have been unmounted) we should not try to create any conditions.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-01-09 08:17:09 +01:00
Joachim Wiberg 89772bf6c0 Merge pull request #338 from JackNewman12/shutdown-hook-fix
Fix shutdown hooks not running

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-01-09 08:08:32 +01:00
Joachim Wiberg 988cdf9878 Merge pull request #341 from troglobit/reboot-delay
Add support for optional reboot delay

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-01-09 06:25:45 +01:00
Joachim Wiberg 0147e0e64f Minor, ensure pointer is legit in --enable-static mode
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-01-08 14:18:30 +01:00
Joachim Wiberg 311c6be9aa Add support for optional reboot delay
Slightly different take on issue #334 making it optional, possible to
enable per system.

    reboot-delay <0-60>           # default: 0 (disabled)

When enabled (non-zero), runs after filesystems have been unmounted,
the root filesystems has been remounted read-only, and sync(2) has
been called, twice.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-01-08 09:37:19 +01:00
Joachim Wiberg 5b41c6e327 HOOK_BASEFS_UP must run as soon as all filesystems are mounted
At this hook point the bootmisc.so plugin runs and creates all relevant
system directories.  Much of the rest of system bootstrap relies on this
so it should be called together with the other FS hooks as soon as all
the filesystems have been mounted.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-01-07 15:09:50 +01:00
Joachim Wiberg 4bd81b4d4c conf_saverc: enaure /var/run/finit exists first
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-01-07 15:08:58 +01:00
Joachim Wiberg c29589c2ca initctl: add support for --json to list command
This allows for easy access to the *disabled* services:

    root@anarchy:~# initctl ls --json |jq '.available - .enabled'
    [
      "chronyd.conf",
      "dnsmasq.conf",
      "gdbserver.conf",
      "inadyn.conf",
      "inetd.conf",
      "isisd.conf",
      "lldpd.conf",
      "mstpd.conf",
      "ntpd.conf",
      "ospf6d.conf",
      "ospfd.conf",
      "querierd.conf",
      "ripd.conf",
      "ripng.conf",
      "sshd.conf",
      "syslogd.conf",
      "telnetd.conf",
      "uftpd.conf",
      "wpa_supplicant.conf",
      "zebra.conf"
    ]

As discussed in PR issue #335

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-01-07 14:00:28 +01:00
Joachim Wiberg 73b89430e4 Fix #340: Finit ignores deleted/moved .conf files in /etc/finit.d
Works locally with/without this patch, but I cannot understand why it
would ever be needed in the first place, so removing.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-01-07 14:00:28 +01:00
Joachim Wiberg 2a62fa3d85 Fix #329: add support for multiple args to initctl cond set/clr
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-01-07 14:00:16 +01:00
Joachim Wiberg 4542fdb5bb Fix #339: use absolute path in enabled symlinks
When the /etc/finit.d/enabled directory is a symlink elsehwere, e.g.,
/var/finit.d/enabled, a relative symlink will not work.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-01-07 11:30:46 +01:00
Jack Newman 2a5c319084 Fix shutdown hooks not running
sig.c was calling plugin_run_hooks for the shutdown hooks, but the
shutdown hooks do not have registered callbacks in hook-scripts.c

Instead directly call plugin_script_run()
2023-01-06 10:29:58 +10:00
Jack 612f4fe288 Merge branch 'troglobit:master' into autoreload-fix 2023-01-06 10:00:03 +10:00
Jack Newman c058c05651 Fix AUTO_RELOAD typo 2023-01-05 09:00:51 +10:00
Jack Newman b9e94e4695 Consider a service dirty if the command line args have changed
This fixes `initctl reload` correctly restarting all daemons that have new
command line arguments.

Previously command line arguments changes were only acted upon if the
service was explicitly reloaded `initctl reload myservice`.
2023-01-04 13:31:41 +10:00
Joachim Wiberg 17c69fef3d Fix #185: add devmon support, <dev/foo> condition provider
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-12-18 22:21:15 +01:00
Joachim Wiberg c586204fc1 New API, iwatch_add1() with no preset mask
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-12-18 22:21:15 +01:00
Joachim Wiberg ff5e3219be Optional debug support of actual execve() args
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-12-18 14:43:51 +01:00
Joachim Wiberg 07c52f1566 Improve logging of modified command args, show parsed args as well
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-12-18 14:43:51 +01:00
Joachim Wiberg 0e04ffd68f service_register(): guard against loss of command args
We use strtok() quite extensively in .conf parser.  Parsing of a service
line is split in two, with the command arguments being parsed very late.

Adding a new sub-option parser, based on strtok(), risk losing command
arguments.  Thus, change to use strtok_r() so that we always know where
the arg parser is.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-12-18 14:43:51 +01:00
Joachim Wiberg 8b5435908c Simplify, conds[] need not be static
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-12-17 15:19:08 +01:00
Joachim Wiberg 1d92819d92 Add more progress messages at shutdown/reboot
This patch changes the way progress for unmounting filesystems is
displayed.  To see each filesystem being unmounted Finit now must
be in debug mode.

A general "Unmounting filesystems ..." have been added instead as well
as progress for last hook script and finall call to reboot().

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-12-16 13:27:24 +01:00
Joachim Wiberg 3d9cbaf040 fgetval(): handle extra separators betwee key and value
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-12-06 14:00:31 +01:00
Joachim Wiberg 70c2939596 Fix #315: add environment variables to hook scripts
All hook scripts are called with at least one environment variable set,
FINIT_HOOK_NAME, useful when reusing the same hook script for multiple
hook points.  It is set to the string name, also used by the path, e.g.,
hook/net/up.

For all hook points from hook/sys/shutdown and later, FINIT_SHUTDOWN is
also set, to one of:  halt, poweroff, reboot.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-23 22:51:40 +01:00
Joachim Wiberg 0498326962 Fix #318: only show "[ OK ] Calling foo" progress for runparts ...
For all other run_parts() use-cases we just give the script control over
stdout/stderr to prevent clobbering ANSI color escape codes.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-23 21:49:30 +01:00
Joachim Wiberg c84ababbd4 Fix #317: make sure hook scripts don't run twice
Also fixes #316

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-23 21:44:31 +01:00
Joachim Wiberg 67ea42c87b Reduce debug noise from run_parts() slightly
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-23 21:12:30 +01:00
Joachim Wiberg a2ab45cad7 network: log output from ifup without trailing newline
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-23 21:08:50 +01:00
Joachim Wiberg f3fcca6150 Revert "Refactor, enter main event loop earlier"
This reverts commit 03c08d3970 due to it
breaking handling of bootstrap tasks, causing endless boot loop.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-23 17:54:32 +01:00
Joachim Wiberg 2b65d8f1e9 Follow-up to 9046b6f, don't warn() on empty lines, drop line debug
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-23 17:54:32 +01:00
Joachim Wiberg 7c2abf69c4 Add missing (new) service state strings
Also, reorder to match state enum order.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-23 17:54:32 +01:00
Joachim Wiberg 457c0a246f Fix #320: close API/IPC socket immediately in shutdown/reboot
This protects against any hook scripts or services calling initctl when
we're going down.  There's no way to service these requests anyway, so
no point in keeping the socket open.  This way initctl can check for
the existence of the socket before attempting any IPC command.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-22 08:10:49 +01:00
Joachim Wiberg 68ce78b3fe Fix #319: add missing HOOK_NETWORK_DN
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-21 20:04:32 +01:00
Joachim Wiberg 6bbfc7b1f1 getty: extend issue parser with /etc/os-release support
Add support for /etC/os-release, with fallback to /usr/lib/os-release,
overriding some traditional modifiers with the os-release variant.  The
traditional values for these modifiers are taken from uname, which on
Linux systems are pretty useless since they always return the kernel
name and version instead of the distro/OS values.

E.g., \s becomes PRETTY_NAME instead of 'Linux' and \v becomes the
pretty VERSION, while \r becomes VERSION_ID.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-20 10:44:30 +01:00
Joachim Wiberg 006dd12b09 initctl: recactor, share fgetval() with rest of Finit
Note: this highly useful function should probably migrate to libite.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-20 10:43:30 +01:00
Joachim Wiberg 9046b6fe2b Fix #186: allow continuation character in .conf files
This change makes it possible to use the standard continuation character
in .conf files.  For example:

    service [23456]     \
         log:stderr     \
         <!pid/foo>     \
         bar            \
         -- This is the bar service, it depends on foo # comment that's dropped

Notice the additional support for comments on .conf lines.  If you use
the comment character today you must change to escape it.  Like this:

    service :2 foo -- Foo \#2

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-19 10:11:11 +01:00
Joachim Wiberg f217794773 Fix #314: call cond_update() also when removing all service/foo/*
When removing a whole tree of conditions we need to walk through each
and call cond_update() to ensure that all dependant tasks are stopped
and put back in waiting.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-15 09:24:54 +01:00
Joachim Wiberg 8b9bb1c7ce Fix #314: skip restart if conditions are lost
This change prevents Finit from attempting to continue restarting
crashing services that've lost their conditions.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-15 01:03:10 +01:00
Joachim Wiberg 3b601d0115 Fix issue with services suddenly converting to 'forking' type
When a service starts up the pidfile.so plugin automatically detects any
new pidfiles that show up in the system.  If it finds a matching service
which does not have a custom configured pidfile, it auto-assigns the
detected pidfile to the service.

However, when the user later calls `initctl reload` to update the
running configuration set, Finit service_register() mistakenly will
set the service to forking since it now suddenly has a pidfile ...

The new style way of configuring a forking service is to set the

     type:forking

option.  The old compat way was to set `pid:!/path/to/pidfile`, so
in service_register() we must be very careful not to interpret the
registered pidfile as confiugred by the user -- i.e., check the pid
option.

Bug #313

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-11 16:35:58 +01:00
Joachim Wiberg 1ef9a9f128 Cancel pending restart timer on initctl stop/start/restart/reload
When a service crashes Finit launches a restart timer that periodically
will try restart the service.  If a user calls `initctl stop foo` finit
must cancel this timer callback, otherwise we may end up with a weird
state where Finit thinkgs the service is running, but pid: 0, i.e., not
started.

Note: this fix has been expanded upon from the proof of concept
      submitted by Jack Newman.

Bug #313

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-11 16:34:50 +01:00
Joachim Wiberg 035f06e137 initctl: dump svc type and forking in JSON output
First set of svc_t properties not possible to debug otherwise.  See
issue #313 for a background.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-11 12:11:24 +01:00
Joachim Wiberg 2f91ab5eac Fix #235: support for overriding /etc/finit.conf and /etc/finit.d
This change adds support for a new command line option finit.config=PATH
which can be used to tell Finit to start with /etc/factory.conf instead
of /etc/finit.conf.

For the complete experience a new top-level configuration file directive
`rcsd PATH` has aslo been added.  It in turn can be used by factory.conf
as follows to override /etc/finit.d:

    rcsd /etc/factory.d

Manually verified in myLinux

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-10 17:21:33 +01:00
Joachim Wiberg f6b5b0260b Fix #312: restart services with respawn set, e.g. ttys, immediately
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-09 20:27:16 +01:00
Joachim Wiberg d27f114742 Document new -j,--json output option in initctl
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-09 16:43:11 +01:00
Joachim Wiberg 505c370898 Follow-up to 912a281: let s6 services use oneshot 'ready' condition
Since the s6 readiness notification mechanism closes the notification
socket to Finit (as per s6 spec.) the 'ready' condition should then
always be asserted, even across system reconfiguration events.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-09 14:27:38 +01:00
Joachim Wiberg 8425bc313b initctl: add --json support for condition status and dump
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-09 14:11:46 +01:00
Joachim Wiberg f4d3cf2835 Fix #273: add JSON output option to initctl status [foo]
This change adds support for JSON output to `initctl status` using a
`-j` or `--json` command line option.

Example:

    root@anarchy:~# initctl status -j mdevd
    {
      "identity": "mdevd",
      "description": "MDEVD Extended Hotplug Daemon",
      "status": "crashed",
      "exit": { "code": 100 },
      "origin": "built-in",
      "command": "/bin/mdevd -C -O 4",
      "restarts": 10,
      "pidfile": "/run/mdevd.pid",
      "pid": 0,
      "user": "root",
      "group": "root",
      "uptime": 0,
      "runlevels": [ "S", 1, 2, 3, 4, 5, 7, 8, 9 ]
    }

The excellent tool `jq` can be used to extract certain parts of the
output for further scripting.  E.g. `initctl status -j foo | jq .exit`

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-09 13:49:03 +01:00
Joachim Wiberg bd5cf7c9eb Drop confusing leading / in sig2str() and code2str()
This was added for the benefit of `initctl status foo`, but we have
other users of these functions that don't expect a leading slash.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-08 22:37:13 +01:00
Joachim Wiberg 729002ef82 Fix regression introduced in d810ac0: drop 'return;' statement
The condition subsystem starts very late, this should not affect running
callbacks in plugins.  In d810ac0 an extra return statement was included
in a new if() statement block that run plugins hooks.  This caused a
massive regression in how Finit starts up and runs.

 - drop return; statement that causes regression
 - move #ifdefs to surround if() statement

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-08 21:32:07 +01:00