Commit Graph
3192 Commits
Author SHA1 Message Date
Joachim Wiberg 726f7ba229 test: new regression test for bug #313
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-11 15:53:48 +01:00
Joachim Wiberg 61dab8bd75 test: add support for new helper functions, skip/fail/check_dep
Also, make sure to exit each test with the correct exit status.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-11 15:52:37 +01:00
Joachim Wiberg a7e81f45c6 test: slay must cache oldpid to an instance specific ramdisk
Running tests in massive parallel causes failing startk-kill-service.sh.
This in turn was caused by the shared test tool 'slay' that cached its
"oldpid" file to a shared area of the rootfs (tenv-root).  It must use a
test instance-specific ramdisk.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-11 12:38:14 +01:00
Joachim Wiberg be4062f019 test: log service.sh output to stderr
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-11 12:37:57 +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 bb9bd7e0b0 Fix #311: document how to combine device tree with conditions
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-09 18:20:57 +01:00
Joachim Wiberg 287abd5c7c Fix #254: document limitations in rc.local and runparts
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-09 18:05:21 +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 f26009ec3e Follow-up to 912a281: reassert 'ready' condition on reload
Services that have not been changed, or otherwise needed to be reloaded,
need to have their 'ready' condition reasserted on 'initctl reload',
otherwise it will remain in 'flux'.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-09 14:25:49 +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 4709394ae6 .github: bump actions to fix Node.js 12 warnings
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-08 21:49:17 +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
Joachim Wiberg 58b075dbf2 Follow-up to 7cfbca6, remove extra , that disables all plugins
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-08 19:49:23 +01:00
Joachim Wiberg d679840fa3 m4: minor, whistespace cleanup
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-08 19:48:56 +01:00
Joachim Wiberg 0e70bdbf6a Handle if building with hook script but no script path
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-07 19:04:59 +01:00
Joachim Wiberg d810ac00bc Fix #302: add support for running scripts at shutdown
This change adds support for running hook scripts at two new hook points
during the shutdown process:

 - HOOK_SVC_DN: after all services and non-reserved processes have been
   killed (and collected)
 - HOOK_SYS_DN: after all file systems have been unmounted, *just prior*
   to Finit calling reboot() to shut down or reboot the system

See doc/plugins.md for details and an example.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-07 07:01:21 +01:00
Joachim Wiberg 5f74adad06 Take down condition subsystem at shutdown/reboot
Leave the system as it was when we found it.  Also, we'll build things
on top of cond_is_available() to handle pre bootstrap and pre shutdown
tasks.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-07 06:44:21 +01:00
Joachim Wiberg 585ac51f45 Refactor local helper function, change readdir() to recursive nftw()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-07 06:43:02 +01:00
Joachim Wiberg ce36797506 doc: update documentation for hook-scripts and all hook points
Follow-up to b62c975.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-06 14:46:17 +01:00
Joachim Wiberg a61c2ceb79 Fix #310: service restart delay not working
Always use the configured restart delay for crashing services.  If no
delay is configured, we default to an initial 2000 msec for forking
daemons and start-stop scripts, and 1 msec for non-forking daemons.

We must track the increasing delay in the svc_t because processes can
fail quickly in differing ways.  E.g, the test daemon 'serv' behaves
extra evil by crashing right after having created its pidile (i.e.,
when it's signaled to Finit it is 'ready' and all is dandy ...).  If
we don't track the delay per svc_t we would restart 'serv' after only
1 msec every (other) time.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-06 13:54:56 +01:00
Joachim Wiberg 383339dc4a Add timestamp to log messages when in fallback and logging to stderr
When there is no log daemon, and we are running in a container, or we
cannot log to the kernel ring buffer, then we log to stderr.  This patch
improves the log output by prefixing each message with a timestamp.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-06 13:54:55 +01:00
Joachim Wiberg 36b46ba134 Improve and increase debug messages for dying services and scripts
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-06 13:54:55 +01:00
Joachim Wiberg a2d0859bf1 test: serv: die immediately (no sleep) if started with -c
We want to stress test Finit as much as possible.  We add a small log
though (which admittedly gives us a little bit of a delay) just to see
what happens when debugging failing tests.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-06 13:54:55 +01:00
Joachim Wiberg d5f542dcca test: slay must wait up to five seconds before giving up
Default max delay before restarting a crashing service is five seconds.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-06 13:54:55 +01:00
Joachim Wiberg fb86042cb3 test: add crashing.sh, verify oncrash:script support
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-06 13:07:10 +01:00
Joachim Wiberg 359fb8530e Minor, spelling
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-06 13:07:10 +01:00
Joachim Wiberg 5dd1a676ac Fix #282: add support for oncrash:script to call post:script action
This patch adds the oncrash:script option to call the post:script
action, if defined, for a crashing service.  The EXIT_CODE variable
sent to the script is set to `crashed`.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-06 13:07:10 +01:00
Joachim Wiberg 278994781b Follow-up to c9f1bff, only allow daemons to reach 'READY' state
By definition, the readiness notification is reserved for daemons.  May
possibly be extended also to sysv services later.  If you arrive hare
with that request, please file an issue with the project.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-10-16 23:52:32 +02:00
Joachim Wiberg c9f1bff419 Refactor ready:script to support new notify framework
Follow-up to abcb3ce, calling the service ready:script when readiness
has been signaled to or detected by Finit.

Issue #300

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-10-16 22:11:12 +02:00
Joachim Wiberg 1f9621cf4b Fix #288: enable built-in sulogin in Alpine and Void Linux builds
Always better to have at least one sulogin available, if the system
provided sulogin isn't available we fall back to the built-in one.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-10-16 21:08:44 +02:00
Joachim Wiberg 9458e4e66b Update docs with new readiness notification support
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-10-16 20:36:15 +02:00
Joachim Wiberg ff08038bdc test: add notify.sh to distribution
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-10-16 20:13:04 +02:00
Joachim Wiberg ce330e8bf1 Minor, whitespace
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-10-16 20:12:12 +02:00
Joachim Wiberg 47d837bf6a test: new test, notify.sh, systemd and s6 readiness notification
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-10-16 20:06:26 +02:00
Joachim Wiberg 912a281ee2 Fix #299: add support for service readiness notification
This patch adds service readiness notification to support daemons
employing systemd and s6 notification.  Complementing the native
Finit readiness support using PID files that exist already.

The two have slightly different ways of implementing readiness:

 - https://www.freedesktop.org/software/systemd/man/sd_notify.html
 - https://skarnet.org/software/s6/notifywhenup.html

Finit now provides both a NOTIFY_SOCKET environemnt variable, for
systemd, and a way to start s6 daemons with a descriptor argument.

For details on the syntax, see the `service` documentation.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-10-16 20:06:26 +02:00
Joachim Wiberg 6e863a7872 client_connect(): ensure socket is also reset to -1 on error
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-10-16 20:01:29 +02:00
Joachim Wiberg 488e6c2adf Follow-up to d82d1197: ensure PID file doesn't exist
Before we clear all conditions for a service, ensure pid_file_read()
didn't fail due to the PID file not (yet) containing a valid number.

If the process dies while starting up, and subsequently removes its
PID file, then the file shouldn't exist.  However, if we get inotify
before the process has finished writing the PID, then we just return
and wait for the next event.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-10-16 20:01:29 +02:00
Joachim Wiberg e177b866a9 initctl: follow-up to e1c59a25, simplify
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-10-16 20:01:29 +02:00
Joachim Wiberg 15dcebd0f1 .globalrc: skip tenv-root/ in gtags indexing
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-10-16 20:01:29 +02:00
Joachim Wiberg af60d8d3ec initctl: fix off-by-one in column width when dumping conditions
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-10-16 20:01:29 +02:00
Joachim Wiberg 5a32fdb309 Simplify error message, same style as other log messages in module
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-10-16 20:01:29 +02:00
Joachim Wiberg 19f5cb1d01 logit: fall back to package name if $LOGNAME and $USER are unset
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-10-16 20:01:29 +02:00
Joachim Wiberg c5bca5f80a Add 'function():' prefix to new log macros, like the old ones
Also, mark old log macros as DEPRECATED.  Will be removed in a later release.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-10-09 12:52:49 +02:00
Joachim Wiberg d22dea74e3 Finalize refactor to new log macros, following-up to 37e3be9
This possible also mitigates the issue tracked in #307.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-10-09 12:52:40 +02:00
Joachim Wiberg dc547317c9 .github: drop setup-root.log from failed builds, no longer a test
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-09-25 11:45:27 +02:00