Commit Graph
2195 Commits
Author SHA1 Message Date
Joachim Wiberg 2bfede2cfe Add /lib/finit/sample.conf for initctl create
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 10:26:39 +01:00
Joachim Wiberg 544180aa0b contrib: update example configs
- check command removed
- disable modules by default (void)
- OpenSSH requires absolute path (void)
- Read keymap from env (alpine)
- minor cleanup/reordering for consistency

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 10:23:15 +01:00
Joachim Wiberg 6862d7cd5f Refactor --with-sysconfig, default to /etc/default and /etc/conf.d
Both Debian and Builroot based systems use /etc/default and
Alpine Linux use /etc/conf.d, so let's just put both in by
default.  If the directories exist we monitor them.

The --with-syconfig configure option is now disabled by default.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 09:53:48 +01:00
Joachim Wiberg 7e3b18a38d Refactor install/uninstall of rescue.conf
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 09:34:36 +01:00
Joachim Wiberg 70c884816e doc: update config.md, no more limitations
Also, mark some settings as bootstrap only.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 09:24:04 +01:00
Joachim Wiberg f8c07e81ff Reclassify module as BOOTSTRAP only, including minor refactor
The module setting is deprecated, other mechanisms exist.  This change
is to ensure we don't try to (re)load any modules at runtime, only at
bootstrap.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 09:24:04 +01:00
Joachim Wiberg 270512bc97 Refactor, collapse parse_conf() and parse_conf_dynamic()
This patch collapses the two similar functions parse_conf() and
parse_conf_dynamic() into a single function.  It also lifts old
restrictions on what config stanzas are allowed in /etc/finit.d

The only remaining restriction is the global rlimits, they remain
as the last setting only possible to define /etc/finit.conf which
then applies to all other services.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 08:38:41 +01:00
Joachim Wiberg c001349dd3 Wrapper for init q and init -t sec 0, used by sysvnit shutdown
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 07:54:16 +01:00
Joachim Wiberg 510bd1ac0b initctl: if edit cannot find the file, list available ones
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-27 20:13:57 +01:00
Joachim Wiberg 0d52583624 initctl: return correct path if -c is given
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-27 20:13:32 +01:00
Joachim Wiberg aa998583a7 Update example ASCII graphic a bit, add log and env commands
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-27 19:29:38 +01:00
Joachim Wiberg f9532d11ba initctl: only show enable/disable commands on compat systems
The enable/disable commands require either both the available/ and
enabled/ subdirectories in /etc/finit.d, or at least available/

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-27 19:27:58 +01:00
Joachim Wiberg c7d189f199 initctl: refactor list command slightly
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-27 19:27:22 +01:00
Joachim Wiberg 83cdb884d9 initctl: extend semantics for enable/disable cmd
A system may, or may not, have the available/ and enabled/
subdirectories in /etc/finit.d.  This is up to distros but
we support the following, example uses /etc/finit.d as the
FINIT_RCSD base directory:

 1. No subdirectories
    - enable: nop
    - disable: nop
 2. Only available/
    - enable: checks if there's a service in available/
      then symlinks to /etc/finit.d/
    - disable: checks if service in /etc/finit.d is a
      symlink, then removes it
 3. Both available/ and enabled/
    - enable: relative symlink in enabled/ is created if
      service is available in available/
    - disable: symlink in enabled/ is removed if exists

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-27 19:22:50 +01:00
Joachim Wiberg e9ed90cb34 initctl: let touch command handle both rcsd and available dirs
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-27 19:22:16 +01:00
Joachim Wiberg 689e6cd52a initctl: add -c create flag, to force creation at edit
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-27 19:21:18 +01:00
Joachim Wiberg 2fd4418371 initctl: add support for reading config to 'create' from stdin
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-27 17:02:37 +01:00
Joachim Wiberg 01cd9ec358 contrib: debian: rsyslogd provides syslogd cond
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 16:42:43 +01:00
Joachim Wiberg 6d4bc670e6 Relocate paste() from helpers.h to util.h, for sharing with initctl
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 16:21:53 +01:00
Joachim Wiberg 5e37f94775 Improve error messages for failing wordexp()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 15:06:02 +01:00
Joachim Wiberg 41319a8cf8 Work around forbidden chars in wordexp(): | < > & ;
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 14:54:34 +01:00
Joachim Wiberg 001e859a97 initctl: add create command, no template yet
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 12:47:47 +01:00
Joachim Wiberg 6cf8c7ade4 initctl: minor refactor, simplify edit command
- Gamble a bit by redirecting stderr to /dev/null instead of command -v
- Drop vi from VISUAL/EDITOR expansion alternatives, tested later anyway

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 11:45:04 +01:00
Joachim Wiberg 7439fa0c2a initctl: fix logic in edit command fallback handling
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 11:08:03 +01:00
Joachim Wiberg 6b1ba37438 doc: bump required versions of libuEv and libite
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 10:57:30 +01:00
Joachim Wiberg a579e0e8ae travis-ci: bump libuEv and libite versions, for systemf()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 10:57:30 +01:00
Joachim Wiberg 8077169ea9 Merge pull request #157 from troglobit/usr/kandeg/initctl-edit
initctl: add edit command, fix #154 

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 10:54:00 +01:00
Andreas Egeberg bf2272c6b3 Beautify code 2021-02-26 10:51:30 +01:00
Andreas Egeberg 60d0ca1075 Added Edit command
Command Edit <CONF>  opens file /etc/finit.d/available/<CONF>.conf in
the editor referenced by Linux environment variable $EDITOR
If $EDITOR is not set it will try to open emacs and if emacs is not
found it will try to open the file in vim.

Signed-off-by: Andreas Egeberg <andreas.egeberg@gmail.com>
2021-02-26 10:28:21 +01:00
Joachim Wiberg e3b27d47bc Follow-up to dfd41a1: fix default finit.conf path regression
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 09:52:42 +01:00
Joachim Wiberg 6b7255fdeb Fix regression introduced in 7ef25ab, global rlimits not initialized
Services that are instantiated by plugins, and thus don't have a .conf
file, tried to use uninitialized rlimits.  This caused the kernel to
immediately kill those services for violating their own rlimits.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 09:11:56 +01:00
Joachim Wiberg 80e4f025d3 flog: new helper function for debugging to file
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 09:09:34 +01:00
Joachim Wiberg 45a374b50a configure: allow custom directory for --with-sysconfig
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 18:28:11 +01:00
Joachim Wiberg ea9f88b9fb contrib: alpine: update to use env: files for service arguments
- Check for env in /etc/conf.d on Alpine
- Update all services with their respective env: file
- Disable default modules, noew modprobe plugin should handle this
- Add watchdog service
- Rename syslogd -> syslog, in case we want to integrate sysklogd

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 18:16:53 +01:00
Joachim Wiberg da2dde879e contrib: debian: update to use env: files for service arguments
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 18:16:53 +01:00
Joachim Wiberg 064d124e19 Refactor, add new helper fn paste() to concat directory compoents
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 17:41:39 +01:00
Joachim Wiberg f8a989439b Minor, insert '/' only if pasting components require it
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 17:18:44 +01:00
Joachim Wiberg dfd41a1b37 configure: minor refactor, simplify to reduce duplication
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 17:17:30 +01:00
Joachim Wiberg 74d3194775 Follow-up to f4a0b99: track modifications of service env: files
Add support for monitoring environment files for services declared with
the `env:[-]/path/to/file` option.  The default path to such files has
been chosen to follow Debian and Buildroot /etc/default/*

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 17:14:26 +01:00
Joachim Wiberg 7ef25abecf Refactor, use new iwatch module for inotify of Finit *.conf files
- Use iwatch, modeled after pidfile plugin
- Use one .conf watcher for all *.conf paths/files
- Use full path of conf file for changes, from realpath().
  This fixes a long-standing limitation on unique filenames
  for services, that absolutely nobody knew about

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 14:28:03 +01:00
Joachim Wiberg ea278a6370 plugins: pidfile: simplify, use constructs from src/conf.c
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 14:27:28 +01:00
Joachim Wiberg 8790fcabf3 iwatch: minor, check if file/dir exists before trying to add
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 14:27:01 +01:00
Joachim Wiberg 3d9ee49759 Follow-up to 6cdcacf, fix minor regression, premature clear of pid
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 14:23:45 +01:00
Joachim Wiberg cafbb18626 plugins: hotplug: log output from udevd/systemd-udevd to syslog
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 00:27:29 +01:00
Joachim Wiberg 939c6f2f67 Fix regression in displaying progress at runtime
We don't want to show progress (starting/stopping/restaring) at
runtime, since Finit v3.  Many systems hooked up to a console
get confused by sudden output, or even ansi escape sequences.

This patch drops code added recently which caused a regression
in this policy.  The resulting code is even more readable.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 00:22:01 +01:00
Joachim Wiberg 477b50b7a6 Check return value from kill(pid, SIGHUP), maybe lost pid
This patch handles a corner case when Finit may not have detected a
supervised process has died.  When a user calls `initctl restart foo`
we now send such lost PIDs to the service_monitor() for restart.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-24 23:58:25 +01:00
Joachim Wiberg 6cdcacf20b Refactor, shared cleanup fn for service_kill() and service_monitor()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-24 23:45:14 +01:00
Joachim Wiberg d37c20f467 Terminate children in the same process group when monitored PID dies
Really kill them, our monitored process may be about to restart, so we
don't want any unintended side effects from lingering children in prior
instances.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-24 23:43:03 +01:00
Joachim Wiberg 14f0443bd7 Allow services to be added *and removed* from /etc/finit.conf
This patch fixes a long standing issue where removing a service from
/etc/finit.conf does not stop and unregister it.  The issue was caused
by the Finit support for "protected" services, e.g. services created
by plugins like hotplug.so

To reproduce issue before this fix:

    cat /etc/finit.d/available/ntpd.conf >> /etc/finit.conf
    initctl reload

The NTP service now runs smoothly, as expected.  Later on, we decide to
drop it from our system:

    sed -i 1,2d /etc/finit.conf
    initctl reload

... and the NTP service continues to run unaffected.  Not what most sane
users expect.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-24 22:12:05 +01:00
Joachim Wiberg 81d8f3cccc Drop unnecessary service_step() in cond_reload()
The cond_reload() fn is called on `initctl reload`, thus we don't need
to call service_step(), since we call service_step_all() later in that
cycle.  So we can drop cond_update(NULL), which calls service_step().

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-24 22:12:05 +01:00