Commit Graph
693 Commits
Author SHA1 Message Date
Joachim Wiberg 3d50a28fe3 Make sure to _exit() TTY child also on error
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 21:25:54 +01:00
Joachim Wiberg 460add3cae initctl: introduce -f,--force option, for delete command
Never prompt, for scripting.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 12:20:29 +01:00
Joachim Wiberg 89be90cade initctl: fix compilation warning
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 12:13:32 +01:00
Joachim Wiberg 93f9856da8 initctl: ignore missing files to delete command, simplify yorn() str
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 12:12:03 +01:00
Joachim Wiberg e2f6ac0ece initctl: iterate command over all args, e.g. delete foo bar baz
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 12:06:59 +01:00
Joachim Wiberg c5db989bed initctl: skip errors from disable while deleting services
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 11:51:37 +01:00
Joachim Wiberg 928110b19e Minor whitespace in sample.conf
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 11:43:16 +01:00
Joachim Wiberg c204724353 Follow-up, fix variable expansion if unset
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 11:42:48 +01:00
Joachim Wiberg 2ac39e1917 initctl: restore Andreas' clever $(command ...) eval, it works
Turns out that on some systems, that has none of the first two, and
neither of the two environment variables set in ${VISUAL:-${EDITOR}},
they evaluate to 'sh /etc/finit.d/file.conf', which is true, so we
wouldn't even try mg or vi ...

This patch reverts to the spirit of Andreas Egebergs initial commit,
which turns out to be a better solution anyway :)

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 11:35:22 +01:00
Joachim Wiberg 49582c70c5 initctl: add companion delete command
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 11:15:36 +01:00
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 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 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 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 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 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 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 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 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 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 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
Joachim Wiberg d27b3948af Drop unnecessary and confusing debug message in mkcond()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-24 22:12:05 +01:00
Joachim Wiberg e0d3aa8e06 iwatch: handle watching paths for same inode
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-24 22:12:05 +01:00
Jacques de Laval 51fe974ee5 Use FINIT_RCSD instead of hard coded value
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-24 18:58:05 +01:00