mirror of
https://github.com/troglobit/finit.git
synced 2026-10-12 10:12:32 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4f3f140a09 | ||
|
|
10c24b1674 | ||
|
|
2b4f89ecd1 | ||
|
|
c42a6f2869 | ||
|
|
89bb609a7e | ||
|
|
da6298aecd | ||
|
|
576318cc29 | ||
|
|
0d7d331ad4 | ||
|
|
c886ecb5cc | ||
|
|
304a096877 | ||
|
|
064c7682fc | ||
|
|
58239b897b | ||
|
|
5281d82e80 | ||
|
|
5ff28c4dc6 | ||
|
|
f2218836af | ||
|
|
fbb3779d17 | ||
|
|
68f44f7a97 | ||
|
|
50e587f447 | ||
|
|
fb4c560196 | ||
|
|
8b5fa5eeaa | ||
|
|
88ec21e9cc | ||
|
|
84adec4006 | ||
|
|
19b2b2a279 | ||
|
|
e4163b7221 | ||
|
|
eaef302420 | ||
|
|
d5738da307 | ||
|
|
c9f930c7ad | ||
|
|
e2ee372b5d | ||
|
|
7ff7f93364 | ||
|
|
d5a95760ef | ||
|
|
24d1425b74 | ||
|
|
43d9e25ba7 | ||
|
|
f27998ae4f | ||
|
|
c8e0b6b9ef | ||
|
|
f7e8fccb2f | ||
|
|
7bbccb1213 | ||
|
|
d38c333e04 | ||
|
|
095f6b645c | ||
|
|
b4d10cbade | ||
|
|
5d703fd39e | ||
|
|
eaaf8d862e | ||
|
|
2468f11cd8 | ||
|
|
f8a6a119ac | ||
|
|
1889b88aab | ||
|
|
0d70023bfe | ||
|
|
41648a073b | ||
|
|
33cee0ba5f | ||
|
|
2235fb8352 | ||
|
|
eb9e94935e | ||
|
|
fb230f2137 | ||
|
|
6aa48a8b32 | ||
|
|
5b9cebbfd3 | ||
|
|
38791616e0 | ||
|
|
fede3fd2e1 | ||
|
|
a46a33238d | ||
|
|
afe0488bf2 | ||
|
|
ec5e42694d | ||
|
|
2e73563eea | ||
|
|
338521a748 | ||
|
|
6ae1083c99 | ||
|
|
846806747b | ||
|
|
8904ca993e | ||
|
|
efed0db16b | ||
|
|
11946f12d3 | ||
|
|
2ba359ed80 | ||
|
|
fafd524701 | ||
|
|
1ee6c9f46b | ||
|
|
a88eb82a68 | ||
|
|
a436a1c8cb | ||
|
|
7cb91854b0 | ||
|
|
939ae02a6a | ||
|
|
480d29175c | ||
|
|
ea68413512 | ||
|
|
4edfa9859e | ||
|
|
eb6291c943 | ||
|
|
756b7c3fb6 | ||
|
|
263aec292a | ||
|
|
5a946a4ea7 | ||
|
|
c90b4d797b | ||
|
|
6e7a2fb6d5 | ||
|
|
ddedcf77e8 | ||
|
|
924ec2ef80 | ||
|
|
a49f27c191 | ||
|
|
b41b4ce989 | ||
|
|
3d74e93fa2 | ||
|
|
443700a88e | ||
|
|
4701edef4c | ||
|
|
e6da0a22e7 | ||
|
|
7be2bbbc30 | ||
|
|
3e269c632f | ||
|
|
f2507d9fd7 | ||
|
|
e9f403bceb | ||
|
|
c03176c42a | ||
|
|
9707bfb103 | ||
|
|
11430f83c8 | ||
|
|
a22a794f55 | ||
|
|
5556501287 | ||
|
|
ab554568b2 | ||
|
|
b39a4498a3 | ||
|
|
dead2444e2 | ||
|
|
a58002588e | ||
|
|
28e101aaae | ||
|
|
6da8af8136 | ||
|
|
3069e753e1 | ||
|
|
aafd5c1010 | ||
|
|
2f51c8ea0d | ||
|
|
d1130473fc | ||
|
|
b682a5e4fe | ||
|
|
1fc0f36c6c | ||
|
|
5df5b22327 | ||
|
|
4153c7966d | ||
|
|
458d68533f | ||
|
|
63b5db38df | ||
|
|
2135639508 | ||
|
|
9c8cd6c024 | ||
|
|
450f498061 | ||
|
|
5769500afe | ||
|
|
dc61969164 | ||
|
|
6f0d448765 | ||
|
|
0c9b7a67e0 | ||
|
|
5db2fb2c32 |
@@ -10,12 +10,29 @@ jobs:
|
|||||||
name: Build and upload release tarball
|
name: Build and upload release tarball
|
||||||
if: startsWith(github.ref, 'refs/tags/')
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
MAKEFLAGS: -j3
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Installing dependencies ...
|
- name: Installing dependencies ...
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get -y update
|
sudo apt-get -y update
|
||||||
sudo apt-get -y install pkg-config jq libuev-dev libite-dev
|
sudo apt-get -y install pkg-config jq libuev-dev libite-dev
|
||||||
|
- name: Setting release variables ...
|
||||||
|
id: build
|
||||||
|
run: |
|
||||||
|
ver=${GITHUB_REF#refs/tags/}
|
||||||
|
echo "ver=${ver}" >> $GITHUB_OUTPUT
|
||||||
|
if echo $ver | grep -qE '^[0-9]+\.[0-9]+(\.[0-9]+)?(-alpha|-beta|-rc)[0-9]*$'; then
|
||||||
|
echo "pre=true" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "pre=false" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
if echo $ver | grep -qE '^[0-9.]+\.[0-9.]+(\.[0-9]+)?$'; then
|
||||||
|
echo "latest=true" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "latest=false" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
- name: Creating Makefiles ...
|
- name: Creating Makefiles ...
|
||||||
run: |
|
run: |
|
||||||
./autogen.sh
|
./autogen.sh
|
||||||
@@ -36,5 +53,7 @@ jobs:
|
|||||||
- uses: ncipollo/release-action@v1
|
- uses: ncipollo/release-action@v1
|
||||||
with:
|
with:
|
||||||
name: Finit v${{ github.ref_name }}
|
name: Finit v${{ github.ref_name }}
|
||||||
|
prerelease: ${{ steps.build.outputs.pre }}
|
||||||
|
makeLatest: ${{ steps.build.outputs.latest }}
|
||||||
bodyFile: "release.md"
|
bodyFile: "release.md"
|
||||||
artifacts: "artifacts/*"
|
artifacts: "artifacts/*"
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Check for any commits since last week
|
- name: Check for any commits since last week
|
||||||
|
id: schedule
|
||||||
run: |
|
run: |
|
||||||
commits="$(git log --format=%H --since='1 week ago')"
|
commits="$(git log --format=%H --since='1 week ago')"
|
||||||
if [ -n "$commits" ]; then
|
if [ -n "$commits" ]; then
|
||||||
@@ -22,10 +23,9 @@ jobs:
|
|||||||
else
|
else
|
||||||
echo "run=false" >> $GITHUB_OUTPUT
|
echo "run=false" >> $GITHUB_OUTPUT
|
||||||
fi
|
fi
|
||||||
|
|
||||||
distcheck:
|
distcheck:
|
||||||
needs: schedule
|
needs: schedule
|
||||||
if: ${{ needs.schedule.outputs.run == 'true' }}
|
if: ${{ needs.schedule.outputs.run }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
|
|||||||
+105
-1
@@ -4,6 +4,109 @@ Change Log
|
|||||||
All relevant changes are documented in this file.
|
All relevant changes are documented in this file.
|
||||||
|
|
||||||
|
|
||||||
|
[4.5][] - 2023-10-30
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
- Refactor `runparts` and `/etc/rc.local` to no longer block the main
|
||||||
|
loop, allowing `initctl` calls to interact with Finit. Issue #356
|
||||||
|
- Refactor the `run` stanza to no longer block the main loop, issue #362
|
||||||
|
- Allow `sulogin` with a user different from `root`, issue #357
|
||||||
|
- Allow disabling invocation of rescue mode from kernel command line
|
||||||
|
- Add `initctl -f` to force-skip asking Finit for existing services
|
||||||
|
when creating new services during bootstrap, e.g. `/etc/rc.local`
|
||||||
|
- `initctl runlevel` now returns `N S` instead of `N 10` in bootstrap
|
||||||
|
- `initctl runlevel N` during bootstrap is now allowed. It changes
|
||||||
|
the next runlevel to go to when bootstrap has completed. Effectively
|
||||||
|
overriding the `runlevel N` statement in `/etc/finit.conf`
|
||||||
|
- Improved logging on failure to `execvp()` a run/task/service, now
|
||||||
|
with `errno`, e.g., "No such file or directory" when the command
|
||||||
|
is missing from `$PATH`
|
||||||
|
- Add Bash completion support for `initctl`, configurable, issue #360
|
||||||
|
- Handle absolute path to `initctl [enable|disable]`, not supported
|
||||||
|
- Update `finit.conf(5)` man page with the recommended directory
|
||||||
|
hierarchy in `/etc/finit.d/`
|
||||||
|
- The `runparts` code has been split into `/libexec/finit/runparts`
|
||||||
|
- The `runparts` command now takes two options: `sysv` and `progress`.
|
||||||
|
The former ensures only `SNNfoo` and `KNNfoo` scripts are run.
|
||||||
|
- Add SysV Init Compatibility section to documentation
|
||||||
|
- Increased MAX path for commands, and arguments: 64 -> 256
|
||||||
|
- The bundled watchdog daemon no longer tries to log at startup, because
|
||||||
|
syslog is not available yet, any startup message leak to console
|
||||||
|
- Extend `if:` option with runtime evaluation of conditions. E.g., start
|
||||||
|
a task only `if:<run/foo/failure>` (here the run task 'foo' failed)
|
||||||
|
- Document new `if:`, `conflict:`, `nowarn` options for run/task/service
|
||||||
|
first introduced in v4.4
|
||||||
|
- Failure to open fstab should log to console, not just log to `/dev/kmsg`
|
||||||
|
- Rename `/lib/finit/system/*.conf`, added numbered prefix to ensure
|
||||||
|
proper execution order, e.g., `udevd` should always run first
|
||||||
|
- Plugins and bundled services: dbus, keventd, watchdogd, and runparts,
|
||||||
|
are now loaded *after* all services in `/lib/finit/system/`. A new
|
||||||
|
runtime-only path (for inspection) in `/run/finit/system/` is used
|
||||||
|
- Redirect `log*` output to console when `finit.debug` is enabled
|
||||||
|
- Assert `<int/container>` condition if we detect running in container
|
||||||
|
- Add support for mdev's netlink daemon mode, issue #367
|
||||||
|
- Add support for mdevd in `10-hotplug.conf`, preferred over plain mdev
|
||||||
|
- Disable modprobe plugin by default, udevd and mdev/mdevd loads modules
|
||||||
|
- Update documentation for run/task shell limitations, issue #376
|
||||||
|
- Update documentation regarding automount of `/run` and `/tmp`
|
||||||
|
- Update plugin documentation, add section about limited tmpfiles.d(5) support
|
||||||
|
- Skip registering service when `if:!name` matches a known service.
|
||||||
|
This allows conditional loading of alternative services, e.g. if udevd
|
||||||
|
is already loaded we do not need mdevd
|
||||||
|
- Drop `doc/bootstrap.md`, inaccurate and confusing to users
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
- Fix #227: believed to have been fixed in v4.3, the root cause was
|
||||||
|
actually that Finit was waiting for a process that was no longer in
|
||||||
|
the system. The fix is to ask the kernel on process-stop-timeout and
|
||||||
|
replay the lost PID so that Finit can continue with reboot/shutdown
|
||||||
|
- Fix #358: fix inotify events for `/etc/finit.conf`, improved log
|
||||||
|
messages and error handling
|
||||||
|
- Fix #361: cgroup move fail if run/task/services start as non-root.
|
||||||
|
Regression in the v4.4 release cycle while adding support for the
|
||||||
|
pre:/post:/ready: scripts. Now the latter scripts also properly run
|
||||||
|
in their correct cgroup
|
||||||
|
- Fix #366: document `fsck.*` kernel command line options and simplify
|
||||||
|
the configure flags `--enable-fsckfix` and `--enable-fastboot` to
|
||||||
|
only adjust the default values for the `fsck.*` options.
|
||||||
|
- Fix #371: swap load order of `/lib/finit/system/*` vs `/etc/finit.d/*`
|
||||||
|
We must run `10-hotplug.conf` first to ensure devices and modules are
|
||||||
|
up and loaded before the user's run/task/services are called. The order
|
||||||
|
at bootstrap is now saved in `/run/finit/conf.order` for inspection,
|
||||||
|
`/run/finit/exec.order` shows the start order of each process
|
||||||
|
- Fix #372: lost `udevadm` calls due to overloading
|
||||||
|
- Adjust final `udevadm settle` timeout: 5 -> 30 sec
|
||||||
|
- Fixed dbus plugin, the function that located `<pidfile> ...` in the
|
||||||
|
`dbus/system.conf` caused spurious line breaks which led to the
|
||||||
|
service not being loaded properly
|
||||||
|
- The `runparts` executor now skips backup files (`foo~`)
|
||||||
|
- The `runparts` stanza now properly appends ` start` to scripts that
|
||||||
|
start with `S[0-9]+`. This has been broken for a very long time.
|
||||||
|
- Fix #377: expand service `env:file` variables, allow constructs like:
|
||||||
|
|
||||||
|
RUNDIR=/var/run/somesvc
|
||||||
|
DAEMON_ARGS=--workdir $RUNDIR --other-args...
|
||||||
|
- Fix #378: warn on console if run/task times out during bootstrap
|
||||||
|
- Fix #378: add run/task support for `<!>` to allow transition from
|
||||||
|
bootstrap to multi-user runlevel even though task has not run yet.
|
||||||
|
- Fix #382: do not clear `<service/foo/STATE>` conditions on reload.
|
||||||
|
Introduced back in v4.3-rc2, 82cc10be8, the support for automatic
|
||||||
|
service conditions have had a weird and unintended behavior. Any
|
||||||
|
change in state (see `doc/svc-machine.png`) caused Finit to clear
|
||||||
|
out *all* previously acquired service conditions.
|
||||||
|
|
||||||
|
However, when moving between RUNNING and PAUSED states, a service
|
||||||
|
should not have its conditions cleared. The PAUSED state, seen
|
||||||
|
also by all conditions moving to FLUX, is only temporary while an
|
||||||
|
`initctl reload` is processed. If a service has no changes to be
|
||||||
|
applied it will move back to RUNNING.
|
||||||
|
|
||||||
|
Also, we cannot clear the service conditions because other run/task
|
||||||
|
or services may depend on it and clearing them would cause Finit to
|
||||||
|
`SIGTERM` these processes (since they are no longer eligible to run).
|
||||||
|
|
||||||
|
|
||||||
[4.4][] - 2023-05-15
|
[4.4][] - 2023-05-15
|
||||||
--------------------
|
--------------------
|
||||||
|
|
||||||
@@ -1510,7 +1613,8 @@ Major bug fix release.
|
|||||||
|
|
||||||
* Initial release
|
* Initial release
|
||||||
|
|
||||||
[UNRELEASED]: https://github.com/troglobit/finit/compare/4.3...HEAD
|
[UNRELEASED]: https://github.com/troglobit/finit/compare/4.5...HEAD
|
||||||
|
[4.5]: https://github.com/troglobit/finit/compare/4.4...4.5
|
||||||
[4.4]: https://github.com/troglobit/finit/compare/4.3...4.4
|
[4.4]: https://github.com/troglobit/finit/compare/4.3...4.4
|
||||||
[4.3]: https://github.com/troglobit/finit/compare/4.2...4.3
|
[4.3]: https://github.com/troglobit/finit/compare/4.2...4.3
|
||||||
[4.2]: https://github.com/troglobit/finit/compare/4.1...4.2
|
[4.2]: https://github.com/troglobit/finit/compare/4.1...4.2
|
||||||
|
|||||||
+8
-3
@@ -10,6 +10,10 @@ if DOC
|
|||||||
SUBDIRS += doc
|
SUBDIRS += doc
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if BASH
|
||||||
|
bashdir = $(BASH_DIR)
|
||||||
|
dist_bash_DATA = initctl
|
||||||
|
endif
|
||||||
# Compat hook
|
# Compat hook
|
||||||
install-dev:
|
install-dev:
|
||||||
@make -C src install-pkgincludeHEADERS
|
@make -C src install-pkgincludeHEADERS
|
||||||
@@ -30,6 +34,7 @@ release: distcheck
|
|||||||
printf "$$file.sha256\t"; cat ../$$file.sha256 | cut -f1 -d' '; \
|
printf "$$file.sha256\t"; cat ../$$file.sha256 | cut -f1 -d' '; \
|
||||||
done
|
done
|
||||||
|
|
||||||
DISTCHECK_CONFIGURE_FLAGS = --prefix=/usr --sysconfdir=/etc --localstatedir=/var \
|
DISTCHECK_CONFIGURE_FLAGS = --prefix=/usr --sysconfdir=/etc --localstatedir=/var \
|
||||||
--enable-testserv-plugin --enable-x11-common-plugin \
|
--enable-testserv-plugin --enable-x11-common-plugin \
|
||||||
--with-watchdog --with-keventd --with-fstab=/etc/fstab
|
--with-watchdog --with-keventd --with-fstab=/etc/fstab \
|
||||||
|
--with-bash-completion-dir=no
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
* [Introduction](#introduction)
|
* [Introduction](#introduction)
|
||||||
* [Features](#features)
|
* [Features](#features)
|
||||||
* [Bootstrap](doc/bootstrap.md#bootstrap)
|
|
||||||
* [Runlevels](#runlevels)
|
* [Runlevels](#runlevels)
|
||||||
* [Syntax](doc/config.md#syntax)
|
* [Syntax](doc/config.md#syntax)
|
||||||
* [Runparts & /etc/rc.local](#runparts--etcrclocal)
|
* [Runparts & /etc/rc.local](#runparts--etcrclocal)
|
||||||
@@ -391,8 +390,7 @@ Right after the runlevel change when all services have started properly,
|
|||||||
No configuration stanza in `/etc/finit.conf` is required for `rc.local`.
|
No configuration stanza in `/etc/finit.conf` is required for `rc.local`.
|
||||||
If it exists and is an executable shell script Finit calls it at the very
|
If it exists and is an executable shell script Finit calls it at the very
|
||||||
end of the boot, before calling the `HOOK_SYSTEM_UP`. See more on hooks
|
end of the boot, before calling the `HOOK_SYSTEM_UP`. See more on hooks
|
||||||
in [doc/plugins.md](doc/plugins.md#hooks), and about the system bootstrap
|
in [doc/plugins.md](doc/plugins.md#hooks).
|
||||||
in [doc/bootstrap.md](doc/bootstrap.md).
|
|
||||||
|
|
||||||
|
|
||||||
### Limitations
|
### Limitations
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Run test suite with the correct configure params
|
||||||
|
|
||||||
|
make distclean
|
||||||
|
./configure --prefix=/usr --exec-prefix= --sysconfdir=/etc --localstatedir=/var \
|
||||||
|
--enable-x11-common-plugin --with-watchdog --with-keventd
|
||||||
|
make -j17 clean check
|
||||||
+50
-15
@@ -1,4 +1,5 @@
|
|||||||
AC_INIT([Finit],[4.4],[https://github.com/troglobit/finit/issues],[finit],[https://troglobit.com/projects/finit/])
|
AC_INIT([Finit], [4.5], [https://github.com/troglobit/finit/issues],
|
||||||
|
[finit], [https://troglobit.com/projects/finit/])
|
||||||
AC_CONFIG_AUX_DIR(aux)
|
AC_CONFIG_AUX_DIR(aux)
|
||||||
AM_INIT_AUTOMAKE([1.11 foreign dist-xz subdir-objects])
|
AM_INIT_AUTOMAKE([1.11 foreign dist-xz subdir-objects])
|
||||||
AM_SILENT_RULES([yes])
|
AM_SILENT_RULES([yes])
|
||||||
@@ -14,10 +15,10 @@ AC_CONFIG_FILES([Makefile
|
|||||||
man/Makefile
|
man/Makefile
|
||||||
plugins/Makefile
|
plugins/Makefile
|
||||||
src/Makefile
|
src/Makefile
|
||||||
system/Makefile
|
system/Makefile system/10-hotplug.conf
|
||||||
tmpfiles.d/Makefile
|
|
||||||
test/test.env test/Makefile
|
test/test.env test/Makefile
|
||||||
test/lib/Makefile test/src/Makefile])
|
test/lib/Makefile test/src/Makefile
|
||||||
|
tmpfiles.d/Makefile])
|
||||||
|
|
||||||
# Older versions of autoconf (<2.58) do not have AC_CONFIG_MACRO_DIR()
|
# Older versions of autoconf (<2.58) do not have AC_CONFIG_MACRO_DIR()
|
||||||
#m4_include([m4/plugin.m4])
|
#m4_include([m4/plugin.m4])
|
||||||
@@ -71,7 +72,7 @@ AC_ARG_ENABLE(redirect,
|
|||||||
enable_redirect=yes])
|
enable_redirect=yes])
|
||||||
|
|
||||||
AC_ARG_ENABLE(logrotate,
|
AC_ARG_ENABLE(logrotate,
|
||||||
AS_HELP_STRING([--disable-logrotate], [Disable built-in rotation of /var/log/wtmp, default enabled]),,[
|
AS_HELP_STRING([--disable-logrotate], [Disable built-in rotation of /var/log/wtmp]),,[
|
||||||
enable_logrotate=yes])
|
enable_logrotate=yes])
|
||||||
|
|
||||||
AC_ARG_ENABLE(doc,
|
AC_ARG_ENABLE(doc,
|
||||||
@@ -82,6 +83,10 @@ AC_ARG_ENABLE(contrib,
|
|||||||
AS_HELP_STRING([--disable-contrib], [Disable build and install of contrib section]),,[
|
AS_HELP_STRING([--disable-contrib], [Disable build and install of contrib section]),,[
|
||||||
enable_contrib=yes])
|
enable_contrib=yes])
|
||||||
|
|
||||||
|
AC_ARG_ENABLE([rescue],
|
||||||
|
AS_HELP_STRING([--disable-rescue], [Disable potentially unsafe rescue mode]),,
|
||||||
|
[enable_rescue=yes])
|
||||||
|
|
||||||
# Check for extra plugins to enable
|
# Check for extra plugins to enable
|
||||||
AC_ARG_ENABLE(all_plugins,
|
AC_ARG_ENABLE(all_plugins,
|
||||||
AS_HELP_STRING([--enable-all-plugins], [Enable all plugins, default: auto]),
|
AS_HELP_STRING([--enable-all-plugins], [Enable all plugins, default: auto]),
|
||||||
@@ -89,18 +94,22 @@ AC_ARG_ENABLE(all_plugins,
|
|||||||
AC_PLUGIN([alsa-utils], [no], [Save and restore ALSA sound settings using alsactl])
|
AC_PLUGIN([alsa-utils], [no], [Save and restore ALSA sound settings using alsactl])
|
||||||
AC_PLUGIN([dbus], [no], [Setup and start system message bus, D-Bus])
|
AC_PLUGIN([dbus], [no], [Setup and start system message bus, D-Bus])
|
||||||
AC_PLUGIN([modules-load], [no], [Scans /etc/modules-load.d for modules to load])
|
AC_PLUGIN([modules-load], [no], [Scans /etc/modules-load.d for modules to load])
|
||||||
AC_PLUGIN([modprobe], [yes], [Coldplug modules using modalias magic])
|
AC_PLUGIN([modprobe], [no], [Coldplug modules using modalias magic])
|
||||||
AC_PLUGIN([resolvconf], [no], [Setup necessary files for resolvconf])
|
AC_PLUGIN([resolvconf], [no], [Setup necessary files for resolvconf])
|
||||||
AC_PLUGIN([x11-common], [no], [Console setup (for X)])
|
AC_PLUGIN([x11-common], [no], [Console setup (for X)])
|
||||||
AC_PLUGIN([netlink], [yes], [Basic netlink plugin for IFUP/IFDN and GW events. Can be replaced with externally built plugin that links with libnl or similar.])
|
AC_PLUGIN([netlink], [yes], [Basic netlink plugin for IFUP/IFDN and GW events. Can be replaced with externally built plugin that links with libnl or similar.])
|
||||||
AC_PLUGIN([hook-scripts], [no], [Trigger script execution from hook points])
|
AC_PLUGIN([hook-scripts], [no], [Trigger script execution from hook points])
|
||||||
AC_PLUGIN([hotplug], [yes], [Setup and start udev or mdev hotplug daemon])
|
AC_PLUGIN([hotplug], [yes], [Start udevd or mdev kernel event datamon])
|
||||||
AC_PLUGIN([rtc], [yes], [Save and restore RTC using hwclock])
|
AC_PLUGIN([rtc], [yes], [Save and restore RTC using hwclock])
|
||||||
AC_PLUGIN([tty], [yes], [Automatically activate new TTYs, e.g. USB-to-serial])
|
AC_PLUGIN([tty], [yes], [Automatically activate new TTYs, e.g. USB-to-serial])
|
||||||
AC_PLUGIN([urandom], [yes], [Setup and save random seed at boot/shutdown])
|
AC_PLUGIN([urandom], [yes], [Setup and save random seed at boot/shutdown])
|
||||||
AC_PLUGIN([testserv], [no], [Test plugin to start test serv daemon])
|
AC_PLUGIN([testserv], [no], [Test plugin to start test serv daemon])
|
||||||
|
|
||||||
# Check for extra arguments or packages
|
# Check for extra arguments or packages
|
||||||
|
AC_ARG_WITH([bash-completion-dir],
|
||||||
|
AS_HELP_STRING([--with-bash-completion-dir[=PATH]], [Directory to install Bash completion, default: auto]),
|
||||||
|
[bash_dir=$withval], [bash_dir=yes])
|
||||||
|
|
||||||
AC_ARG_WITH(fstab,
|
AC_ARG_WITH(fstab,
|
||||||
AS_HELP_STRING([--with-fstab=FILE], [System default fstab, default $sysconfdir/fstab]),
|
AS_HELP_STRING([--with-fstab=FILE], [System default fstab, default $sysconfdir/fstab]),
|
||||||
[fstab=$withval], [fstab=yes])
|
[fstab=$withval], [fstab=yes])
|
||||||
@@ -145,10 +154,10 @@ AC_ARG_WITH(keventd,
|
|||||||
AS_HELP_STRING([--with-keventd], [Enable built-in keventd, default: no]),, [with_keventd=no])
|
AS_HELP_STRING([--with-keventd], [Enable built-in keventd, default: no]),, [with_keventd=no])
|
||||||
|
|
||||||
AC_ARG_WITH(sulogin,
|
AC_ARG_WITH(sulogin,
|
||||||
AS_HELP_STRING([--with-sulogin], [Enable built-in sulogin, default: no.]),, [with_sulogin=no])
|
AS_HELP_STRING([--with-sulogin@<:@=USER@:>@], [Enable built-in sulogin, optional USER to request password for (default root), default: no.]),[sulogin=$withval],[with_sulogin=no])
|
||||||
|
|
||||||
AC_ARG_WITH(watchdog,
|
AC_ARG_WITH(watchdog,
|
||||||
AS_HELP_STRING([--with-watchdog=[DEV]], [Enable built-in watchdog, default: /dev/watchdog]),
|
AS_HELP_STRING([--with-watchdog@<:@=DEV@:>@], [Enable built-in watchdog, default: /dev/watchdog]),
|
||||||
[watchdog=$withval], [with_watchdog=no watchdog=])
|
[watchdog=$withval], [with_watchdog=no watchdog=])
|
||||||
|
|
||||||
AC_ARG_WITH(hook-scripts-path,
|
AC_ARG_WITH(hook-scripts-path,
|
||||||
@@ -185,9 +194,18 @@ AS_IF([test "x$enable_redirect" = "xyes"], [
|
|||||||
AS_IF([test "x$enable_logrotate" != "xno"], [
|
AS_IF([test "x$enable_logrotate" != "xno"], [
|
||||||
AC_DEFINE(LOGROTATE_ENABLED, 1, [Enable built-in rotation of /var/log/wtmp et al.])])
|
AC_DEFINE(LOGROTATE_ENABLED, 1, [Enable built-in rotation of /var/log/wtmp et al.])])
|
||||||
|
|
||||||
|
AS_IF([test "x$enable_rescue" != "xno"], [
|
||||||
|
AC_DEFINE([RESCUE_MODE], 1, [Define to enable support for rescue mode.])])
|
||||||
|
|
||||||
AM_CONDITIONAL(LOGROTATE, [test "x$enable_logrotate" = "xyes"])
|
AM_CONDITIONAL(LOGROTATE, [test "x$enable_logrotate" = "xyes"])
|
||||||
|
|
||||||
### With features ##############################################################################
|
### With features ##############################################################################
|
||||||
|
AS_IF([test "x$bash_dir" = "xyes"], [
|
||||||
|
PKG_CHECK_MODULES([BASH_COMPLETION], [bash-completion >= 2.0],
|
||||||
|
[BASH_DIR="$(pkg-config --variable=completionsdir bash-completion)"],
|
||||||
|
[BASH_DIR="$datadir/bash-completion/completions"])], [
|
||||||
|
BASH_DIR="$bash_dir"])
|
||||||
|
|
||||||
AS_IF([test "x$with_fstab" != "xno"], [
|
AS_IF([test "x$with_fstab" != "xno"], [
|
||||||
AS_IF([test "x$fstab" = "xyes"], [fstab=$sysconfdir/fstab])
|
AS_IF([test "x$fstab" = "xyes"], [fstab=$sysconfdir/fstab])
|
||||||
AC_EXPAND_DIR(fstab_path, "$fstab")
|
AC_EXPAND_DIR(fstab_path, "$fstab")
|
||||||
@@ -252,7 +270,12 @@ AS_IF([test "x$rtc_date" != "xno"], [
|
|||||||
|
|
||||||
AS_IF([test "x$with_keventd" != "xno"], [with_keventd=yes])
|
AS_IF([test "x$with_keventd" != "xno"], [with_keventd=yes])
|
||||||
|
|
||||||
AS_IF([test "x$with_sulogin" != "xno"], [with_sulogin=yes])
|
AS_IF([test "x$with_sulogin" != "xno"], [
|
||||||
|
AS_IF([test "x$sulogin" = "xyes"], [
|
||||||
|
sulogin=root])
|
||||||
|
with_sulogin=yes
|
||||||
|
AC_DEFINE_UNQUOTED(SULOGIN_USER, "$sulogin", [Built-in sulogin user, default: root])], [
|
||||||
|
sulogin=])
|
||||||
|
|
||||||
AS_IF([test "x$with_watchdog" != "xno"], [
|
AS_IF([test "x$with_watchdog" != "xno"], [
|
||||||
AS_IF([test "x$watchdog" = "xyes"], [
|
AS_IF([test "x$watchdog" = "xyes"], [
|
||||||
@@ -272,19 +295,26 @@ AS_IF([test "x$with_plugin_path" != "xno"], [
|
|||||||
AC_DEFINE_UNQUOTED(EXTERNAL_PLUGIN_PATH, "$plugin_path", [Built-in default: /usr/lib/finit/plugins:/usr/local/lib/finit/plugins])])
|
AC_DEFINE_UNQUOTED(EXTERNAL_PLUGIN_PATH, "$plugin_path", [Built-in default: /usr/lib/finit/plugins:/usr/local/lib/finit/plugins])])
|
||||||
|
|
||||||
# Control build with automake flags
|
# Control build with automake flags
|
||||||
AM_CONDITIONAL(STATIC, [test "x$enable_static" = "xyes"])
|
AM_CONDITIONAL(BASH, [test "x$bash_dir" != "xno"])
|
||||||
|
AM_CONDITIONAL(STATIC, [test "x$enable_static" = "xyes"])
|
||||||
AM_CONDITIONAL(KEVENTD, [test "x$with_keventd" != "xno"])
|
AM_CONDITIONAL(KEVENTD, [test "x$with_keventd" != "xno"])
|
||||||
AM_CONDITIONAL(SULOGIN, [test "x$with_sulogin" != "xno"])
|
AM_CONDITIONAL(SULOGIN, [test "x$with_sulogin" != "xno"])
|
||||||
AM_CONDITIONAL(WATCHDOGD, [test "x$with_watchdog" != "xno"])
|
AM_CONDITIONAL(WATCHDOGD, [test "x$with_watchdog" != "xno"])
|
||||||
AM_CONDITIONAL(DOC, [test "x$enable_doc" = "xyes"])
|
AM_CONDITIONAL(DOC, [test "x$enable_doc" = "xyes"])
|
||||||
AM_CONDITIONAL(CONTRIB, [test "x$enable_contrib" = "xyes"])
|
AM_CONDITIONAL(CONTRIB, [test "x$enable_contrib" = "xyes"])
|
||||||
AM_CONDITIONAL(TESTSERV, [test "x$enable_testserv_plugin" = "xyes"])
|
AM_CONDITIONAL(TESTSERV, [test "x$enable_testserv_plugin" = "xyes"])
|
||||||
|
|
||||||
|
# Workaround for as-of-yet unreleased runstatedir support, planned for
|
||||||
|
# autoconf 2.70, which some major distros have backported.
|
||||||
|
AS_IF([test -z "$runstatedir"], runstatedir="$localstatedir/run")
|
||||||
|
AC_SUBST(runstatedir)
|
||||||
|
|
||||||
# Override default libdir, used for plugins and rescue.conf
|
# Override default libdir, used for plugins and rescue.conf
|
||||||
pkglibdir=$libdir/finit
|
pkglibdir=$libdir/finit
|
||||||
AC_SUBST(pkglibexecdir)
|
AC_SUBST(pkglibexecdir)
|
||||||
AC_EXPAND_DIR(pkglibexecdir, "$libexecdir/finit")
|
AC_EXPAND_DIR(pkglibexecdir, "$libexecdir/finit")
|
||||||
AC_DEFINE_UNQUOTED(FINIT_EXECPATH_, "$pkglibexecdir", [Finit libexec path])
|
AC_DEFINE_UNQUOTED(FINIT_EXECPATH_, "$pkglibexecdir", [Finit libexec path])
|
||||||
|
AC_DEFINE_UNQUOTED(FINIT_RUNPATH_, "$runstatedir/finit/system", [Finit runtime dynamic system services])
|
||||||
|
|
||||||
AC_EXPAND_DIR(plugin_path, "$pkglibdir/plugins")
|
AC_EXPAND_DIR(plugin_path, "$pkglibdir/plugins")
|
||||||
AC_SUBST(plugin_path)
|
AC_SUBST(plugin_path)
|
||||||
@@ -292,7 +322,7 @@ AC_DEFINE_UNQUOTED(PLUGIN_PATH, "$plugin_path", [Finit plugin path])
|
|||||||
|
|
||||||
AC_EXPAND_DIR(tmpfiles_path, "$libdir/tmpfiles.d")
|
AC_EXPAND_DIR(tmpfiles_path, "$libdir/tmpfiles.d")
|
||||||
AC_SUBST(tmpfiles_path)
|
AC_SUBST(tmpfiles_path)
|
||||||
AC_DEFINE_UNQUOTED(TMPFILES_PATH, "$tmpfiles_path", [Main tmpfiles.d/, override in /etc])
|
AC_DEFINE_UNQUOTED(TMPFILES_PATH_, "$tmpfiles_path", [Main tmpfiles.d/, override in /etc])
|
||||||
|
|
||||||
AC_EXPAND_DIR(finit_tmpfiles, "$pkglibdir/tmpfiles.d")
|
AC_EXPAND_DIR(finit_tmpfiles, "$pkglibdir/tmpfiles.d")
|
||||||
AC_SUBST(finit_tmpfiles)
|
AC_SUBST(finit_tmpfiles)
|
||||||
@@ -300,13 +330,16 @@ AC_DEFINE_UNQUOTED(FINIT_TMPFILES, "$finit_tmpfiles", [Finit tmpfiles.d/ .conf p
|
|||||||
|
|
||||||
AC_EXPAND_DIR(system_path, "$pkglibdir/system")
|
AC_EXPAND_DIR(system_path, "$pkglibdir/system")
|
||||||
AC_SUBST(system_path)
|
AC_SUBST(system_path)
|
||||||
AC_DEFINE_UNQUOTED(FINIT_SYSPATH, "$system_path", [Static services, previously generated at runtime by plugins])
|
AC_DEFINE_UNQUOTED(FINIT_SYSPATH_, "$system_path", [Static services, previously generated at runtime by plugins])
|
||||||
|
|
||||||
AC_EXPAND_DIR(rescue_conf, "$pkglibdir/rescue.conf")
|
AC_EXPAND_DIR(rescue_conf, "$pkglibdir/rescue.conf")
|
||||||
AC_DEFINE_UNQUOTED(RESCUE_CONF, "$rescue_conf", [Finit rescue mode .conf])
|
AC_DEFINE_UNQUOTED(RESCUE_CONF, "$rescue_conf", [Finit rescue mode .conf])
|
||||||
AC_EXPAND_DIR(sample_conf, "$pkglibdir/sample.conf")
|
AC_EXPAND_DIR(sample_conf, "$pkglibdir/sample.conf")
|
||||||
AC_DEFINE_UNQUOTED(SAMPLE_CONF, "$sample_conf", [Finit sameple.conf for initctl create])
|
AC_DEFINE_UNQUOTED(SAMPLE_CONF, "$sample_conf", [Finit sameple.conf for initctl create])
|
||||||
|
|
||||||
|
AC_EXPAND_DIR(bash_completion_dir, "$BASH_DIR")
|
||||||
|
AC_SUBST(BASH_DIR, "$bash_completion_dir")
|
||||||
|
|
||||||
AS_IF([test "$heading" = ""], [heading="<DEFAULT>"])
|
AS_IF([test "$heading" = ""], [heading="<DEFAULT>"])
|
||||||
AS_IF([test "$heading" = "no"], [heading="<NONE>"])
|
AS_IF([test "$heading" = "no"], [heading="<NONE>"])
|
||||||
|
|
||||||
@@ -343,13 +376,15 @@ Behavior:
|
|||||||
Optional features:
|
Optional features:
|
||||||
Install doc/..........: $enable_doc
|
Install doc/..........: $enable_doc
|
||||||
Install contrib/......: $enable_contrib
|
Install contrib/......: $enable_contrib
|
||||||
|
Bash completion.......: $bash_completion_dir
|
||||||
Built-in keventd......: $with_keventd
|
Built-in keventd......: $with_keventd
|
||||||
Built-in sulogin......: $with_sulogin
|
Built-in sulogin......: $with_sulogin $sulogin
|
||||||
Built-in watchdogd....: $with_watchdog $watchdog
|
Built-in watchdogd....: $with_watchdog $watchdog
|
||||||
Built-in logrotate....: $enable_logrotate
|
Built-in logrotate....: $enable_logrotate
|
||||||
Skip fsck check.......: $enable_fastboot
|
Skip fsck check.......: $enable_fastboot
|
||||||
Run fsck fix mode.....: $enable_fsckfix
|
Run fsck fix mode.....: $enable_fsckfix
|
||||||
Redirect output.......: $enable_redirect
|
Redirect output.......: $enable_redirect
|
||||||
|
Rescue mode...........: $enable_rescue
|
||||||
Default hostname......: $hostname
|
Default hostname......: $hostname
|
||||||
Default group.........: $group
|
Default group.........: $group
|
||||||
Default runlevel......: $runlevel
|
Default runlevel......: $runlevel
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ PKG_CONFIG_LIBDIR=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig ./configure \
|
|||||||
--prefix=/usr --exec-prefix= \
|
--prefix=/usr --exec-prefix= \
|
||||||
--sysconfdir=/etc --localstatedir=/var \
|
--sysconfdir=/etc --localstatedir=/var \
|
||||||
--enable-dbus-plugin --enable-x11-common-plugin \
|
--enable-dbus-plugin --enable-x11-common-plugin \
|
||||||
--enable-alsa-utils-plugin --with-watchdog \
|
--enable-alsa-utils-plugin --without-watchdog \
|
||||||
--with-keventd --with-sulogin
|
--with-keventd --with-sulogin
|
||||||
|
|
||||||
echo
|
echo
|
||||||
|
|||||||
@@ -1,59 +0,0 @@
|
|||||||
Bootstrap
|
|
||||||
=========
|
|
||||||
|
|
||||||
0. Get bearings, disable kernel logs, initialize TTY and print banner,
|
|
||||||
unless `HOOK_BANNER` is defined, then call that instead
|
|
||||||
1. Prepare emergency shell, if enabled
|
|
||||||
2. Set up initial signal handlers
|
|
||||||
3. Set up default $PATH early
|
|
||||||
4. Mount `/proc` and `/sys`
|
|
||||||
5. Check kernel command line for `debug` to figure out log level
|
|
||||||
6. Load all `.so` plugins
|
|
||||||
7. Call `fsck` on file systems listed in `/etc/fstab`
|
|
||||||
8. Populate `/dev` using either udev or mdev, depending on system type
|
|
||||||
9. Parse `/etc/finit.conf`
|
|
||||||
10. Start built-in watchdog, if enabled and `WDT_DEVNODE` exists. This
|
|
||||||
means any WDT that requires a kernel module need to be either
|
|
||||||
compiled into the kernel, or insmod'ed in `/etc/finit.conf`
|
|
||||||
11. Load all `/etc/finit.d/*.conf` files and set hostname
|
|
||||||
12. Remount `/` read-write if `/` is listed in `/etc/fstab` without `ro`
|
|
||||||
13. Call 1st level hooks, `HOOK_ROOTFS_UP`
|
|
||||||
14. Mount all file systems listed in `/etc/fstab` and swap, if available.
|
|
||||||
On mount error `HOOK_MOUNT_ERROR` is called. After mount, regardless
|
|
||||||
of error, `HOOK_MOUNT_POST` is called
|
|
||||||
15. Enable SysV init signals
|
|
||||||
16. Call 2nd level hooks, `HOOK_BASEFS_UP`
|
|
||||||
17. Cleanup stale files from `/tmp/*` et al, handled by `bootmisc` plugin
|
|
||||||
18. Load kernel params from `/etc/sysctl.d/*.conf`, `/etc/sysctl.conf`
|
|
||||||
et al. (Supports all locations that SysV init does.), handled by
|
|
||||||
`procps` plugin
|
|
||||||
19. Start all 'S' runlevel tasks and services
|
|
||||||
20. Bring up loopback interface and all `/etc/network/interfaces`, if
|
|
||||||
the `.conf` setting `network <SCRIPT>` is set, it is called instead
|
|
||||||
21. Call 3rd level hooks, `HOOK_NETWORK_UP`
|
|
||||||
22. If `runparts <DIR>` is set, [run-parts(8)][] is called on `<DIR>`
|
|
||||||
23. Switch to the configured runlevel from `/etc/finit.conf`, default 2.
|
|
||||||
At every runlevel change all `*.conf` files in `/etc/finit.d/` are
|
|
||||||
(re)loaded and new services, tasks, and blocking run commands are
|
|
||||||
started. Provided they are allowed in the new runlevel and all of
|
|
||||||
their conditions, if any, are set.
|
|
||||||
24. Call 4th level hooks, `HOOK_SVC_UP`
|
|
||||||
25. Call `/etc/rc.local`, if it exists and is an executable shell script
|
|
||||||
26. Call 5th level (last) hooks, `HOOK_SYSTEM_UP`
|
|
||||||
27. Start all configured TTYs
|
|
||||||
|
|
||||||
In (19) and (23) tasks and services defined in `/etc/finit.conf` and
|
|
||||||
`/etc/finit.d/*.conf` are started.
|
|
||||||
|
|
||||||
Notice the seven hook points that are called at various point in the
|
|
||||||
bootstrap process. This is where plugins can extend the boot in any
|
|
||||||
way they please. There are other hook points available, for more on
|
|
||||||
this, see [plugins.md](plugins.md).
|
|
||||||
|
|
||||||
For instance, at `HOOK_BASEFS_UP` a plugin could read an XML file from a
|
|
||||||
USB stick, convert/copy its contents to the system's `/etc/` directory,
|
|
||||||
well before all 'S' runlevel tasks are started. This could be used with
|
|
||||||
system images that are created read-only and all configuration is stored
|
|
||||||
on external media.
|
|
||||||
|
|
||||||
[run-parts(8)]: http://manpages.debian.org/cgi-bin/man.cgi?query=run-parts
|
|
||||||
+16
-4
@@ -12,6 +12,15 @@ The `bool` setting is one of `on, off, true false, 1, 0`.
|
|||||||
* `debug`: Enable kernel debug. Debug messages are printed to the
|
* `debug`: Enable kernel debug. Debug messages are printed to the
|
||||||
console until Finit starts up, unless `loglevel=7` (below) is used.
|
console until Finit starts up, unless `loglevel=7` (below) is used.
|
||||||
|
|
||||||
|
* `fsck.mode=<auto,force,skip>`, default: `auto`, unless built with
|
||||||
|
`configure --enable-fastboot`, in which case the default is `skip`
|
||||||
|
|
||||||
|
* `fsck.repair=<preen,yes,no>`, default: `preen`, unless built with
|
||||||
|
`configure --enable-fsckfix`, in which case the default is `yes`.
|
||||||
|
This configure option also sets `fsck.mode=force`, unless fastboot
|
||||||
|
is selected at the same time. I.e., the `--enable-fastboot` build
|
||||||
|
option overrides the `fsck.mode` default value.
|
||||||
|
|
||||||
* `finit.cond=foo[,bar[,baz]]`: set `<boot/foo>` condition, optionally
|
* `finit.cond=foo[,bar[,baz]]`: set `<boot/foo>` condition, optionally
|
||||||
multiple conditions can be set using the same option, separated with a
|
multiple conditions can be set using the same option, separated with a
|
||||||
comma. Alternatively, multiple `foo.cond=arg` can be given. Each will
|
comma. Alternatively, multiple `foo.cond=arg` can be given. Each will
|
||||||
@@ -86,13 +95,16 @@ The `bool` setting is one of `on, off, true false, 1, 0`.
|
|||||||
the system booted in a limited fallback mode. See [config.md][]
|
the system booted in a limited fallback mode. See [config.md][]
|
||||||
for more information.
|
for more information.
|
||||||
|
|
||||||
|
This option can be disabled with `configure --without-rescue`
|
||||||
|
|
||||||
**Note:** in this mode `initctl` will not work. Correct the problem
|
**Note:** in this mode `initctl` will not work. Correct the problem
|
||||||
and use `reboot -f` to force reboot.
|
and use `reboot -f` to force reboot.
|
||||||
|
|
||||||
* `single`, or `S`: Single user mode, runlevel 1, in Finit. Useful to
|
* `single`, or `S`: Overrides the configured runlevel (default: 2) to go
|
||||||
debug problems with the regular runlevel. All services and TTYs in
|
to after bootstrap by forcing it to runlevel 1, this is also known
|
||||||
`[1]` will be started, so a `tty [1] @console nologin` configuration
|
as single user mode. Useful to debug startup problems. All services
|
||||||
presents you with a root console without login.
|
and TTYs in `[1]` will be started, so a `tty [1] @console nologin`
|
||||||
|
configuration presents you with a root console without login.
|
||||||
|
|
||||||
* `1-9`, except `6`: override the configured `runlevel`. Like the `S`
|
* `1-9`, except `6`: override the configured `runlevel`. Like the `S`
|
||||||
and `rescue`, giving a single number on the kernel command line tells
|
and `rescue`, giving a single number on the kernel command line tells
|
||||||
|
|||||||
@@ -27,6 +27,16 @@ specified separated by comma. Multiple conditions are logically AND'ed
|
|||||||
during evaluation, i.e. all conditions must be satisfied in order for a
|
during evaluation, i.e. all conditions must be satisfied in order for a
|
||||||
service to run.
|
service to run.
|
||||||
|
|
||||||
|
A special syntax, using a leading `!` in run/task/service conditions,
|
||||||
|
denote if a:
|
||||||
|
|
||||||
|
- service does not support `SIGHUP`
|
||||||
|
- run/task should not block runlevel changes (i.e., bootstrap)
|
||||||
|
|
||||||
|
Finit guarantees by default that all run/tasks run (at least) once
|
||||||
|
per runlevel. For most tasks this is a good default, for example
|
||||||
|
checking SSH host keys or loading keymap. However, for conditions
|
||||||
|
that are unlikely to happen it is not. (See example below.)
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
@@ -41,6 +51,19 @@ being created, i.e., the service's default readiness notification.
|
|||||||
asserted. I.e., if the Zebra process above stops or restarts, netd
|
asserted. I.e., if the Zebra process above stops or restarts, netd
|
||||||
will also stop or restart.
|
will also stop or restart.
|
||||||
|
|
||||||
|
Another example is `dropbear`, it does not support `SIGHUP`, but we can
|
||||||
|
also see optional sourcing of arguments from an environment file:
|
||||||
|
|
||||||
|
service [2345789] <!> env:-/etc/default/dropbear dropbear -F -R $DROPBEAR_ARGS -- Dropbear SSH daemon
|
||||||
|
|
||||||
|
Finally, the weird "block runlevel changes" example. Here we see what
|
||||||
|
happens when Finit receives `SIGPWR`, sent from a power daemon like
|
||||||
|
[powstatd(8)][]. A condition is asserted and a user can set up their
|
||||||
|
own task to act on it. We do not want this task to block Finit from
|
||||||
|
moving to the next runlevel after bootstrap, so we set `<!>`:
|
||||||
|
|
||||||
|
task [S0123456789] <!sys/pwr/fail> name:pwrfail initctl poweroff -- Power failure, shutting down
|
||||||
|
|
||||||
|
|
||||||
Triggering
|
Triggering
|
||||||
----------
|
----------
|
||||||
@@ -260,3 +283,5 @@ Therefore, any plugin that supplies Finit with conditions must ensure
|
|||||||
that their state is updated after each reconfiguration. This can be
|
that their state is updated after each reconfiguration. This can be
|
||||||
done by binding to the `HOOK_SVC_RECONF` hook. For an example of how
|
done by binding to the `HOOK_SVC_RECONF` hook. For an example of how
|
||||||
to do this, see `plugins/pidfile.c`.
|
to do this, see `plugins/pidfile.c`.
|
||||||
|
|
||||||
|
[powstatd(8)]: https://manpages.ubuntu.com/manpages/trusty/en/man8/powstatd.8.html
|
||||||
|
|||||||
+317
-100
@@ -28,6 +28,7 @@ Finit Configuration
|
|||||||
* [TTYs and Consoles](#ttys-and-consoles)
|
* [TTYs and Consoles](#ttys-and-consoles)
|
||||||
* [Non-privileged Services](#non-privileged-services)
|
* [Non-privileged Services](#non-privileged-services)
|
||||||
* [Redirecting Output](#redirecting-output)
|
* [Redirecting Output](#redirecting-output)
|
||||||
|
* [SysV Init Compatibility](#sysv-init-compatibility)
|
||||||
* [Rescue Mode](#rescue-mode)
|
* [Rescue Mode](#rescue-mode)
|
||||||
* [Limitations](#limitations)
|
* [Limitations](#limitations)
|
||||||
* [/etc/finit.conf](#etcfinitconf)
|
* [/etc/finit.conf](#etcfinitconf)
|
||||||
@@ -45,31 +46,86 @@ Plugins start at [hook points](plugins.md#hooks) and can run various set
|
|||||||
up, or install event handlers that later provide runtime services, e.g.,
|
up, or install event handlers that later provide runtime services, e.g.,
|
||||||
PID file monitoring, or [conditions](conditions.md).
|
PID file monitoring, or [conditions](conditions.md).
|
||||||
|
|
||||||
|
> **Tip:** see [SysV Init Compatibility](#sysv-init-compatibility) for
|
||||||
|
> help to quickly get going with an existing SysV or BusyBox init setup.
|
||||||
|
|
||||||
|
|
||||||
### Configuration Files
|
### Configuration Files
|
||||||
|
|
||||||
Originally Finit was configured using a single file, `/etc/finit.conf`.
|
Originally Finit was configured using a single file, `/etc/finit.conf`,
|
||||||
Although still possible, today we recommended using the Apache-style
|
and although still possible to use a single configuration file, today
|
||||||
`available/*.conf` and `enabled/*.conf` layaout. These are called
|
the following layout is recommended:
|
||||||
dynamic services, in contrast to static -- the only difference being
|
|
||||||
where they are installed and if the `initctl` tool can manage them.
|
|
||||||
|
|
||||||
/etc/
|
/
|
||||||
|- finit.d/
|
|- etc/
|
||||||
| |- available/
|
| |- finit.d/
|
||||||
| | `- my-service.conf
|
| | |- available/
|
||||||
: |- enabled/
|
| | | `- my-service.conf
|
||||||
: | `- my-service.conf -> ../available/my-service.conf
|
| : |- enabled/
|
||||||
: :
|
| : | `- my-service.conf -> ../available/my-service.conf
|
||||||
: |- static-service.conf
|
| : :
|
||||||
: `- another-static.conf # eg. bootstrap run/task commands
|
| : |- static-service.conf
|
||||||
:
|
| : `- another-static.conf
|
||||||
`- finit.conf # global settings
|
| :
|
||||||
|
| `- finit.conf
|
||||||
|
|- lib
|
||||||
|
| `- finit/
|
||||||
|
| `- system/
|
||||||
|
| |- 10-hotplug.conf
|
||||||
|
| `- ...
|
||||||
|
`- run/
|
||||||
|
`- finit/
|
||||||
|
`- system/
|
||||||
|
|- dbus.conf
|
||||||
|
|- keventd.conf
|
||||||
|
|- runparts.conf
|
||||||
|
|- watchdogd.conf
|
||||||
|
`- ...
|
||||||
|
|
||||||
|
Configuration files in `/etc` are provided by the user, or projects like
|
||||||
|
[finit-skel](https://github.com/troglobit/finit-skel) and extended by
|
||||||
|
the user.
|
||||||
|
|
||||||
|
The files in `/lib/finit/system/*.conf` are system critical services and
|
||||||
|
setup provided by Finit, e.g. udev/mdev that must run very early at system
|
||||||
|
bootstrap. This system directory was introduced in Finit v4.4 to replace
|
||||||
|
the hard-coded services provided by plugins before. All .conf files in this
|
||||||
|
directory be either replaced by a system administrator or overridden by a
|
||||||
|
file with the same name in `/etc/finit.d/`.
|
||||||
|
|
||||||
|
The files in `/run/finit/system/*.conf` are created by plugins and Finit
|
||||||
|
bundled services like runparts, the [watchdog](#watchdog), and `keventd`
|
||||||
|
if they are enabled. Like `/lib/finit/system/*.conf`, these files can
|
||||||
|
be overridden by file with the same name in `/etc/finit.d/`.
|
||||||
|
|
||||||
|
Services in the `available/` and `enabled/` sub-directories are called
|
||||||
|
dynamic services, in contrast to static services -- the only difference
|
||||||
|
being where they are installed and if the `initctl` tool can manage them
|
||||||
|
with the `enable` and `disable` commands. An administrator can always
|
||||||
|
create files and symlinks manually.
|
||||||
|
|
||||||
At bootstrap, and `initctl reload`, all .conf files are read, starting
|
At bootstrap, and `initctl reload`, all .conf files are read, starting
|
||||||
with `finit.conf`, then, in alphabetical order, all `finit.d/*.conf`
|
with `finit.conf`, then `/lib/finit/system/*.conf`, `finit.d/*.conf`,
|
||||||
files, and finally (still in alphabetical order) all `enabled/*.conf`
|
and finally all `finit.d/enabled/*.conf` files. Each directory is a
|
||||||
files.
|
unique group, where files within each group are sorted alphabetically.
|
||||||
|
|
||||||
|
**Example:**
|
||||||
|
|
||||||
|
/lib/finit/system/10-hotplug.conf
|
||||||
|
/lib/finit/system/90-testserv.conf
|
||||||
|
/run/finit/system/dbus.conf
|
||||||
|
/run/finit/system/runparts.conf
|
||||||
|
/etc/finit.d/10-abc.conf
|
||||||
|
/etc/finit.d/20-abc.conf
|
||||||
|
/etc/finit.d/enabled/1-aaa.conf
|
||||||
|
/etc/finit.d/enabled/1-abc.conf
|
||||||
|
|
||||||
|
The resulting combined configuration is read line by line, each `run`,
|
||||||
|
`task`, and `service` added to an ordered list that ensures they are
|
||||||
|
started in the same order. This is important because of the blocking
|
||||||
|
properties of the `run` statement. For an example on the relation of
|
||||||
|
`service` and `run` statements, and dependency handling between them,
|
||||||
|
see [Conditional Loading](#conditional-loading), below.
|
||||||
|
|
||||||
> **Note:** the `finit.conf` and `finit.d/` names are only defaults.
|
> **Note:** the `finit.conf` and `finit.d/` names are only defaults.
|
||||||
> They can be changed at compile-time with two `configure` options:
|
> They can be changed at compile-time with two `configure` options:
|
||||||
@@ -118,21 +174,25 @@ layout, as specified in the [FHS][]:
|
|||||||
|- spool/
|
|- spool/
|
||||||
`- tmp/
|
`- tmp/
|
||||||
|
|
||||||
Finit starts (very early) by mounting `/dev`, `/proc/`, and `/sys`,
|
Finit starts by mounting the critical file systems `/dev`, `/proc/`, and
|
||||||
unless they (i.e., `/dev`) are already mounted. When all plugins and
|
`/sys`, unless they are already mounted. When all plugins and other,
|
||||||
other, core Finit functions, have been set up, all relevant filesystems
|
core Finit functions, have been set up, all relevant filesystems (where
|
||||||
(`PASS > 0`) are checked and mounted from the selected `fstab`, either
|
`PASS > 0`) are checked and mounted from the selected `fstab`, either
|
||||||
the default `/etc/fstab`, or any custom one selected from the command
|
the default `/etc/fstab`, or any custom one selected from the command
|
||||||
line, or at build time.
|
line, or at build time.
|
||||||
|
|
||||||
Any file system not listed `fstab` are automatically mounted by Finit,
|
To provide a smooth ride, file system not listed in the given `fstab`,
|
||||||
as listed above, provided their respective mount point exists.
|
e.g. `/tmp` and `/run`, are automatically mounted by Finit, as listed
|
||||||
|
above, provided their respective mount point exists.
|
||||||
|
|
||||||
With all filesystems mounted, Finit calls `swapon`.
|
With all filesystems mounted, Finit calls `swapon`.
|
||||||
|
|
||||||
|
> **Tip:** to see what happens when all filesystems are mounted, have a
|
||||||
|
> look at the [`bootmisc.so` plugin](plugins.md).
|
||||||
|
|
||||||
At shutdown, and after having stopped all services and other lingering
|
At shutdown, and after having stopped all services and other lingering
|
||||||
processes killed, filesystems are unmounted in the reverse order, and
|
processes have been killed, filesystems are unmounted in the reverse
|
||||||
`swapoff` is called.
|
order, and `swapoff` is called.
|
||||||
|
|
||||||
[FHS]: https://refspecs.linuxfoundation.org/FHS_3.0/fhs/index.html
|
[FHS]: https://refspecs.linuxfoundation.org/FHS_3.0/fhs/index.html
|
||||||
|
|
||||||
@@ -146,24 +206,30 @@ processes killed, filesystems are unmounted in the reverse order, and
|
|||||||
- ` 0`: shutdown
|
- ` 0`: shutdown
|
||||||
|
|
||||||
Runlevels are declared per service/run/task/sysv command. Starting in
|
Runlevels are declared per service/run/task/sysv command. Starting in
|
||||||
runlevel S ([bootStrap](bootstrap.md)), usually only for tasks supposed
|
runlevel S (bootStrap), usually only for tasks supposed to run once at
|
||||||
to run once at boot, and services like `syslogd`, which you need to
|
boot, and services like `syslogd`, which you need to start and run
|
||||||
start and run throughout the whole time your system is up. Before `S`
|
throughout the whole time your system is up.
|
||||||
is started, however, Finit performs a lot of housekeeping tasks like
|
|
||||||
mounting all filesystems, calling `fsck` if needed, and making sure the
|
Before `S` is started, however, Finit performs a lot of housekeeping
|
||||||
everything is OK.
|
tasks like mounting all filesystems, calling `fsck` if needed, and
|
||||||
|
making sure the everything is OK.
|
||||||
|
|
||||||
task [S] /lib/console-setup/console-setup.sh
|
task [S] /lib/console-setup/console-setup.sh
|
||||||
service [S12345] env:-/etc/default/rsyslog rsyslogd -n $RSYSLOGD_ARGS
|
service [S12345] env:-/etc/default/rsyslog rsyslogd -n $RSYSLOGD_ARGS
|
||||||
|
|
||||||
After runlevel S, Finit proceeds to runlevel 2. (This can be changed in
|
After runlevel S, Finit proceeds to runlevel 2. This can be changed in
|
||||||
`/etc/finit.conf` using the `runlevel N` directive.) Before starting
|
`/etc/finit.conf` using the `runlevel N` directive, or by a script
|
||||||
the services in runlevel 2, Finit first stops everything that is not
|
running in runlevel S that calls, e.g., `initctl runlevel 9`. The
|
||||||
allowed to run in 2, and then brings up networking. Networking is
|
latter is useful if startup scripts detect problems outside of Finit's
|
||||||
expected to be available in all runlevels except: S, 1 (single user
|
control, e.g., critical services/devices missing or hardware problems.
|
||||||
level), 6, and 0. Networking is enabled either by the `network script`
|
|
||||||
directive, or if you have an `/etc/network/interfaces` file, Finit calls
|
Before starting the services in runlevel 2, Finit first stops everything
|
||||||
`ifup -a` -- at the very least the loopback interface is brought up.
|
that is not allowed to run in 2, and then brings up networking.
|
||||||
|
Networking is expected to be available in all runlevels except: S, 1
|
||||||
|
(single user level), 6, and 0. Networking is enabled either by the
|
||||||
|
`network script` directive, or if you have an `/etc/network/interfaces`
|
||||||
|
file, Finit calls `ifup -a` -- at the very least the loopback interface
|
||||||
|
is brought up.
|
||||||
|
|
||||||
> **Note:** when moving from runlevel S to 2, all run/task/services that
|
> **Note:** when moving from runlevel S to 2, all run/task/services that
|
||||||
> were constrained to runlevel S only are dropped from bookkeeping. So
|
> were constrained to runlevel S only are dropped from bookkeeping. So
|
||||||
@@ -459,7 +525,7 @@ following directives:
|
|||||||
|
|
||||||
|
|
||||||
> **Note:** not all directives are available in `/etc/finit.d/*.conf`
|
> **Note:** not all directives are available in `/etc/finit.d/*.conf`
|
||||||
> and some directives are only available at [bootstrap][], runlevel `S`,
|
> and some directives are only available at bootstrap, runlevel `S`,
|
||||||
> see [Limitations](#limitations) below for details.
|
> see [Limitations](#limitations) below for details.
|
||||||
|
|
||||||
|
|
||||||
@@ -472,7 +538,7 @@ the contents of that file is used.
|
|||||||
|
|
||||||
Deprecated. We recommend using `/etc/hostname` instead.
|
Deprecated. We recommend using `/etc/hostname` instead.
|
||||||
|
|
||||||
> **Note:** only read and executed in runlevel S ([bootstrap][]).
|
> **Note:** only read and executed in runlevel S (bootstrap).
|
||||||
|
|
||||||
|
|
||||||
### Kernel Modules
|
### Kernel Modules
|
||||||
@@ -490,7 +556,7 @@ BusyBox mdev tool, add to `/etc/mdev.conf`:
|
|||||||
|
|
||||||
$MODALIAS=.* root:root 0660 @modprobe -b "$MODALIAS"
|
$MODALIAS=.* root:root 0660 @modprobe -b "$MODALIAS"
|
||||||
|
|
||||||
> **Note:** only read and executed in runlevel S ([bootstrap][]).
|
> **Note:** only read and executed in runlevel S (bootstrap).
|
||||||
|
|
||||||
|
|
||||||
### Networking
|
### Networking
|
||||||
@@ -503,7 +569,7 @@ Deprecated. We recommend using dedicated task/run stanzas per runlevel,
|
|||||||
or `/etc/network/interfaces` if you have a system with `ifupdown`, like
|
or `/etc/network/interfaces` if you have a system with `ifupdown`, like
|
||||||
Debian, Ubuntu, Linux Mint, or an embedded BusyBox system.
|
Debian, Ubuntu, Linux Mint, or an embedded BusyBox system.
|
||||||
|
|
||||||
> **Note:** only read and executed in runlevel S ([bootstrap][]).
|
> **Note:** only read and executed in runlevel S (bootstrap).
|
||||||
|
|
||||||
|
|
||||||
### Alternate finit.d/
|
### Alternate finit.d/
|
||||||
@@ -558,7 +624,7 @@ stanzas can share the same rlimits if they are in the same .conf.
|
|||||||
|
|
||||||
**Syntax:** `runlevel <N>`
|
**Syntax:** `runlevel <N>`
|
||||||
|
|
||||||
The system runlevel to go to after [bootstrap][] (S) has completed. `N`
|
The system runlevel to go to after bootstrap (S) has completed. `N`
|
||||||
is the runlevel number 0-9, where 6 is reserved for reboot and 0 for
|
is the runlevel number 0-9, where 6 is reserved for reboot and 0 for
|
||||||
halt.
|
halt.
|
||||||
|
|
||||||
@@ -567,40 +633,61 @@ Finit disables networking in this mode.
|
|||||||
|
|
||||||
*Default:* 2
|
*Default:* 2
|
||||||
|
|
||||||
> **Note:** only read and executed in runlevel S ([bootstrap][]).
|
> **Note:** only read and executed in runlevel S (bootstrap).
|
||||||
|
|
||||||
|
|
||||||
### One-shot Commands (sequence)
|
### One-shot Commands (sequence)
|
||||||
|
|
||||||
**Syntax:** `run [LVLS] <COND> /path/to/cmd ARGS -- Optional description`
|
**Syntax:** `run [LVLS] <COND> /path/to/cmd ARGS -- Optional description`
|
||||||
|
|
||||||
One-shot command to run in sequence when entering a runlevel, with
|
|
||||||
optional arguments and description.
|
|
||||||
|
|
||||||
`run` commands are guaranteed to be completed before running the next
|
|
||||||
command. Highly useful if true serialization is needed.
|
|
||||||
|
|
||||||
> `<COND>` is described in the [Services](#services) section.
|
> `<COND>` is described in the [Services](#services) section.
|
||||||
|
|
||||||
|
One-shot command to run in sequence when entering a runlevel, with
|
||||||
|
optional arguments and description. `run` commands are guaranteed to be
|
||||||
|
completed before running the next command. Useful when serialization is
|
||||||
|
required.
|
||||||
|
|
||||||
|
> **Warning:** try to avoid the `run` command. It blocks much of the
|
||||||
|
> functionality in Finit, like (re)starting other (perhaps crashing)
|
||||||
|
> services while a `run` task is executing. Use other synchronization
|
||||||
|
> mechanisms instead, like conditions.
|
||||||
|
|
||||||
|
Incomplete list of unsupported `initctl` commands in `run` tasks:
|
||||||
|
|
||||||
|
- `initctl runlevel N`, setting runlevel
|
||||||
|
- `initctl reboot`
|
||||||
|
- `initctl halt`
|
||||||
|
- `initctl poweroff`
|
||||||
|
- `initctl suspend`
|
||||||
|
|
||||||
|
To prevent `initctl` from calling Finit when enabling and disabling
|
||||||
|
services from inside a `run` task, use the `--force` option. See
|
||||||
|
also the `--quiet` and `--batch` options.
|
||||||
|
|
||||||
|
|
||||||
### One-shot Commands (parallel)
|
### One-shot Commands (parallel)
|
||||||
|
|
||||||
**Syntax:** `task [LVLS] <COND> /path/to/cmd ARGS -- Optional description`
|
**Syntax:** `task [LVLS] <COND> /path/to/cmd ARGS -- Optional description`
|
||||||
|
|
||||||
|
> `<COND>` is described in the [Services](#services) section.
|
||||||
|
|
||||||
One-shot like 'run', but starts in parallel with the next command.
|
One-shot like 'run', but starts in parallel with the next command.
|
||||||
|
|
||||||
Both `run` and `task` commands are run in a shell, so pipes and
|
Both `run` and `task` commands are run in a shell, so basic pipes and
|
||||||
redirects can be freely used:
|
redirects can be used:
|
||||||
|
|
||||||
task [s] echo "foo" | cat >/tmp/bar
|
task [s] echo "foo" | cat >/tmp/bar
|
||||||
|
|
||||||
> `<COND>` is described in the [Services](#services) section.
|
Please note, `;`, `&&`, `||`, and similar are *not supported*. Any
|
||||||
|
non-trivial constructs are better placed in a separate shell script.
|
||||||
|
|
||||||
|
|
||||||
### SysV Init Scripts
|
### SysV Init Scripts
|
||||||
|
|
||||||
**Syntax:** `sysv [LVLS] <COND> /path/to/init-script -- Optional description`
|
**Syntax:** `sysv [LVLS] <COND> /path/to/init-script -- Optional description`
|
||||||
|
|
||||||
|
> `<COND>` is described in the [Services](#services) section.
|
||||||
|
|
||||||
Similar to `task` is the `sysv` stanza, which can be used to call SysV
|
Similar to `task` is the `sysv` stanza, which can be used to call SysV
|
||||||
style scripts. The primary intention for this command is to be able to
|
style scripts. The primary intention for this command is to be able to
|
||||||
re-use much of existing setup and init scripts in Linux distributions.
|
re-use much of existing setup and init scripts in Linux distributions.
|
||||||
@@ -618,7 +705,7 @@ file, but rather watch that file for the resulting forked-off PID. This
|
|||||||
syntax also works for forking daemons that do not have a command line
|
syntax also works for forking daemons that do not have a command line
|
||||||
option to run it in the foreground, more on this below in `service`.
|
option to run it in the foreground, more on this below in `service`.
|
||||||
|
|
||||||
> `<COND>` is described in the [Services](#services) section.
|
> **Tip:** see also [SysV Init Compatibility](#sysv-init-compatibility).
|
||||||
|
|
||||||
|
|
||||||
### Services
|
### Services
|
||||||
@@ -813,45 +900,106 @@ These script actions *must terminate*, so they have a default execution
|
|||||||
time of 3 seconds before they are SIGKILLed, this can be adjusted using
|
time of 3 seconds before they are SIGKILLed, this can be adjusted using
|
||||||
the above `kill:SEC` syntax.
|
the above `kill:SEC` syntax.
|
||||||
|
|
||||||
|
#### Conditional Loading
|
||||||
|
|
||||||
|
Finit support conditional loading of stanzas. The following example is
|
||||||
|
take from the `system/hotplug.conf` file in the Finit distribution.
|
||||||
|
Here we only show a simplified subset.
|
||||||
|
|
||||||
|
Starting with the `nowarn` option.
|
||||||
|
|
||||||
|
service nowarn name:udevd pid:udevd /lib/systemd/systemd-udevd
|
||||||
|
service nowarn name:udevd pid:udevd udevd
|
||||||
|
|
||||||
|
When loading the .conf file Finit looks for `/lib/systemd/systemd-udevd`
|
||||||
|
if that is not found Finit automatically logs a warning. The `nowarn`
|
||||||
|
option disables this warning so that the second line can be evaluated,
|
||||||
|
which also provides a service named `udevd`.
|
||||||
|
|
||||||
|
run nowarn if:udevd <pid/udevd> :1 udevadm settle -t 0
|
||||||
|
|
||||||
|
This line is only loaded if we know of a service named `udevd`. Again,
|
||||||
|
we do not warn if `udevadm` is not found, Execution will also stop here
|
||||||
|
until the PID condition is asserted, i.e., Finit detecting udevd has
|
||||||
|
started.
|
||||||
|
|
||||||
|
run nowarn conflict:udevd [S] mdev -s -- Populating device tree
|
||||||
|
|
||||||
|
If `udevd` is not available, we try to run `mdev`, but if that is not
|
||||||
|
found, again we do not warn.
|
||||||
|
|
||||||
|
Conditional loading statements can also be negated, so the previous stanza
|
||||||
|
can also be written as:
|
||||||
|
|
||||||
|
run nowarn if:!udevd [S] mdev -s -- Populating device tree
|
||||||
|
|
||||||
|
The reason for using `confict` in this example is that a conflict can be
|
||||||
|
resolved. Stanzas marked with `conflict:foo` are rechecked at runtime.
|
||||||
|
|
||||||
|
#### Conditional Execution
|
||||||
|
|
||||||
|
Similar to conditional loading of stanzas there is conditional runtime
|
||||||
|
execution. This can be confusing at first, since Finit already has a
|
||||||
|
condition subsystem, but this is more akin to the qualification to a
|
||||||
|
runlevel. E.g., a `task [123]` is qualified to run only in runlevel 1,
|
||||||
|
2, and 3. It is not considered for other runlevels.
|
||||||
|
|
||||||
|
Conditional execution qualify a run/task/service based on a condition.
|
||||||
|
Consider this (simplified) example from the Infix operating system:
|
||||||
|
|
||||||
|
run [S] name:startup <pid/sysrepo> confd -b --load startup-config
|
||||||
|
run [S] if:<usr/fail-startup> name:failure <pid/sysrepo> confd --load failure-config
|
||||||
|
|
||||||
|
The two run statements reside in the same .conf file so Finit runs them
|
||||||
|
in true sequence. If loading the file `startup-config` fails confd sets
|
||||||
|
the condition `usr/fail-startup`, thus allowing the next run statement
|
||||||
|
to load `failure-config`.
|
||||||
|
|
||||||
|
Notice critical the difference between `<pid/sysrepo>` condition and
|
||||||
|
`if:<usr/fail-startup>`. The former is a condition for starting and the
|
||||||
|
latter is a condition to check if a run/task/service is qualified to
|
||||||
|
even be considered.
|
||||||
|
|
||||||
|
Conditional execution statements can also be negated, so provided the
|
||||||
|
file loaded did the opposite, i.e., set a condition on success, the
|
||||||
|
previous stanza can also be written as:
|
||||||
|
|
||||||
|
run [S] if:<!usr/startup-ok> name:failure <pid/sysrepo> confd ...
|
||||||
|
|
||||||
### Run-parts Scripts
|
### Run-parts Scripts
|
||||||
|
|
||||||
**Syntax:** `runparts <DIR>`
|
**Syntax:** `runparts [progress] [sysv] <DIR>`
|
||||||
|
|
||||||
Call [run-parts(8)][] on `DIR` to run start scripts. All executable
|
Call [run-parts(8)][] on `DIR` to run start scripts. All executable
|
||||||
files, or scripts, in the directory are called, in alphabetic order.
|
files in the directory are called, in alphabetic order. The scripts in
|
||||||
The scripts in this directory are executed at the very end of runlevel
|
this directory are executed at the very end of runlevel `S`.
|
||||||
`S`, [bootstrap][].
|
|
||||||
|
|
||||||
A common use-case for runparts scripts is to create and enable/disable
|
A common use-case for runparts scripts is to create and enable/disable
|
||||||
services, which Finit will then apply when changing runlevel from S to
|
services, which Finit will then apply when changing runlevel from S to
|
||||||
whatever the next runlevel is set to be (default 2). E.g., generate a
|
whatever the next runlevel is set to be (default 2). E.g., generate a
|
||||||
`/etc/chrony.conf` and `initctl enable chronyd`.
|
`/etc/chrony.conf` and call `initctl enable chronyd`.
|
||||||
|
|
||||||
|
**Options:**
|
||||||
|
|
||||||
|
- `progress`: display the progress of each script being executed
|
||||||
|
- `sysv`: run only SysV style scripts, i.e., `SNNfoo`, or `KNNbar`,
|
||||||
|
where `NN` is a number (0-99).
|
||||||
|
|
||||||
|
If global debug mode is enabled, the `runparts` program is also called
|
||||||
|
with the debug flag.
|
||||||
|
|
||||||
**Limitations:**
|
**Limitations:**
|
||||||
|
|
||||||
Scripts called from `runparts`, or hook scripts (see below), are limited
|
Scripts called from `runparts`, or hook scripts (see below), are limited
|
||||||
in what they can do and expect from Finit:
|
in their interaction with Finit. Like the standalone `run` stanza and
|
||||||
|
the `/etc/rc.local` shell script, Finit waits for their completion
|
||||||
|
before continuing. None of them can issue commands to start, stop, or
|
||||||
|
restart other services. Also, ensure all your services and programs
|
||||||
|
either terminate or start in the background or you will block Finit.
|
||||||
|
|
||||||
1. Finit is single threaded and all scripts executed from these two
|
> **Note:** `runparts` scrips are only read and executed in runlevel S.
|
||||||
mechanisms are limited to file system operations (early or late
|
> See [hook scripts](plugins.md#hooks) for other ways to run scripts at
|
||||||
hooks may not have write access!) and standard UNIX programs.
|
> certain points during the complete lifetime of the system.
|
||||||
2. Thus, it is *not possible* to call `initctl` to query status of
|
|
||||||
services since that calls Finit over the `/run/finit/socket`.
|
|
||||||
3. Confusingly enough, there are some commands to `initctl` that are
|
|
||||||
available; `ls`, `enable`, `disable`, `touch`, `create`, `delete`,
|
|
||||||
and all the `cond` commands. Because all these are basically just
|
|
||||||
wrappers for manipulating files (again, write access for early/late
|
|
||||||
hooks may not be available).
|
|
||||||
|
|
||||||
Also, similar to the `/etc/rc.local` shell script, make sure that all
|
|
||||||
your services and programs either terminate or start in the background
|
|
||||||
or you will block Finit.
|
|
||||||
|
|
||||||
> **Note:** `runparts` scrips are only read and executed in runlevel S
|
|
||||||
> ([bootstrap][]). See [hook scripts](plugins.md#hooks) for other ways
|
|
||||||
> to run scripts at certain points during the complete lifetime of the
|
|
||||||
> system.
|
|
||||||
|
|
||||||
**Recommendations:**
|
**Recommendations:**
|
||||||
|
|
||||||
@@ -964,8 +1112,8 @@ can be omitted to keep the kernel default.
|
|||||||
tty [12345] @console noclear vt220
|
tty [12345] @console noclear vt220
|
||||||
|
|
||||||
On really bare bones systems, or for board bringup, Finit can give you a
|
On really bare bones systems, or for board bringup, Finit can give you a
|
||||||
shell prompt as soon as [bootstrap][] is done, without opening any
|
shell prompt as soon as bootstrap is done, without opening any device
|
||||||
device node:
|
node:
|
||||||
|
|
||||||
tty [12345789] notty
|
tty [12345789] notty
|
||||||
|
|
||||||
@@ -1044,6 +1192,72 @@ sync(2) has been called, twice.
|
|||||||
> finally written.
|
> finally written.
|
||||||
|
|
||||||
|
|
||||||
|
SysV Init Compatibility
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
It is not possible to run unmodified SysV init systems with Finit. This
|
||||||
|
was never the intention and is not the strength of Finit. However, it
|
||||||
|
comes with a few SysV Init compatibility features to ease the transition
|
||||||
|
from a serialized boot process.
|
||||||
|
|
||||||
|
### `runparts DIRECTORY`
|
||||||
|
|
||||||
|
For a directory with traditional start/stop scripts that should run, in
|
||||||
|
order, at bootstrap, Finit provides the `runparts` directive. It runs
|
||||||
|
in runlevel S, at the very end of it (before calling `/etc/rc.local`)
|
||||||
|
making it perfect for most scenarios.
|
||||||
|
|
||||||
|
For syntax details, see [Run-parts Scripts](#run-parts-scripts) above.
|
||||||
|
Here is an example take from a Debian installation:
|
||||||
|
|
||||||
|
runparts /etc/rc2.d
|
||||||
|
|
||||||
|
Files in these directories are usually named `SNNfoo` and `KNNfoo`,
|
||||||
|
which Finit knows about and automatically appends the correct argument:
|
||||||
|
|
||||||
|
/bin/sh -c /etc/rc2.d/S01openbsd-inetd start
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
/bin/sh -c /etc/rc0.d/K01openbsd-inetd stop
|
||||||
|
|
||||||
|
Files that do not match this pattern are started similarly but without
|
||||||
|
the extra command line argument.
|
||||||
|
|
||||||
|
|
||||||
|
### Start/Stop Scripts
|
||||||
|
|
||||||
|
For syntax details, see [SysV Init Scripts](#sysv-init-scripts), above.
|
||||||
|
Here follows an example taken from a Debian installation:
|
||||||
|
|
||||||
|
sysv [2345] <pid/syslogd> /etc/init.d/openbsd-inetd -- OpenBSD inet daemon
|
||||||
|
|
||||||
|
The init script header could be parsed to extract `Default-Start:` and
|
||||||
|
other parameters for the `sysv` command to Finit. There is currently no
|
||||||
|
way to detail a generic syslogd dependency in Finit, so `Should-Start:`
|
||||||
|
in the header must be mapped to the condition system in Finit using an
|
||||||
|
absolute reference, here we depend on the sysklogd project's syslogd.
|
||||||
|
|
||||||
|
### `/etc/rc.local`
|
||||||
|
|
||||||
|
One often requested feature, early on, was a way to run a site specific
|
||||||
|
script to set up, e.g., static routes or firewall rules. A user can add
|
||||||
|
a `task` or `run` command in the Finit configuration for this, but for
|
||||||
|
compatibility reasons the more widely know `/etc/rc.local` is used if
|
||||||
|
it exists, and is executable. It is called very late in the boot process
|
||||||
|
when the system has left runlevel S, stopped all old and started all new
|
||||||
|
services in the target runlevel (default 2).
|
||||||
|
|
||||||
|
> In Finit releases before v4.5 this script blocked Finit execution and
|
||||||
|
> made it as good as impossible to call `initctl` during that time.
|
||||||
|
|
||||||
|
### `init q`
|
||||||
|
|
||||||
|
When `/sbin/finit` is installed as `/sbin/init`, it is possible to use
|
||||||
|
`init q` to reload the configuration. This is the same as calling
|
||||||
|
`initctl reload`.
|
||||||
|
|
||||||
|
|
||||||
Rescue Mode
|
Rescue Mode
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
@@ -1051,6 +1265,10 @@ Finit supports a rescue mode which is activated by the `rescue` option
|
|||||||
on the kernel command line. See [cmdline docs](cmdline.md) for how to
|
on the kernel command line. See [cmdline docs](cmdline.md) for how to
|
||||||
activate it.
|
activate it.
|
||||||
|
|
||||||
|
This rescue mode can be disabled at configure time using:
|
||||||
|
|
||||||
|
configure --without-rescue
|
||||||
|
|
||||||
The rescue mode comes in two flavors; *traditional* and *fallback*.
|
The rescue mode comes in two flavors; *traditional* and *fallback*.
|
||||||
|
|
||||||
> **Note:** in this mode `initctl` will not work. Use the `-f` flag to
|
> **Note:** in this mode `initctl` will not work. Use the `-f` flag to
|
||||||
@@ -1060,15 +1278,17 @@ The rescue mode comes in two flavors; *traditional* and *fallback*.
|
|||||||
### Traditional
|
### Traditional
|
||||||
|
|
||||||
This is what most users expect. A very early maintenance login prompt,
|
This is what most users expect. A very early maintenance login prompt,
|
||||||
served by the bundled `/libexec/finit/sulogin` program, or the standard
|
served by the system `sulogin` program from util-linux, or BusyBox. If
|
||||||
`sulogin` from util-linux or BusyBox is searched for in the UNIX default
|
that is not found in `$PATH`, the bundled `/libexec/finit/sulogin`
|
||||||
`$PATH`. If a successful login is made, or the user exits (Ctrl-D), the
|
program is used instead. If a successful login is made, or if the user
|
||||||
rescue mode is ended and the system boots up normally.
|
exits (Ctrl-D), the rescue mode is ended and the system boots up
|
||||||
|
normally.
|
||||||
|
|
||||||
> **Note:** if the user (UID 0 and GID 0) does not have a password, or
|
> **Note:** the bundled sulogin in Finit can at configure time be given
|
||||||
> __the account is locked__, the user is presented with a password-less
|
> another user than the default (root). If the sulogin user does not
|
||||||
> `"Press enter to enter maintenance mode."`, prompt which opens up a
|
> have a password, or __the account is locked__, the user is presented
|
||||||
> root shell.
|
> with a password-less `"Press enter to enter maintenance mode."`,
|
||||||
|
> prompt which opens up a root shell.
|
||||||
|
|
||||||
|
|
||||||
### Fallback
|
### Fallback
|
||||||
@@ -1128,12 +1348,11 @@ Watchdog
|
|||||||
When built `--with-watchdog` a separate service is built and installed
|
When built `--with-watchdog` a separate service is built and installed
|
||||||
in `/libexec/finit/watchdogd`. If this exists at runtime, and the WDT
|
in `/libexec/finit/watchdogd`. If this exists at runtime, and the WDT
|
||||||
device node exists, Finit will start it and treat it as the elected
|
device node exists, Finit will start it and treat it as the elected
|
||||||
watchdog service to delegate its reboot to. See [bootstrap][] for
|
watchdog service to delegate its reboot to. This delegation is to
|
||||||
details. This delegation is to ensure that the system is rebooted by a
|
ensure that the system is rebooted by a hardware watchdog timer -- on
|
||||||
hardware watchdog timer -- on many embedded systems this is crucial to
|
many embedded systems this is crucial to ensure all circuits on the
|
||||||
ensure all circuits on the board are properly reset for the next boot,
|
board are properly reset for the next boot, in effect ensuring the
|
||||||
in effect ensuring the system works the same after both a power-on and
|
system works the same after both a power-on and reboot event.
|
||||||
reboot event.
|
|
||||||
|
|
||||||
The delegation is performed at the very last steps of system shutdown,
|
The delegation is performed at the very last steps of system shutdown,
|
||||||
if reboot has been selected and an elected watchdog is known, first a
|
if reboot has been selected and an elected watchdog is known, first a
|
||||||
@@ -1155,8 +1374,6 @@ device descriptor. If the kernel driver has been built without this,
|
|||||||
the only option is to remove `/libexec/finit/watchdogd` or build without
|
the only option is to remove `/libexec/finit/watchdogd` or build without
|
||||||
it at configure time.
|
it at configure time.
|
||||||
|
|
||||||
[bootstrap]: bootstrap.md
|
|
||||||
|
|
||||||
|
|
||||||
keventd
|
keventd
|
||||||
-------
|
-------
|
||||||
|
|||||||
+19
-7
@@ -28,9 +28,16 @@ For your convenience a set of *optional* plugins are available:
|
|||||||
system and runs at `HOOK_BASEFS_UP`. The `/var`, `/run`, and `/dev`
|
system and runs at `HOOK_BASEFS_UP`. The `/var`, `/run`, and `/dev`
|
||||||
file systems must be writable for this plugin to work.
|
file systems must be writable for this plugin to work.
|
||||||
|
|
||||||
Note: On an embedded system both `/var` and `/run` can be `tmpfs` RAM
|
This plugin is a wrapper for the [tmpfiles.d(5)][] implementation that
|
||||||
disks and `/dev` is usually a `devtmpfs`. This must be defined in the
|
Finit has. Capable but limited: no aging, attributes, or subvolumes.
|
||||||
`/etc/fstab` file and in the Linux kernel config.
|
|
||||||
|
By default, `/lib/finit/tmpfiles.d` carries all the default .conf
|
||||||
|
files distributed with Finit. It is read first but can be overridden
|
||||||
|
by any of the standard tmpfiles.d directories, e.g. `/etc/tmpfiles.d`.
|
||||||
|
|
||||||
|
> **Note:** On an embedded system both `/var` and `/run` can be `tmpfs`
|
||||||
|
> RAM disks and `/dev` is usually a `devtmpfs`. This must be defined
|
||||||
|
> in the `/etc/fstab` file and in the Linux kernel config.
|
||||||
|
|
||||||
* *dbus.so*: Setup and start system message bus, D-Bus, at boot.
|
* *dbus.so*: Setup and start system message bus, D-Bus, at boot.
|
||||||
_Optional plugin._
|
_Optional plugin._
|
||||||
@@ -50,8 +57,11 @@ For your convenience a set of *optional* plugins are available:
|
|||||||
customized at build-time using the `--with-hook-scripts-path=PATH`
|
customized at build-time using the `--with-hook-scripts-path=PATH`
|
||||||
argument to `configure`.
|
argument to `configure`.
|
||||||
|
|
||||||
* *hotplug.so*: Setup and start either udev or mdev hotplug daemon, if
|
* *hotplug.so*: Replaced with `/lib/finit/system/10-hotplug.conf`, which
|
||||||
available. Enabled by default.
|
checks for `udevd` and `mdev` at boot. This file can be overridden by a
|
||||||
|
file in `/etc/finit.d/10-hotplug.conf`.
|
||||||
|
|
||||||
|
Enabled by default.
|
||||||
|
|
||||||
> See the [Services](config.md#services) section in the configuration
|
> See the [Services](config.md#services) section in the configuration
|
||||||
> guide for an example how to run `mdevd`, alternative to plain mdev.
|
> guide for an example how to run `mdevd`, alternative to plain mdev.
|
||||||
@@ -136,7 +146,7 @@ hook points:
|
|||||||
**Example:**
|
**Example:**
|
||||||
|
|
||||||
$ mkdir -p /libexec/finit/hook/sys/down
|
$ mkdir -p /libexec/finit/hook/sys/down
|
||||||
$ cat <<EOF >/libexec/finit/hook/sys/foo.sh
|
$ cat <<EOF >/libexec/finit/hook/sys/down/foo.sh
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
echo 'I run just before the reboot() syscall at shutdown/reboot'
|
echo 'I run just before the reboot() syscall at shutdown/reboot'
|
||||||
echo 'I have access to /dev since devtmpfs is exempt from umount'
|
echo 'I have access to /dev since devtmpfs is exempt from umount'
|
||||||
@@ -146,7 +156,7 @@ hook points:
|
|||||||
fi
|
fi
|
||||||
exit 0
|
exit 0
|
||||||
EOF
|
EOF
|
||||||
$ chmod +x /libexec/finit/hook/sys/foo.sh
|
$ chmod +x /libexec/finit/hook/sys/down/foo.sh
|
||||||
|
|
||||||
> **Note:** to use hook scripts, even for pre-bootstrap and pre-shutdown
|
> **Note:** to use hook scripts, even for pre-bootstrap and pre-shutdown
|
||||||
> tasks, you must build with `configure --enable-hook-scripts-plugin`.
|
> tasks, you must build with `configure --enable-hook-scripts-plugin`.
|
||||||
@@ -217,3 +227,5 @@ Plugins like `tty.so` extend finit by acting on events, they are called
|
|||||||
I/O plugins and are called from the finit main loop when `poll()`
|
I/O plugins and are called from the finit main loop when `poll()`
|
||||||
detects an event. See the source code for `plugins/*.c` for more help
|
detects an event. See the source code for `plugins/*.c` for more help
|
||||||
and ideas.
|
and ideas.
|
||||||
|
|
||||||
|
[tmpfiles.d(5)]: https://www.freedesktop.org/software/systemd/man/tmpfiles.d.html
|
||||||
|
|||||||
@@ -0,0 +1,141 @@
|
|||||||
|
_cond()
|
||||||
|
{
|
||||||
|
initctl -pt cond dump | awk '{print $4}' | sed 's/<\(.*\)>/\1/'
|
||||||
|
}
|
||||||
|
|
||||||
|
_ident()
|
||||||
|
{
|
||||||
|
if [ -n "$1" ]; then
|
||||||
|
initctl ident | grep -q $1
|
||||||
|
else
|
||||||
|
initctl ident
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_svc()
|
||||||
|
{
|
||||||
|
initctl ls -pt | grep $1 | sed "s/.*\/\(.*\)/\1/g" | sort -u
|
||||||
|
}
|
||||||
|
|
||||||
|
_enabled()
|
||||||
|
{
|
||||||
|
echo "$(_svc enabled)"
|
||||||
|
}
|
||||||
|
|
||||||
|
_available()
|
||||||
|
{
|
||||||
|
all=$(mktemp)
|
||||||
|
ena=$(mktemp)
|
||||||
|
echo "$(_svc available)" >$all
|
||||||
|
echo "$(_svc enabled)" >$ena
|
||||||
|
grep -v -f $ena $all
|
||||||
|
rm $all $ena
|
||||||
|
}
|
||||||
|
|
||||||
|
# Determine first non-option word. Usually the command
|
||||||
|
_firstword() {
|
||||||
|
local firstword i
|
||||||
|
|
||||||
|
firstword=
|
||||||
|
for ((i = 1; i < ${#COMP_WORDS[@]}; ++i)); do
|
||||||
|
if [[ ${COMP_WORDS[i]} != -* ]]; then
|
||||||
|
firstword=${COMP_WORDS[i]}
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo $firstword
|
||||||
|
}
|
||||||
|
|
||||||
|
# Determine last non-option word. Uusally a sub-command
|
||||||
|
_lastword() {
|
||||||
|
local lastword i
|
||||||
|
|
||||||
|
lastword=
|
||||||
|
for ((i = 1; i < ${#COMP_WORDS[@]}; ++i)); do
|
||||||
|
if [[ ${COMP_WORDS[i]} != -* ]] && [[ -n ${COMP_WORDS[i]} ]] && [[ ${COMP_WORDS[i]} != $cur ]]; then
|
||||||
|
lastword=${COMP_WORDS[i]}
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo $lastword
|
||||||
|
}
|
||||||
|
|
||||||
|
_initctl()
|
||||||
|
{
|
||||||
|
local cur command
|
||||||
|
|
||||||
|
cur=${COMP_WORDS[COMP_CWORD]}
|
||||||
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||||
|
firstword=$(_firstword)
|
||||||
|
lastword=$(_lastword)
|
||||||
|
|
||||||
|
commands="status cond debug help kill ls log version list enable \
|
||||||
|
disable touch show cat edit create delete reload start \
|
||||||
|
stop restart signal cgroup ps top plugins runlevel reboot \
|
||||||
|
halt poweroff suspend utmp"
|
||||||
|
cond_cmds="set get clear status dump"
|
||||||
|
cond_types="hook net pid service task usr"
|
||||||
|
signals="int term hup stop tstp cont usr1 usr2 pwr"
|
||||||
|
options="-b --batch \
|
||||||
|
-c --create \
|
||||||
|
-d --debug \
|
||||||
|
-f --force \
|
||||||
|
-h --help \
|
||||||
|
-j --json \
|
||||||
|
-n --noerr \
|
||||||
|
-1 --once \
|
||||||
|
-p --plain \
|
||||||
|
-q --quiet \
|
||||||
|
-t --no-heading \
|
||||||
|
-v --verbose \
|
||||||
|
-V --version"
|
||||||
|
|
||||||
|
case "${firstword}" in
|
||||||
|
enable)
|
||||||
|
COMPREPLY=($(compgen -W "$(_available)" -- $cur))
|
||||||
|
;;
|
||||||
|
disable|touch)
|
||||||
|
COMPREPLY=($(compgen -W "$(_enabled)" -- $cur))
|
||||||
|
;;
|
||||||
|
show|cat|edit|delete)
|
||||||
|
COMPREPLY=($(compgen -W "$(_svc .)" -- $cur))
|
||||||
|
;;
|
||||||
|
start|stop|restart|log|status)
|
||||||
|
COMPREPLY=($(compgen -W "$(_ident)" -- $cur))
|
||||||
|
;;
|
||||||
|
signal|kill)
|
||||||
|
if $(_ident "${prev}"); then
|
||||||
|
COMPREPLY=($(compgen -W "$signals" -- $cur))
|
||||||
|
else
|
||||||
|
COMPREPLY=($(compgen -W "$(_ident)" -- $cur))
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
cond)
|
||||||
|
case "${lastword}" in
|
||||||
|
set|clear)
|
||||||
|
compopt -o nospace
|
||||||
|
COMPREPLY=($(compgen -W "usr/" -- $cur))
|
||||||
|
;;
|
||||||
|
get)
|
||||||
|
COMPREPLY=($(compgen -W "$(_cond)" -- $cur))
|
||||||
|
;;
|
||||||
|
dump)
|
||||||
|
COMPREPLY=($(compgen -W "$cond_types" -- $cur))
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
COMPREPLY=($(compgen -W "$cond_cmds" -- $cur))
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
COMPREPLY=($(compgen -W "$commands" -- $cur))
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [[ $cur == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "$options" -- $cur))
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
complete -F _initctl initctl
|
||||||
+1
-1
@@ -275,7 +275,7 @@ The following condition families are available today:
|
|||||||
Linux netlink events, e.g. net/route/default, net/eth0/up, and
|
Linux netlink events, e.g. net/route/default, net/eth0/up, and
|
||||||
net/et0/running
|
net/et0/running
|
||||||
.It Cm pid
|
.It Cm pid
|
||||||
PID files basd on the service declaration
|
PID files based on the service declaration
|
||||||
.Cm name:id ,
|
.Cm name:id ,
|
||||||
gives the condition pid/name:id
|
gives the condition pid/name:id
|
||||||
.It Cm service
|
.It Cm service
|
||||||
|
|||||||
+50
-26
@@ -2,7 +2,7 @@
|
|||||||
.\" First parameter, NAME, should be all caps
|
.\" First parameter, NAME, should be all caps
|
||||||
.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
|
.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
|
||||||
.\" other parameters are allowed: see man(7), man(1)
|
.\" other parameters are allowed: see man(7), man(1)
|
||||||
.Dd Apr 24, 2023
|
.Dd July 11, 2023
|
||||||
.Dt FINIT.CONF 5 SMM
|
.Dt FINIT.CONF 5 SMM
|
||||||
.Os Linux
|
.Os Linux
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@@ -12,40 +12,64 @@
|
|||||||
.Nm /etc/finit.conf
|
.Nm /etc/finit.conf
|
||||||
.Nm /etc/finit.d/*.conf
|
.Nm /etc/finit.d/*.conf
|
||||||
.Nm /etc/finit.d/available/*.conf
|
.Nm /etc/finit.d/available/*.conf
|
||||||
|
.Nm /etc/finit.d/enabled/*.conf
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
.Nm finit
|
.Nm Finit
|
||||||
can be configured using only the original
|
based systems can be set up with a single file:
|
||||||
.Pa /etc/finit.conf
|
.Pa /etc/finit.conf .
|
||||||
file or in combination with
|
This is the traditional way of doing it which can be ideal for some
|
||||||
.Pa /etc/finit.d/*.conf .
|
setups since it gives a great overview of the system configuration.
|
||||||
Useful for package-based Linux distributions \(em each package can
|
|
||||||
provide its own "script" file.
|
|
||||||
.Pp
|
.Pp
|
||||||
.Bl -tag -width /etc/finit.d/*.conf -offset indent -compact
|
More comprehensive setups, however, require more careful planning.
|
||||||
.It Pa /etc/finit.conf
|
The recommendation is per-package
|
||||||
Main configuration file
|
.Cm *.conf
|
||||||
.It Pa /etc/finit.d/*.conf
|
files in
|
||||||
Snippets, usually one service per file
|
.Pa /etc/finit.d/available/ .
|
||||||
.El
|
This allows end users to enable and disable parts of the system
|
||||||
|
configuration at runtime. Finit tracks which tasks and services belong
|
||||||
|
to a given file, so that when the user calls
|
||||||
|
.Cm initctl reload
|
||||||
|
to activate the changes they have made, only the affected tasks and
|
||||||
|
services are stopped, started, or restarted. Hence, this approach is
|
||||||
|
useful for modern package-based Linux distributions.
|
||||||
.Pp
|
.Pp
|
||||||
Not all configuration directives are available in
|
The following sections describe the more of this in detail, starting
|
||||||
.Pa /etc/finit.d/*.conf
|
with files, the file format, and available directives. Remember to
|
||||||
and some directives are only available at bootstrap, runlevel
|
also visit the other manual pages (references at the bottom).
|
||||||
.Cm S ,
|
|
||||||
see the section
|
|
||||||
.Sx Limitations
|
|
||||||
below for details.
|
|
||||||
.Sh FILES
|
.Sh FILES
|
||||||
.Bl -tag -width /etc/finit.d/available/*.conf -compact
|
.Bl -tag -width /etc/finit.d/available/*.conf -compact
|
||||||
.It Pa /etc/finit.conf
|
.It Pa /etc/finit.conf
|
||||||
Main configuration file
|
Main configuration file, optional
|
||||||
.It Pa /etc/finit.d/*.conf
|
.It Pa /etc/finit.d/*.conf
|
||||||
Static service definitions
|
Static (system) service definitions
|
||||||
.It Pa /etc/finit.d/available/*.conf
|
.It Pa /etc/finit.d/available/*.conf
|
||||||
Available services
|
Available (installed) services
|
||||||
.It Pa /etc/finit.d/enabled/*.conf
|
.It Pa /etc/finit.d/enabled/*.conf
|
||||||
Enabled services, symlinks from available
|
Enabled services (symlink back)
|
||||||
.El
|
.El
|
||||||
|
.Pp
|
||||||
|
Static services,
|
||||||
|
.Cm .conf
|
||||||
|
files in
|
||||||
|
.Pa /etc/finit.d/ ,
|
||||||
|
cannot be enabled or disabled using
|
||||||
|
.Cm initctl [enable | disable] service[.conf] .
|
||||||
|
An enabled service is a symlink back to the corresponding
|
||||||
|
.Cm ../available/
|
||||||
|
service
|
||||||
|
.Cm .conf
|
||||||
|
file. Please use the
|
||||||
|
.Cm initctl
|
||||||
|
tool to manage these symlinks to ensure proper operation.
|
||||||
|
.Pp
|
||||||
|
.Sy NOTE:
|
||||||
|
Previous versions of
|
||||||
|
.Nm Finit
|
||||||
|
created symlinks in
|
||||||
|
.Pa /etc/finit.d/
|
||||||
|
if
|
||||||
|
.Pa /etc/finit.d/enabled/
|
||||||
|
was missing, this is as of v4.4 not supported.
|
||||||
.Sh FILE FORMAT
|
.Sh FILE FORMAT
|
||||||
The file format is line based, empty lines and comments, lines starting
|
The file format is line based, empty lines and comments, lines starting
|
||||||
with `#', are ignored. A configuration directive starts with a keyword
|
with `#', are ignored. A configuration directive starts with a keyword
|
||||||
@@ -960,6 +984,6 @@ settings in
|
|||||||
.Xr finit 8 ,
|
.Xr finit 8 ,
|
||||||
.Xr initctl 8
|
.Xr initctl 8
|
||||||
.Sh AUTHORS
|
.Sh AUTHORS
|
||||||
.Nm finit
|
.Nm Finit
|
||||||
was conceived and reverse engineered by Claudio Matsuoka. Since v1.0,
|
was conceived and reverse engineered by Claudio Matsuoka. Since v1.0,
|
||||||
maintained by Joachim Wiberg, with contributions by many others.
|
maintained by Joachim Wiberg, with contributions by many others.
|
||||||
|
|||||||
@@ -240,6 +240,11 @@ Show top-like listing based on cgroups.
|
|||||||
List installed plugins.
|
List installed plugins.
|
||||||
.It Nm Ar runlevel Op Ar 0-9
|
.It Nm Ar runlevel Op Ar 0-9
|
||||||
Show or set runlevel: 0 halt, 6 reboot.
|
Show or set runlevel: 0 halt, 6 reboot.
|
||||||
|
.Pp
|
||||||
|
If called at boot (runlevel S) to set the runlevel, Finit only schedules
|
||||||
|
the change, effectively overriding the configured runlevel from
|
||||||
|
.Pa /etc/finit.conf .
|
||||||
|
Useful to trigger a fail-safe mode, or similar.
|
||||||
.It Nm Ar reboot
|
.It Nm Ar reboot
|
||||||
Reboot system, default if
|
Reboot system, default if
|
||||||
.Cm reboot
|
.Cm reboot
|
||||||
|
|||||||
+3
-4
@@ -83,6 +83,7 @@ static char *dbus_pidfn(void)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
*pos = 0;
|
*pos = 0;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
@@ -142,7 +143,7 @@ static void setup(void *arg)
|
|||||||
|
|
||||||
/* Generate machine id for dbus */
|
/* Generate machine id for dbus */
|
||||||
if (whichp("dbus-uuidgen"))
|
if (whichp("dbus-uuidgen"))
|
||||||
run_interactive("dbus-uuidgen --ensure", "Creating machine UUID for D-Bus");
|
run_interactive("dbus-uuidgen --ensure", "Verifying D-Bus machine UUID");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Register service with Finit
|
* Register service with Finit
|
||||||
@@ -156,9 +157,7 @@ static void setup(void *arg)
|
|||||||
snprintf(line, sizeof(line), "[S123456789] cgroup.system name:dbus %s %s -- %s",
|
snprintf(line, sizeof(line), "[S123456789] cgroup.system name:dbus %s %s -- %s",
|
||||||
cmd, DBUS_ARGS, DBUS_DESC);
|
cmd, DBUS_ARGS, DBUS_DESC);
|
||||||
|
|
||||||
if (service_register(SVC_TYPE_SERVICE, line, global_rlimit, NULL))
|
conf_save_service(SVC_TYPE_SERVICE, line, "dbus.conf");
|
||||||
err(1, "Failed registering %s", DBUS_DAEMON);
|
|
||||||
|
|
||||||
free(cmd);
|
free(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ static int modules_load(const char *file, int index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
while ((line = fparseln(fp, NULL, NULL, NULL, 0))) {
|
while ((line = fparseln(fp, NULL, NULL, NULL, 0))) {
|
||||||
char cmd[CMD_SIZE * 2], *mod, *args, *set;
|
char cmd[CMD_SIZE], *mod, *args, *set;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* fparseln() skips regular UNIX comments only.
|
* fparseln() skips regular UNIX comments only.
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ static void setup(void *arg)
|
|||||||
|
|
||||||
touch("/etc/resolvconf/run/enable-updates");
|
touch("/etc/resolvconf/run/enable-updates");
|
||||||
chdir("/etc/resolvconf/run/interface");
|
chdir("/etc/resolvconf/run/interface");
|
||||||
run_parts("/etc/resolvconf/update.d", "-i", NULL, 0);
|
run_parts("/etc/resolvconf/update.d", "-i", NULL, 0, 0);
|
||||||
chdir("/");
|
chdir("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ initctl
|
|||||||
keventd
|
keventd
|
||||||
logit
|
logit
|
||||||
reboot
|
reboot
|
||||||
|
runparts
|
||||||
sulogin
|
sulogin
|
||||||
watchdogd
|
watchdogd
|
||||||
Makefile
|
Makefile
|
||||||
|
|||||||
+9
-2
@@ -8,7 +8,7 @@ AM_LDFLAGS = -export-dynamic
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
sbin_PROGRAMS = finit initctl
|
sbin_PROGRAMS = finit initctl
|
||||||
pkglibexec_PROGRAMS = getty logit
|
pkglibexec_PROGRAMS = getty logit runparts
|
||||||
if SULOGIN
|
if SULOGIN
|
||||||
pkglibexec_PROGRAMS += sulogin
|
pkglibexec_PROGRAMS += sulogin
|
||||||
endif
|
endif
|
||||||
@@ -19,6 +19,8 @@ if WATCHDOGD
|
|||||||
pkglibexec_PROGRAMS += watchdogd
|
pkglibexec_PROGRAMS += watchdogd
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
dist_pkglibexec_SCRIPTS = coldplug
|
||||||
|
|
||||||
finit_pkglibdir = $(pkglibdir)
|
finit_pkglibdir = $(pkglibdir)
|
||||||
finit_pkglib_SCRIPTS = rescue.conf sample.conf
|
finit_pkglib_SCRIPTS = rescue.conf sample.conf
|
||||||
|
|
||||||
@@ -32,6 +34,11 @@ keventd_CFLAGS = -W -Wall -Wextra -std=gnu99
|
|||||||
keventd_CFLAGS += $(lite_CFLAGS)
|
keventd_CFLAGS += $(lite_CFLAGS)
|
||||||
keventd_LDADD = $(lite_LIBS)
|
keventd_LDADD = $(lite_LIBS)
|
||||||
|
|
||||||
|
runparts_SOURCES = runparts.c
|
||||||
|
runparts_CFLAGS = -W -Wall -Wextra -std=gnu99
|
||||||
|
runparts_CFLAGS += $(lite_CFLAGS)
|
||||||
|
runparts_LDADD = $(lite_LIBS)
|
||||||
|
|
||||||
sulogin_SOURCES = sulogin.c
|
sulogin_SOURCES = sulogin.c
|
||||||
sulogin_CFLAGS = -W -Wall -Wextra -std=gnu99
|
sulogin_CFLAGS = -W -Wall -Wextra -std=gnu99
|
||||||
sulogin_LDADD = -lcrypt
|
sulogin_LDADD = -lcrypt
|
||||||
@@ -54,7 +61,7 @@ finit_SOURCES = api.c cgroup.c cgroup.h \
|
|||||||
mdadm.c mount.c \
|
mdadm.c mount.c \
|
||||||
pid.c pid.h \
|
pid.c pid.h \
|
||||||
plugin.c plugin.h private.h \
|
plugin.c plugin.h private.h \
|
||||||
schedule.c schedule.h \
|
runparts.c schedule.c schedule.h \
|
||||||
service.c service.h \
|
service.c service.h \
|
||||||
sig.c sig.h \
|
sig.c sig.h \
|
||||||
sm.c sm.h \
|
sm.c sm.h \
|
||||||
|
|||||||
@@ -367,7 +367,6 @@ static void api_cb(uev_t *w, void *arg, int events)
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (rq.cmd) {
|
switch (rq.cmd) {
|
||||||
case INIT_CMD_RUNLVL:
|
|
||||||
case INIT_CMD_RELOAD:
|
case INIT_CMD_RELOAD:
|
||||||
case INIT_CMD_START_SVC:
|
case INIT_CMD_START_SVC:
|
||||||
case INIT_CMD_RESTART_SVC:
|
case INIT_CMD_RESTART_SVC:
|
||||||
@@ -378,7 +377,7 @@ static void api_cb(uev_t *w, void *arg, int events)
|
|||||||
case INIT_CMD_POWEROFF:
|
case INIT_CMD_POWEROFF:
|
||||||
case INIT_CMD_SUSPEND:
|
case INIT_CMD_SUSPEND:
|
||||||
if (IS_RESERVED_RUNLEVEL(runlevel)) {
|
if (IS_RESERVED_RUNLEVEL(runlevel)) {
|
||||||
warnx("Unsupported command in runlevel S and 6.");
|
warnx("Unsupported command in runlevel S and 6/0.");
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@@ -387,6 +386,14 @@ static void api_cb(uev_t *w, void *arg, int events)
|
|||||||
|
|
||||||
switch (rq.cmd) {
|
switch (rq.cmd) {
|
||||||
case INIT_CMD_RUNLVL:
|
case INIT_CMD_RUNLVL:
|
||||||
|
/* Allow changing cfglevel in runlevel S */
|
||||||
|
if (IS_RESERVED_RUNLEVEL(runlevel)) {
|
||||||
|
if (runlevel != INIT_LEVEL) {
|
||||||
|
warnx("Cannot abort runlevel 6/0.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (rq.runlevel) {
|
switch (rq.runlevel) {
|
||||||
case 's':
|
case 's':
|
||||||
case 'S':
|
case 'S':
|
||||||
@@ -400,7 +407,12 @@ static void api_cb(uev_t *w, void *arg, int events)
|
|||||||
halt = SHUT_OFF;
|
halt = SHUT_OFF;
|
||||||
if (lvl == 6)
|
if (lvl == 6)
|
||||||
halt = SHUT_REBOOT;
|
halt = SHUT_REBOOT;
|
||||||
service_runlevel(lvl);
|
|
||||||
|
/* User requested change in next runlevel */
|
||||||
|
if (runlevel == INIT_LEVEL)
|
||||||
|
cfglevel = lvl;
|
||||||
|
else
|
||||||
|
service_runlevel(lvl);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
Executable
+11
@@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# With the daemon mode ('mdev -df') we no longer need the hotplug helper
|
||||||
|
echo "" > /proc/sys/kernel/hotplug
|
||||||
|
|
||||||
|
# Wait for 'mdev -df' to set up its event queue.
|
||||||
|
sleep 1
|
||||||
|
|
||||||
|
# Trigger 'add' event for all devices and subsystems to load all modules
|
||||||
|
# and any firmware needed by the hardware.
|
||||||
|
find /sys/devices -name uevent -print | while IFS='' read X; do echo add > $X; done
|
||||||
+10
-2
@@ -222,8 +222,16 @@ static int do_delete(const char *fpath, const struct stat *sb, int tflag, struct
|
|||||||
static void cond_delpath(const char *path)
|
static void cond_delpath(const char *path)
|
||||||
{
|
{
|
||||||
nftw(path, do_delete, 20, FTW_DEPTH);
|
nftw(path, do_delete, 20, FTW_DEPTH);
|
||||||
if (remove(path) && errno != ENOENT)
|
if (remove(path)) {
|
||||||
err(1, "Failed removing condition path %s", path);
|
switch (errno) {
|
||||||
|
case ENOENT: /* Ignore */
|
||||||
|
case ENOTEMPTY: /* Only at shutdown and for directories */
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
err(1, "Failed removing condition path %s", path);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int cond_set_path(const char *path, enum cond_state next)
|
int cond_set_path(const char *path, enum cond_state next)
|
||||||
|
|||||||
+195
-15
@@ -62,8 +62,29 @@ static TAILQ_HEAD(, env_entry) env_list = TAILQ_HEAD_INITIALIZER(env_list);
|
|||||||
struct rlimit initial_rlimit[RLIMIT_NLIMITS];
|
struct rlimit initial_rlimit[RLIMIT_NLIMITS];
|
||||||
struct rlimit global_rlimit[RLIMIT_NLIMITS];
|
struct rlimit global_rlimit[RLIMIT_NLIMITS];
|
||||||
|
|
||||||
|
/*
|
||||||
|
* --enable-fastboot => fsck_mode: NULL => no fsck by default
|
||||||
|
* --enable-fsckfix => fsck_mode: "-f" + fsck_repair: "y"
|
||||||
|
*/
|
||||||
|
#ifdef FSCK_FIX
|
||||||
|
# ifdef FAST_BOOT
|
||||||
|
char *fsck_mode = NULL;
|
||||||
|
# else
|
||||||
|
char *fsck_mode = "-f";
|
||||||
|
# endif
|
||||||
|
char *fsck_repair = "-y";
|
||||||
|
#else
|
||||||
|
# ifdef FAST_BOOT
|
||||||
|
char *fsck_mode = NULL;
|
||||||
|
# else
|
||||||
char *fsck_mode = "";
|
char *fsck_mode = "";
|
||||||
|
# endif
|
||||||
char *fsck_repair = "-p";
|
char *fsck_repair = "-p";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
char *runparts = NULL;
|
||||||
|
int runparts_progress;
|
||||||
|
int runparts_sysv;
|
||||||
|
|
||||||
char cgroup_current[16]; /* cgroup.NAME sets current cgroup for a set of services */
|
char cgroup_current[16]; /* cgroup.NAME sets current cgroup for a set of services */
|
||||||
|
|
||||||
@@ -246,10 +267,12 @@ static void parse_arg(char *arg)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef RESCUE_MODE
|
||||||
if (string_compare(arg, "rescue") || string_compare(arg, "recover")) {
|
if (string_compare(arg, "rescue") || string_compare(arg, "recover")) {
|
||||||
rescue = 1;
|
rescue = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (string_compare(arg, "single") || string_compare(arg, "S")) {
|
if (string_compare(arg, "single") || string_compare(arg, "S")) {
|
||||||
single = 1;
|
single = 1;
|
||||||
@@ -391,6 +414,79 @@ void conf_saverc(void)
|
|||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Called at bootstrap to log execution order (for debug)
|
||||||
|
*/
|
||||||
|
void conf_save_exec_order(svc_t *svc, char *cmdline, int result)
|
||||||
|
{
|
||||||
|
const char *fn = _PATH_VARRUN "finit/exec.order";
|
||||||
|
const char *ststr = !result ? "[ OK ]" : "[FAIL]";
|
||||||
|
static char *prepared = NULL;
|
||||||
|
int first = !fexist(fn);
|
||||||
|
FILE *fp;
|
||||||
|
|
||||||
|
fp = fopen(fn, "a+");
|
||||||
|
if (!fp) {
|
||||||
|
err(1, "failed writing to %s", fn);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (first) {
|
||||||
|
fprintf(fp, "# Execution order of run/task/services at bootstrap\n");
|
||||||
|
fprintf(fp, "# ST TYPE COMMAND LINE (DESC)\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result == -1) {
|
||||||
|
int len;
|
||||||
|
|
||||||
|
len = snprintf(NULL, 0, " %-7s %-64s (%s)", svc_typestr(svc), cmdline, svc->desc);
|
||||||
|
if (len > 0) {
|
||||||
|
if (prepared)
|
||||||
|
free(prepared);
|
||||||
|
prepared = malloc(++len);
|
||||||
|
if (!prepared)
|
||||||
|
goto done;
|
||||||
|
snprintf(prepared, len, " %-7s %-64s (%s)", svc_typestr(svc), cmdline, svc->desc);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (prepared) {
|
||||||
|
memcpy(prepared, ststr, strlen(ststr));
|
||||||
|
fprintf(fp, "%s\n", prepared);
|
||||||
|
free(prepared);
|
||||||
|
prepared = NULL;
|
||||||
|
} else {
|
||||||
|
fprintf(fp, "%s %-7s %-64s (%s)\n", ststr, svc_typestr(svc), cmdline, svc->desc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
done:
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Called by plugins and similar that dynamically generate system services
|
||||||
|
*/
|
||||||
|
void conf_save_service(int type, char *cfg, char *file)
|
||||||
|
{
|
||||||
|
char fn[256];
|
||||||
|
svc_t foo;
|
||||||
|
FILE *fp;
|
||||||
|
|
||||||
|
mkpath(FINIT_RUNPATH_, 0755);
|
||||||
|
snprintf(fn, sizeof(fn), "%s/%s", FINIT_RUNPATH_, file);
|
||||||
|
if (fexist(fn))
|
||||||
|
warnx("File %s already exists, overwriting.", fn);
|
||||||
|
fp = fopen(fn, "w");
|
||||||
|
if (!fp) {
|
||||||
|
err(1, "Failed creating %s", fn);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foo.type = type;
|
||||||
|
fprintf(fp, "# Generated by finit:%s()\n", __func__);
|
||||||
|
fprintf(fp, "%s %s\n", svc_typestr(&foo), cfg);
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sets, and makes a note of, all KEY=VALUE lines in a given .conf line
|
* Sets, and makes a note of, all KEY=VALUE lines in a given .conf line
|
||||||
* from finit.conf, or other .conf file. Note, PATH is always reset in
|
* from finit.conf, or other .conf file. Note, PATH is always reset in
|
||||||
@@ -560,11 +656,22 @@ void conf_parse_cond(svc_t *svc, char *cond)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* First character must be '!' if SIGHUP is not supported. */
|
/*
|
||||||
|
* First character must be '!' if:
|
||||||
|
* - service: SIGHUP is not supported
|
||||||
|
* - run/task: Do not block bootstrap
|
||||||
|
*/
|
||||||
ptr = cond;
|
ptr = cond;
|
||||||
if (ptr[i] == '!') {
|
if (ptr[i] == '!') {
|
||||||
svc->sighup = 0;
|
|
||||||
ptr++;
|
ptr++;
|
||||||
|
|
||||||
|
if (svc_is_runtask(svc)) {
|
||||||
|
/* see service_runtask_clean() */
|
||||||
|
svc->sighup = 1;
|
||||||
|
svc->once = 1;
|
||||||
|
} else {
|
||||||
|
svc->sighup = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (ptr[i] != '>' && ptr[i] != 0)
|
while (ptr[i] != '>' && ptr[i] != 0)
|
||||||
@@ -776,6 +883,15 @@ static int parse_static(char *line, int is_rcsd)
|
|||||||
|
|
||||||
if (BOOTSTRAP && MATCH_CMD(line, "runparts ", x)) {
|
if (BOOTSTRAP && MATCH_CMD(line, "runparts ", x)) {
|
||||||
if (runparts) free(runparts);
|
if (runparts) free(runparts);
|
||||||
|
runparts_progress = runparts_sysv = 0;
|
||||||
|
while (x) {
|
||||||
|
if (MATCH_CMD(x, "progress", x))
|
||||||
|
runparts_progress = 1;
|
||||||
|
else if (MATCH_CMD(x, "sysv", x))
|
||||||
|
runparts_sysv = 1;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
runparts = strdup(strip_line(x));
|
runparts = strdup(strip_line(x));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -862,7 +978,7 @@ static int parse_static(char *line, int is_rcsd)
|
|||||||
|
|
||||||
service_interval = val * 1000; /* to milliseconds */
|
service_interval = val * 1000; /* to milliseconds */
|
||||||
if (disabled)
|
if (disabled)
|
||||||
service_init();
|
service_init(NULL);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1083,6 +1199,14 @@ int conf_reload(void)
|
|||||||
*/
|
*/
|
||||||
memcpy(global_rlimit, initial_rlimit, sizeof(global_rlimit));
|
memcpy(global_rlimit, initial_rlimit, sizeof(global_rlimit));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* When built with --disable-rescue mode many other 'if (rescue)'
|
||||||
|
* code paths are #ifdeffed out. This one, and the ones in the
|
||||||
|
* plugins, are not because a hook or plugin can still trigger
|
||||||
|
* the alternative rescue.conf instead of finit.conf. This for
|
||||||
|
* very advanced use-cases where files on /etc are generated at
|
||||||
|
* bootstrap, including users and passwords, from other sources.
|
||||||
|
*/
|
||||||
if (rescue) {
|
if (rescue) {
|
||||||
int rc;
|
int rc;
|
||||||
char line[80] = "tty [12345789] rescue";
|
char line[80] = "tty [12345789] rescue";
|
||||||
@@ -1112,20 +1236,51 @@ int conf_reload(void)
|
|||||||
* but are now regular files that can be overridden by files in
|
* but are now regular files that can be overridden by files in
|
||||||
* /etc/finit.d -- similar to how tmfiles.d(5) work. E.g., add
|
* /etc/finit.d -- similar to how tmfiles.d(5) work. E.g., add
|
||||||
* an override .conf, or an ignore by symlinking to /dev/null
|
* an override .conf, or an ignore by symlinking to /dev/null
|
||||||
|
*
|
||||||
|
* The .conf files (and run/task/service stanzas) are parsed and
|
||||||
|
* started in order. Each directory is sorted alphanumerically
|
||||||
|
* and then the result is appended to the overall order:
|
||||||
|
*
|
||||||
|
* /lib/finit/system/10-hotplug.conf
|
||||||
|
* /lib/finit/system/90-testserv.conf
|
||||||
|
* /run/finit/system/dbus.conf
|
||||||
|
* /run/finit/system/tty.conf
|
||||||
|
* /etc/finit.d/10-abc.conf
|
||||||
|
* /etc/finit.d/20-abc.conf
|
||||||
|
* /etc/finit.d/enabled/1-aaa.conf
|
||||||
|
* /etc/finit.d/enabled/1-abc.conf
|
||||||
|
* /etc/finit.d/enabled/2-aaa.conf
|
||||||
*/
|
*/
|
||||||
glob_append(&gl, 0, "%s/*.conf", finit_rcsd);
|
glob_append(&gl, 0, "%s/*.conf", FINIT_SYSPATH_);
|
||||||
glob_append(&gl, 1, "%s/*.conf", FINIT_SYSPATH);
|
glob_append(&gl, 1, "%s/*.conf", FINIT_RUNPATH_);
|
||||||
|
glob_append(&gl, 1, "%s/*.conf", finit_rcsd);
|
||||||
glob_append(&gl, 1, "%s/enabled/*.conf", finit_rcsd);
|
glob_append(&gl, 1, "%s/enabled/*.conf", finit_rcsd);
|
||||||
|
|
||||||
|
if (bootstrap) {
|
||||||
|
const char *fn = _PATH_VARRUN "finit/conf.order";
|
||||||
|
FILE *fp;
|
||||||
|
|
||||||
|
fp = fopen(fn, "w");
|
||||||
|
if (!fp) {
|
||||||
|
err(1, "failed creating %s", fn);
|
||||||
|
} else {
|
||||||
|
fprintf(fp, "# Evaluation & execution order of .conf files\n");
|
||||||
|
for (i = 0; i < gl.gl_pathc; i++)
|
||||||
|
fprintf(fp, "%s\n", gl.gl_pathv[i]);
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < gl.gl_pathc; i++) {
|
for (i = 0; i < gl.gl_pathc; i++) {
|
||||||
char *path = gl.gl_pathv[i];
|
char *path = gl.gl_pathv[i];
|
||||||
char *rp = NULL;
|
char *rp = NULL;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
size_t j, len;
|
size_t j, len;
|
||||||
|
|
||||||
/* check for FINIT_SYSPATH overrides */
|
/* check for FINIT_SYSPATH_ or FINIT_RUNPATH_ overrides */
|
||||||
for (j = i + 1; j < gl.gl_pathc; j++) {
|
for (j = i + 1; j < gl.gl_pathc; j++) {
|
||||||
if (strncmp(path, FINIT_SYSPATH, strlen(FINIT_SYSPATH)))
|
if (strncmp(path, FINIT_SYSPATH_, strlen(FINIT_SYSPATH_)) &&
|
||||||
|
strncmp(path, FINIT_RUNPATH_, strlen(FINIT_RUNPATH_)))
|
||||||
continue;
|
continue;
|
||||||
if (strcmp(basename(path), basename(gl.gl_pathv[j])))
|
if (strcmp(basename(path), basename(gl.gl_pathv[j])))
|
||||||
continue;
|
continue;
|
||||||
@@ -1185,6 +1340,9 @@ done:
|
|||||||
/* Drop record of all .conf changes */
|
/* Drop record of all .conf changes */
|
||||||
drop_changes();
|
drop_changes();
|
||||||
|
|
||||||
|
if (bootstrap)
|
||||||
|
wdog = svc_find("watchdog", "finit");
|
||||||
|
|
||||||
/* Override configured runlevel, user said 'S' on /proc/cmdline */
|
/* Override configured runlevel, user said 'S' on /proc/cmdline */
|
||||||
if (BOOTSTRAP && single)
|
if (BOOTSTRAP && single)
|
||||||
cfglevel = 1;
|
cfglevel = 1;
|
||||||
@@ -1235,7 +1393,10 @@ static int conf_change_act(char *dir, char *name, uint32_t mask)
|
|||||||
struct conf_change *node;
|
struct conf_change *node;
|
||||||
char *rp = NULL;
|
char *rp = NULL;
|
||||||
|
|
||||||
paste(fn, sizeof(fn), dir, name);
|
if (name[0])
|
||||||
|
paste(fn, sizeof(fn), dir, name);
|
||||||
|
else
|
||||||
|
strlcpy(fn, dir, sizeof(fn));
|
||||||
dbg("path: %s mask: %08x", fn, mask);
|
dbg("path: %s mask: %08x", fn, mask);
|
||||||
|
|
||||||
/* Handle disabling/removal of service */
|
/* Handle disabling/removal of service */
|
||||||
@@ -1266,7 +1427,7 @@ static int conf_change_act(char *dir, char *name, uint32_t mask)
|
|||||||
dbg("event registered for %s, mask 0x%x", rp, mask);
|
dbg("event registered for %s, mask 0x%x", rp, mask);
|
||||||
return 0;
|
return 0;
|
||||||
fail:
|
fail:
|
||||||
warn("failed registering %s event", fn);
|
warn("failed registering %s event mask %08x", fn, mask);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1329,10 +1490,8 @@ static int conf_iwatch_read(int fd)
|
|||||||
if (!iwp)
|
if (!iwp)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (conf_change_act(iwp->path, ev->name, ev->mask)) {
|
if (conf_change_act(iwp->path, ev->name, ev->mask))
|
||||||
err(1, " Out of memory");
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1420,15 +1579,16 @@ int conf_init(uev_ctx_t *ctx)
|
|||||||
*/
|
*/
|
||||||
#ifdef WDT_DEVNODE
|
#ifdef WDT_DEVNODE
|
||||||
if (whichp(FINIT_EXECPATH_ "/watchdogd") && fexist(WDT_DEVNODE)) {
|
if (whichp(FINIT_EXECPATH_ "/watchdogd") && fexist(WDT_DEVNODE)) {
|
||||||
service_register(SVC_TYPE_SERVICE, "[S0123456789] cgroup.init name:watchdog :finit " FINIT_EXECPATH_ "/watchdogd -- Finit watchdog daemon", global_rlimit, NULL);
|
conf_save_service(SVC_TYPE_SERVICE, "[S0123456789] cgroup.init name:watchdog :finit "
|
||||||
wdog = svc_find("watchdog", "finit");
|
FINIT_EXECPATH_ "/watchdogd -- Finit watchdog daemon", "watchdogd.conf");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/*
|
/*
|
||||||
* Start kernel event daemon as soon as possible, if enabled
|
* Start kernel event daemon as soon as possible, if enabled
|
||||||
*/
|
*/
|
||||||
if (whichp(FINIT_EXECPATH_ "/keventd"))
|
if (whichp(FINIT_EXECPATH_ "/keventd"))
|
||||||
service_register(SVC_TYPE_SERVICE, "[S0123456789] cgroup.init " FINIT_EXECPATH_ "/keventd -- Finit kernel event daemon", global_rlimit, NULL);
|
conf_save_service(SVC_TYPE_SERVICE, "[S0123456789] cgroup.init "
|
||||||
|
FINIT_EXECPATH_ "/keventd -- Finit kernel event daemon", "keventd.conf");
|
||||||
|
|
||||||
dbg("Allow plugins to register early runlevel 1 run/task/services ...");
|
dbg("Allow plugins to register early runlevel 1 run/task/services ...");
|
||||||
plugin_run_hooks(HOOK_SVC_PLUGIN);
|
plugin_run_hooks(HOOK_SVC_PLUGIN);
|
||||||
@@ -1447,6 +1607,26 @@ int conf_init(uev_ctx_t *ctx)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Background startup scripts in the runparts directory, if any.
|
||||||
|
*/
|
||||||
|
if (runparts && fisdir(runparts) && !rescue) {
|
||||||
|
char conf[sizeof(_PATH_RUNPARTS) + strlen(runparts) + 100];
|
||||||
|
char args[10] = { 0 };
|
||||||
|
|
||||||
|
if (debug)
|
||||||
|
strlcat(args, "-d ", sizeof(args));
|
||||||
|
if (runparts_progress)
|
||||||
|
strlcat(args, "-p ", sizeof(args));
|
||||||
|
if (runparts_sysv)
|
||||||
|
strlcat(args, "-s ", sizeof(args));
|
||||||
|
|
||||||
|
snprintf(conf, sizeof(conf), "[S] <int/bootstrap> log:console %s %s %s"
|
||||||
|
" -- Calling runparts %s in the background",
|
||||||
|
_PATH_RUNPARTS, args, runparts, runparts);
|
||||||
|
conf_save_service(SVC_TYPE_TASK, conf, "runparts.conf");
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ int conf_monitor (void);
|
|||||||
|
|
||||||
void conf_reset_env (void);
|
void conf_reset_env (void);
|
||||||
void conf_saverc (void);
|
void conf_saverc (void);
|
||||||
|
void conf_save_exec_order (svc_t *svc, char *cmdline, int result);
|
||||||
|
void conf_save_service (int type, char *cfg, char *file);
|
||||||
void conf_parse_cmdline (int argc, char *argv[]);
|
void conf_parse_cmdline (int argc, char *argv[]);
|
||||||
int conf_parse_runlevels (char *runlevels);
|
int conf_parse_runlevels (char *runlevels);
|
||||||
void conf_parse_cond (svc_t *svc, char *cond);
|
void conf_parse_cond (svc_t *svc, char *cond);
|
||||||
|
|||||||
+2
-2
@@ -237,13 +237,13 @@ static void devmon_cb(uev_t *w, void *arg, int events)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
dbg("Got %s", ev->name);
|
// dbg("Got %s", ev->name);
|
||||||
if (ev->mask & (IN_CREATE | IN_DELETE))
|
if (ev->mask & (IN_CREATE | IN_DELETE))
|
||||||
devmon_update_conds(iwp->path, ev->name, ev->mask);
|
devmon_update_conds(iwp->path, ev->name, ev->mask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void devmon_init(void)
|
void devmon_init(uev_ctx_t *ctx)
|
||||||
{
|
{
|
||||||
char dir[MAX_ARG_LEN];
|
char dir[MAX_ARG_LEN];
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -27,6 +27,6 @@
|
|||||||
void devmon_add_cond(const char *cond);
|
void devmon_add_cond(const char *cond);
|
||||||
void devmon_del_cond(const char *cond);
|
void devmon_del_cond(const char *cond);
|
||||||
|
|
||||||
void devmon_init(void);
|
void devmon_init(uev_ctx_t *ctx);
|
||||||
|
|
||||||
#endif /* FINIT_DEVMON_H_ */
|
#endif /* FINIT_DEVMON_H_ */
|
||||||
|
|||||||
+15
-93
@@ -24,8 +24,6 @@
|
|||||||
|
|
||||||
#include "config.h" /* Generated by configure script */
|
#include "config.h" /* Generated by configure script */
|
||||||
|
|
||||||
#include <ctype.h> /* isdigit() */
|
|
||||||
#include <dirent.h>
|
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <sysexits.h>
|
#include <sysexits.h>
|
||||||
@@ -59,11 +57,11 @@ int complete(char *cmd, int pid)
|
|||||||
|
|
||||||
if (waitpid(pid, &status, 0) == -1) {
|
if (waitpid(pid, &status, 0) == -1) {
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
errx(1, "Caught unblocked signal waiting for %s, aborting", cmd);
|
warnx("Caught unblocked signal waiting for %s, aborting", cmd);
|
||||||
else if (errno == ECHILD)
|
else if (errno == ECHILD)
|
||||||
errx(1, "Caught SIGCHLD waiting for %s, aborting", cmd);
|
warnx("Caught SIGCHLD waiting for %s, aborting", cmd);
|
||||||
else
|
else
|
||||||
errx(1, "Failed starting %s, error %d: %s", cmd, errno, strerror (errno));
|
warnx("Failed starting %s, error %d: %s", cmd, errno, strerror(errno));
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -186,7 +184,7 @@ int run(char *cmd, char *log)
|
|||||||
} else if (WIFSIGNALED(status)) {
|
} else if (WIFSIGNALED(status)) {
|
||||||
dbg("Process '%s' terminated by signal %d", cmd, WTERMSIG(status));
|
dbg("Process '%s' terminated by signal %d", cmd, WTERMSIG(status));
|
||||||
if (!result)
|
if (!result)
|
||||||
result = 1; /* Must alert callee that the command did complete successfully.
|
result = 1; /* Must alert callee the command did not complete successfully.
|
||||||
* This is necessary since not all programs trap signals and
|
* This is necessary since not all programs trap signals and
|
||||||
* change their return code accordingly. --Jocke */
|
* change their return code accordingly. --Jocke */
|
||||||
}
|
}
|
||||||
@@ -272,7 +270,7 @@ int exec_runtask(char *cmd, char *args[])
|
|||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
strlcat(buf, cmd, sizeof(buf));
|
strlcat(buf, cmd, sizeof(buf));
|
||||||
for (i = 1; args[i]; i++) {
|
for (i = 1; args && args[i]; i++) {
|
||||||
strlcat(buf, " ", sizeof(buf));
|
strlcat(buf, " ", sizeof(buf));
|
||||||
strlcat(buf, args[i], sizeof(buf));
|
strlcat(buf, args[i], sizeof(buf));
|
||||||
}
|
}
|
||||||
@@ -443,96 +441,20 @@ pid_t run_sh(char *tty, int noclear, int nowait, struct rlimit rlimit[])
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void run_env(const char *env[])
|
pid_t run_bg(char *cmd, char *args[])
|
||||||
{
|
{
|
||||||
size_t i = 0;
|
pid_t pid;
|
||||||
|
|
||||||
if (!env)
|
if (access(cmd, X_OK))
|
||||||
return;
|
return 0;
|
||||||
|
|
||||||
while (env[i]) {
|
print(-1, "Calling %s in the background", cmd);
|
||||||
size_t j = i + 1;
|
pid = fork();
|
||||||
|
if (!pid)
|
||||||
|
_exit(exec_runtask(cmd, args));
|
||||||
|
print_result(pid == -1);
|
||||||
|
|
||||||
if (!env[j])
|
return pid;
|
||||||
break;
|
|
||||||
|
|
||||||
setenv(env[i], env[j], 1);
|
|
||||||
i += 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int run_parts(char *dir, char *cmd, const char *env[], int progress)
|
|
||||||
{
|
|
||||||
struct dirent **e;
|
|
||||||
int i, num;
|
|
||||||
|
|
||||||
num = scandir(dir, &e, NULL, alphasort);
|
|
||||||
if (num < 0) {
|
|
||||||
dbg("No files found in %s, skipping ...", dir);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < num; i++) {
|
|
||||||
const char *name = e[i]->d_name;
|
|
||||||
char path[strlen(dir) + strlen(name) + 2];
|
|
||||||
struct stat st;
|
|
||||||
char *argv[4] = {
|
|
||||||
"sh",
|
|
||||||
"-c",
|
|
||||||
path,
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
pid_t pid = 0;
|
|
||||||
int status;
|
|
||||||
|
|
||||||
paste(path, sizeof(path), dir, name);
|
|
||||||
if (stat(path, &st)) {
|
|
||||||
dbg("Failed stat(%s): %s", path, strerror(errno));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!S_ISEXEC(st.st_mode) || S_ISDIR(st.st_mode)) {
|
|
||||||
if (strcmp(name, ".") && strcmp(name, ".."))
|
|
||||||
dbg("Skipping %s ...", path);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If the callee didn't supply a run_parts() argument */
|
|
||||||
if (!cmd) {
|
|
||||||
/* Check if S<NUM>service or K<NUM>service notation is used */
|
|
||||||
// dbg("Checking if %s is a sysvinit startstop script ...", name);
|
|
||||||
if (name[0] == 'S' && isdigit(name[1]))
|
|
||||||
strlcat(path, " start", sizeof(path));
|
|
||||||
else if (name[0] == 'K' && isdigit(name[1]))
|
|
||||||
strlcat(path, " stop", sizeof(path));
|
|
||||||
} else {
|
|
||||||
strlcat(path, cmd, sizeof(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (progress)
|
|
||||||
print_desc("Calling ", path);
|
|
||||||
pid = fork();
|
|
||||||
if (!pid) {
|
|
||||||
sig_unblock();
|
|
||||||
run_env(env);
|
|
||||||
|
|
||||||
return execvp(_PATH_BSHELL, argv);
|
|
||||||
}
|
|
||||||
|
|
||||||
status = complete(path, pid);
|
|
||||||
if (WIFEXITED(status))
|
|
||||||
warnx("%s exited with status %d", path, WEXITSTATUS(status));
|
|
||||||
else if (WIFSIGNALED(status))
|
|
||||||
warnx("%s terminated by signad %d", path, WTERMSIG(status));
|
|
||||||
if (progress)
|
|
||||||
print_result(WEXITSTATUS(status));
|
|
||||||
}
|
|
||||||
|
|
||||||
while (num--)
|
|
||||||
free(e[num]);
|
|
||||||
free(e);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+16
-133
@@ -58,7 +58,6 @@
|
|||||||
#include "tty.h"
|
#include "tty.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "utmp-api.h"
|
#include "utmp-api.h"
|
||||||
#include "schedule.h"
|
|
||||||
|
|
||||||
int runlevel = INIT_LEVEL; /* Bootstrap 'S' */
|
int runlevel = INIT_LEVEL; /* Bootstrap 'S' */
|
||||||
int cfglevel = RUNLEVEL; /* Fallback if no configured runlevel */
|
int cfglevel = RUNLEVEL; /* Fallback if no configured runlevel */
|
||||||
@@ -76,7 +75,6 @@ char *fstab = NULL;
|
|||||||
char *sdown = NULL;
|
char *sdown = NULL;
|
||||||
char *network = NULL;
|
char *network = NULL;
|
||||||
char *hostname = NULL;
|
char *hostname = NULL;
|
||||||
char *runparts = NULL;
|
|
||||||
char *osheading = NULL;
|
char *osheading = NULL;
|
||||||
|
|
||||||
uev_ctx_t *ctx = NULL; /* Main loop context */
|
uev_ctx_t *ctx = NULL; /* Main loop context */
|
||||||
@@ -206,7 +204,7 @@ static int fsck(int pass)
|
|||||||
|
|
||||||
fp = setmntent(fstab, "r");
|
fp = setmntent(fstab, "r");
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
err(1, "Failed opening fstab: %s", fstab);
|
logit(LOG_CONSOLE | LOG_ALERT, "Failed opening fstab: %s", fstab);
|
||||||
sulogin(1);
|
sulogin(1);
|
||||||
}
|
}
|
||||||
dbg("Opened %s, pass %d", fstab, pass);
|
dbg("Opened %s, pass %d", fstab, pass);
|
||||||
@@ -256,11 +254,7 @@ static int fsck(int pass)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef FSCK_FIX
|
|
||||||
snprintf(cmd, sizeof(cmd), "fsck -yf %s", dev);
|
|
||||||
#else
|
|
||||||
snprintf(cmd, sizeof(cmd), "fsck %s %s %s", fsck_mode, fsck_repair, dev);
|
snprintf(cmd, sizeof(cmd), "fsck %s %s %s", fsck_mode, fsck_repair, dev);
|
||||||
#endif
|
|
||||||
dbg("Running pass %d fsck command %s", pass, cmd);
|
dbg("Running pass %d fsck command %s", pass, cmd);
|
||||||
fsck_rc = run_interactive(cmd, "Checking filesystem %s", dev);
|
fsck_rc = run_interactive(cmd, "Checking filesystem %s", dev);
|
||||||
/*
|
/*
|
||||||
@@ -283,7 +277,6 @@ static int fsck(int pass)
|
|||||||
static int fsck_all(void)
|
static int fsck_all(void)
|
||||||
{
|
{
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
#ifndef FAST_BOOT
|
|
||||||
int pass;
|
int pass;
|
||||||
|
|
||||||
if (!fsck_mode)
|
if (!fsck_mode)
|
||||||
@@ -294,7 +287,7 @@ static int fsck_all(void)
|
|||||||
if (rc)
|
if (rc)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -521,113 +514,6 @@ static void fs_init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Handle bootstrap transition to configured runlevel, start TTYs
|
|
||||||
*
|
|
||||||
* This is the final stage of bootstrap. It changes to the default
|
|
||||||
* (configured) runlevel, calls all external start scripts and final
|
|
||||||
* bootstrap hooks before bringing up TTYs.
|
|
||||||
*
|
|
||||||
* We must ensure that all declared `task [S]` and `run [S]` jobs in
|
|
||||||
* finit.conf, or *.conf in finit.d/, run to completion before we
|
|
||||||
* finalize the bootstrap process by calling this function.
|
|
||||||
*/
|
|
||||||
static void finalize(void *unused)
|
|
||||||
{
|
|
||||||
/* Clean up bootstrap-only tasks/services that never started */
|
|
||||||
dbg("Clean up all bootstrap-only tasks/services ...");
|
|
||||||
svc_prune_bootstrap();
|
|
||||||
|
|
||||||
/* All services/tasks/etc. in configure runlevel have started */
|
|
||||||
dbg("Running svc up hooks ...");
|
|
||||||
plugin_run_hooks(HOOK_SVC_UP);
|
|
||||||
service_step_all(SVC_TYPE_ANY);
|
|
||||||
|
|
||||||
/* Convenient SysV compat for when you just don't care ... */
|
|
||||||
if (!access(FINIT_RC_LOCAL, X_OK) && !rescue)
|
|
||||||
run_interactive(FINIT_RC_LOCAL, "Calling %s", FINIT_RC_LOCAL);
|
|
||||||
|
|
||||||
/* Hooks that should run at the very end */
|
|
||||||
dbg("Calling all system up hooks ...");
|
|
||||||
plugin_run_hooks(HOOK_SYSTEM_UP);
|
|
||||||
service_step_all(SVC_TYPE_ANY);
|
|
||||||
|
|
||||||
/* Disable progress output at normal runtime */
|
|
||||||
enable_progress(0);
|
|
||||||
|
|
||||||
/* System bootrapped, launch TTYs et al */
|
|
||||||
bootstrap = 0;
|
|
||||||
service_step_all(SVC_TYPE_RESPAWN);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Start cranking the big state machine
|
|
||||||
*/
|
|
||||||
static void crank_worker(void *unused)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* Initialize state machine and start all bootstrap tasks
|
|
||||||
* NOTE: no network available!
|
|
||||||
*/
|
|
||||||
sm_init(&sm);
|
|
||||||
sm_step(&sm);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Wait for system bootstrap to complete, all SVC_TYPE_RUNTASK must be
|
|
||||||
* allowed to complete their work in [S], or timeout, before we switch
|
|
||||||
* to the configured runlevel and call finalize(), should not take more
|
|
||||||
* than 120 sec.
|
|
||||||
*/
|
|
||||||
static void bootstrap_worker(void *work)
|
|
||||||
{
|
|
||||||
static struct wq final = {
|
|
||||||
.cb = finalize,
|
|
||||||
.delay = 10
|
|
||||||
};
|
|
||||||
static int cnt = 120 * 10; /* We run with 100ms period */
|
|
||||||
int level = cfglevel;
|
|
||||||
|
|
||||||
dbg("Step all services ...");
|
|
||||||
service_step_all(SVC_TYPE_ANY);
|
|
||||||
|
|
||||||
if (cnt-- > 0 && !service_completed()) {
|
|
||||||
dbg("Not all bootstrap run/tasks have completed yet ... %d", cnt);
|
|
||||||
schedule_work(work);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cnt > 0)
|
|
||||||
dbg("All run/task have completed, resuming bootstrap.");
|
|
||||||
else
|
|
||||||
dbg("Timeout, resuming bootstrap.");
|
|
||||||
|
|
||||||
dbg("Starting runlevel change finalize ...");
|
|
||||||
schedule_work(&final);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Run startup scripts in the runparts directory, if any.
|
|
||||||
*/
|
|
||||||
if (runparts && fisdir(runparts) && !rescue)
|
|
||||||
run_parts(runparts, NULL, NULL, 1);
|
|
||||||
|
|
||||||
|
|
||||||
dbg("Flushing pending .conf file events ...");
|
|
||||||
conf_flush_events();
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Start all tasks/services in the configured runlevel, or jump
|
|
||||||
* into the runlevel selected from the command line.
|
|
||||||
*/
|
|
||||||
if (cmdlevel) {
|
|
||||||
dbg("Runlevel %d requested from command line, starting all services ...", cmdlevel);
|
|
||||||
level = cmdlevel;
|
|
||||||
} else
|
|
||||||
dbg("Change to default runlevel(%d), starting all services ...", cfglevel);
|
|
||||||
|
|
||||||
service_runlevel(level);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int version(int rc)
|
static int version(int rc)
|
||||||
{
|
{
|
||||||
puts(PACKAGE_STRING);
|
puts(PACKAGE_STRING);
|
||||||
@@ -658,7 +544,7 @@ static int usage(int rc)
|
|||||||
" 2-9 Change runlevel\n"
|
" 2-9 Change runlevel\n"
|
||||||
" q, Q Reload /etc/finit.conf and/or any *.conf in /etc/finit.d/\n"
|
" q, Q Reload /etc/finit.conf and/or any *.conf in /etc/finit.d/\n"
|
||||||
" if modified, same as initctl reload or SIGHUP to PID 1\n"
|
" if modified, same as initctl reload or SIGHUP to PID 1\n"
|
||||||
" 1, s, S Enter system rescue mode, runlevel 1\n"
|
" 1, s, S Enter single user mode, no networking, runlevel 1\n"
|
||||||
"\n", prognm);
|
"\n", prognm);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
@@ -708,14 +594,6 @@ static int telinit(int argc, char *argv[])
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct wq crank_work = {
|
|
||||||
.cb = crank_worker,
|
|
||||||
.delay = 10
|
|
||||||
};
|
|
||||||
struct wq bootstrap_work = {
|
|
||||||
.cb = bootstrap_worker,
|
|
||||||
.delay = 100
|
|
||||||
};
|
|
||||||
uev_ctx_t loop;
|
uev_ctx_t loop;
|
||||||
|
|
||||||
/* user calling telinit or init */
|
/* user calling telinit or init */
|
||||||
@@ -765,8 +643,10 @@ int main(int argc, char *argv[])
|
|||||||
/*
|
/*
|
||||||
* In case of emergency.
|
* In case of emergency.
|
||||||
*/
|
*/
|
||||||
|
#ifdef RESCUE_MODE
|
||||||
if (rescue)
|
if (rescue)
|
||||||
rescue = sulogin(0);
|
rescue = sulogin(0);
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Load plugins early, the first hook is in banner(), so we
|
* Load plugins early, the first hook is in banner(), so we
|
||||||
@@ -815,11 +695,15 @@ int main(int argc, char *argv[])
|
|||||||
cond_set_oneshot(plugin_hook_str(HOOK_BANNER));
|
cond_set_oneshot(plugin_hook_str(HOOK_BANNER));
|
||||||
cond_set_oneshot(plugin_hook_str(HOOK_ROOTFS_UP));
|
cond_set_oneshot(plugin_hook_str(HOOK_ROOTFS_UP));
|
||||||
|
|
||||||
|
/* Some bootstrap tasks may need to know if we're in a container. */
|
||||||
|
if (in_container())
|
||||||
|
cond_set("int/container");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize .conf system and load static /etc/finit.conf then
|
* Initialize .conf system and load static /etc/finit.conf then
|
||||||
* tell the world what we used.
|
* tell the world what we used.
|
||||||
*/
|
*/
|
||||||
devmon_init();
|
devmon_init(&loop);
|
||||||
conf_init(&loop);
|
conf_init(&loop);
|
||||||
conf_saverc();
|
conf_saverc();
|
||||||
|
|
||||||
@@ -832,16 +716,15 @@ int main(int argc, char *argv[])
|
|||||||
dbg("Starting initctl API responder ...");
|
dbg("Starting initctl API responder ...");
|
||||||
api_init(&loop);
|
api_init(&loop);
|
||||||
|
|
||||||
dbg("Starting the big state machine ...");
|
dbg("Starting service interval monitor ...");
|
||||||
schedule_work(&crank_work);
|
service_init(&loop);
|
||||||
|
|
||||||
dbg("Starting bootstrap finalize timer ...");
|
|
||||||
schedule_work(&bootstrap_work);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Background service tasks
|
* Initialize state machine and start all bootstrap tasks
|
||||||
|
* NOTE: no network available!
|
||||||
*/
|
*/
|
||||||
service_init();
|
sm_init(&sm);
|
||||||
|
sm_step(&sm);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Enter main loop to monitor /dev/initctl and services
|
* Enter main loop to monitor /dev/initctl and services
|
||||||
|
|||||||
+2
-1
@@ -56,10 +56,11 @@
|
|||||||
|
|
||||||
/* To use these, include config.h, or define FINIT_EXECPATH_ */
|
/* To use these, include config.h, or define FINIT_EXECPATH_ */
|
||||||
#define _PATH_LOGIT FINIT_EXECPATH_ "/logit"
|
#define _PATH_LOGIT FINIT_EXECPATH_ "/logit"
|
||||||
|
#define _PATH_RUNPARTS FINIT_EXECPATH_ "/runparts"
|
||||||
#define _PATH_SULOGIN FINIT_EXECPATH_ "/sulogin"
|
#define _PATH_SULOGIN FINIT_EXECPATH_ "/sulogin"
|
||||||
#define _PATH_GETTY FINIT_EXECPATH_ "/getty"
|
#define _PATH_GETTY FINIT_EXECPATH_ "/getty"
|
||||||
|
|
||||||
#define CMD_SIZE 256
|
#define CMD_SIZE 1024
|
||||||
#define LINE_SIZE 1024
|
#define LINE_SIZE 1024
|
||||||
#define BUF_SIZE 4096
|
#define BUF_SIZE 4096
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -369,7 +369,7 @@ restart:
|
|||||||
|
|
||||||
static int usage(int rc)
|
static int usage(int rc)
|
||||||
{
|
{
|
||||||
warnx("usage: getty [-h?] tty [speed [term]]");
|
warnx("usage: getty [-h?p] tty [speed [term]]");
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -88,7 +88,8 @@ int run_interactive (char *cmd, char *fmt, ...) __attribute__ ((format (prin
|
|||||||
int exec_runtask (char *cmd, char *args[]);
|
int exec_runtask (char *cmd, char *args[]);
|
||||||
pid_t run_getty (char *tty, char *cmd, char *args[], int noclear, int nowait, struct rlimit rlimit[]);
|
pid_t run_getty (char *tty, char *cmd, char *args[], int noclear, int nowait, struct rlimit rlimit[]);
|
||||||
pid_t run_sh (char *tty, int noclear, int nowait, struct rlimit rlimit[]);
|
pid_t run_sh (char *tty, int noclear, int nowait, struct rlimit rlimit[]);
|
||||||
int run_parts (char *dir, char *cmd, const char *env[], int progress);
|
pid_t run_bg (char *cmd, char *args[]);
|
||||||
|
int run_parts (char *dir, char *cmd, const char *env[], int progress, int sysv);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Defaults to user "root" and group "wheel" (root) if:
|
* Defaults to user "root" and group "wheel" (root) if:
|
||||||
|
|||||||
+10
-3
@@ -209,19 +209,26 @@ static int do_runlevel(char *arg)
|
|||||||
if (!arg) {
|
if (!arg) {
|
||||||
int prevlevel = 0;
|
int prevlevel = 0;
|
||||||
int currlevel;
|
int currlevel;
|
||||||
char prev;
|
char prev, curr;
|
||||||
|
|
||||||
currlevel = runlevel_get(&prevlevel);
|
currlevel = runlevel_get(&prevlevel);
|
||||||
if (255 == currlevel) {
|
switch (currlevel) {
|
||||||
|
case 255:
|
||||||
printf("unknown\n");
|
printf("unknown\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
case INIT_LEVEL:
|
||||||
|
curr = 'S';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
curr = currlevel + '0';
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
prev = prevlevel + '0';
|
prev = prevlevel + '0';
|
||||||
if (prev <= '0' || prev > '9')
|
if (prev <= '0' || prev > '9')
|
||||||
prev = 'N';
|
prev = 'N';
|
||||||
|
|
||||||
printf("%c %d\n", prev , currlevel);
|
printf("%c %c\n", prev , curr);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ static __attribute__ ((format (printf, 1, 2))) inline void dbg(char *fmt, ...)
|
|||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
vfprintf(stderr, fmt, ap);
|
vfprintf(stderr, fmt, ap);
|
||||||
|
fputs("\n", stderr);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
#define info(fmt, args...) warnx(fmt, ##args)
|
#define info(fmt, args...) warnx(fmt, ##args)
|
||||||
|
|||||||
+2
-2
@@ -230,7 +230,7 @@ void plugin_script_run(hook_point_t no)
|
|||||||
} else
|
} else
|
||||||
env[2] = NULL;
|
env[2] = NULL;
|
||||||
|
|
||||||
run_parts(path, NULL, env, 0);
|
run_parts(path, NULL, env, 0, 0);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
void plugin_script_run(hook_point_t no)
|
void plugin_script_run(hook_point_t no)
|
||||||
@@ -288,7 +288,7 @@ static void generic_io_cb(uev_t *w, void *arg, int events)
|
|||||||
/* Stop watcher, callback may close descriptor on us ... */
|
/* Stop watcher, callback may close descriptor on us ... */
|
||||||
uev_io_stop(w);
|
uev_io_stop(w);
|
||||||
|
|
||||||
dbg("Calling I/O %s from runloop...", basename(p->name));
|
// dbg("Calling I/O %s from runloop...", basename(p->name));
|
||||||
p->io.cb(p->io.arg, w->fd, events);
|
p->io.cb(p->io.arg, w->fd, events);
|
||||||
|
|
||||||
/* Update fd, may be changed by plugin callback, e.g., if FIFO */
|
/* Update fd, may be changed by plugin callback, e.g., if FIFO */
|
||||||
|
|||||||
+230
@@ -0,0 +1,230 @@
|
|||||||
|
#include <ctype.h> /* isdigit() */
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <err.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <paths.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
|
||||||
|
#ifdef _LIBITE_LITE
|
||||||
|
# include <libite/conio.h>
|
||||||
|
# include <libite/lite.h>
|
||||||
|
#else
|
||||||
|
# include <lite/conio.h>
|
||||||
|
# include <lite/lite.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "log.h"
|
||||||
|
#include "sig.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
#ifdef __FINIT__
|
||||||
|
#include "helpers.h"
|
||||||
|
#else
|
||||||
|
#include <sys/prctl.h>
|
||||||
|
|
||||||
|
int debug;
|
||||||
|
|
||||||
|
static void print_desc(const char *prefix, const char *msg)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "\e[1m[\e[0m\e[1;33m ⋯ \e[0m\e[1m]\e[0m %s %s", prefix, msg);
|
||||||
|
}
|
||||||
|
static void print_result(int rc)
|
||||||
|
{
|
||||||
|
if (rc)
|
||||||
|
fputs("\r\e[1m[\e[0m\e[1;31mFAIL\e[0m\e[1m]\e[0m\n", stderr);
|
||||||
|
else
|
||||||
|
fputs("\r\e[1m[\e[0m\e[1;32m OK \e[0m\e[1m]\e[0m\n", stderr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sig_unblock(void)
|
||||||
|
{
|
||||||
|
struct sigaction sa;
|
||||||
|
sigset_t nmask;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
sigemptyset(&nmask);
|
||||||
|
sigaddset(&nmask, SIGHUP);
|
||||||
|
sigaddset(&nmask, SIGCHLD);
|
||||||
|
sigaddset(&nmask, SIGINT);
|
||||||
|
sigaddset(&nmask, SIGPWR);
|
||||||
|
sigaddset(&nmask, SIGSTOP);
|
||||||
|
sigaddset(&nmask, SIGTSTP);
|
||||||
|
sigaddset(&nmask, SIGCONT);
|
||||||
|
sigaddset(&nmask, SIGTERM);
|
||||||
|
sigaddset(&nmask, SIGUSR1);
|
||||||
|
sigaddset(&nmask, SIGUSR2);
|
||||||
|
sigprocmask(SIG_UNBLOCK, &nmask, NULL);
|
||||||
|
|
||||||
|
/* Reset signal handlers that were set by the parent process */
|
||||||
|
for (i = 1; i < NSIG; i++)
|
||||||
|
DFLSIG(sa, i, 0);
|
||||||
|
}
|
||||||
|
#endif /* __FINIT__ */
|
||||||
|
|
||||||
|
static void run_env(const char *env[])
|
||||||
|
{
|
||||||
|
size_t i = 0;
|
||||||
|
|
||||||
|
if (!env)
|
||||||
|
return;
|
||||||
|
|
||||||
|
while (env[i]) {
|
||||||
|
size_t j = i + 1;
|
||||||
|
|
||||||
|
if (!env[j])
|
||||||
|
break;
|
||||||
|
|
||||||
|
setenv(env[i], env[j], 1);
|
||||||
|
i += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int run_parts(char *dir, char *cmd, const char *env[], int progress, int sysv)
|
||||||
|
{
|
||||||
|
size_t cmdlen = cmd ? strlen(cmd) : strlen("start");
|
||||||
|
struct dirent **d;
|
||||||
|
int i, num;
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
|
num = scandir(dir, &d, NULL, alphasort);
|
||||||
|
if (num < 0) {
|
||||||
|
dbg("No files found in %s, skipping ...", dir);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < num; i++) {
|
||||||
|
char path[strlen(dir) + strlen(d[i]->d_name) + 3 + cmdlen];
|
||||||
|
const char *name = d[i]->d_name;
|
||||||
|
char *argv[4] = {
|
||||||
|
"sh",
|
||||||
|
"-c",
|
||||||
|
path,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
struct stat st;
|
||||||
|
int result = 0;
|
||||||
|
pid_t pid = 0;
|
||||||
|
int status;
|
||||||
|
|
||||||
|
/* skip backup files */
|
||||||
|
if (name[strlen(name) - 1] == '~')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* cannot rely on d_type, not supported on all filesystems */
|
||||||
|
paste(path, sizeof(path), dir, name);
|
||||||
|
if (stat(path, &st)) {
|
||||||
|
warn("failed stat(%s)", path);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* skip non-executable files and directories */
|
||||||
|
if (!S_ISEXEC(st.st_mode) || S_ISDIR(st.st_mode)) {
|
||||||
|
dbg("skipping %s not an executable or is a directory", path);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sysv && name[0] != 'S' && name[0] != 'K') {
|
||||||
|
dbg("S-only flag set, skipping non-SysV script: %s", name);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If the callee didn't supply a run_parts() argument */
|
||||||
|
if (!cmd) {
|
||||||
|
/* Check if S<NUM>service or K<NUM>service notation is used */
|
||||||
|
if (name[0] == 'S' && isdigit(name[1]))
|
||||||
|
strlcat(path, " start", sizeof(path));
|
||||||
|
else if (name[0] == 'K' && isdigit(name[1]))
|
||||||
|
strlcat(path, " stop", sizeof(path));
|
||||||
|
} else {
|
||||||
|
strlcat(path, " ", sizeof(path));
|
||||||
|
strlcat(path, cmd, sizeof(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (progress)
|
||||||
|
print_desc("Calling", path);
|
||||||
|
|
||||||
|
pid = fork();
|
||||||
|
if (!pid) {
|
||||||
|
sig_unblock();
|
||||||
|
run_env(env);
|
||||||
|
|
||||||
|
_exit(execvp(_PATH_BSHELL, argv));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (waitpid(pid, &status, 0) == -1) {
|
||||||
|
warnx("failed starting %s, error %d: %s", path, errno, strerror(errno));
|
||||||
|
result = 1;
|
||||||
|
} else {
|
||||||
|
if (WIFEXITED(status)) {
|
||||||
|
result = WEXITSTATUS(status);
|
||||||
|
dbg("%s exited with status %d", path, result);
|
||||||
|
} else if (WIFSIGNALED(status)) {
|
||||||
|
warnx("%s terminated by signal %d", path, WTERMSIG(status));
|
||||||
|
result = 1;
|
||||||
|
} else
|
||||||
|
result = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (progress)
|
||||||
|
print_result(result);
|
||||||
|
rc += result;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (num--)
|
||||||
|
free(d[num]);
|
||||||
|
free(d);
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef __FINIT__
|
||||||
|
static int usage(int rc)
|
||||||
|
{
|
||||||
|
warnx("usage: runparts [-dhps?] DIRECTORY");
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int rc, c, progress = 0, sysv = 0;
|
||||||
|
char *dir;
|
||||||
|
|
||||||
|
while ((c = getopt(argc, argv, "dh?ps")) != EOF) {
|
||||||
|
switch(c) {
|
||||||
|
case 'd':
|
||||||
|
debug = 1;
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
case '?':
|
||||||
|
return usage(0);
|
||||||
|
case 'p':
|
||||||
|
progress = 1;
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
sysv = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return usage(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (optind >= argc)
|
||||||
|
return usage(1);
|
||||||
|
|
||||||
|
dir = argv[optind];
|
||||||
|
if (!fisdir(dir))
|
||||||
|
return usage(1);
|
||||||
|
|
||||||
|
prctl(PR_SET_CHILD_SUBREAPER, 1);
|
||||||
|
|
||||||
|
rc = run_parts(dir, NULL, NULL, progress, sysv);
|
||||||
|
if (rc == -1)
|
||||||
|
err(1, "failed run-parts %s", dir);
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
#endif /* __FINIT__ */
|
||||||
+14
@@ -41,6 +41,10 @@ static int is_builtin(char *arg)
|
|||||||
{
|
{
|
||||||
svc_t *svc;
|
svc_t *svc;
|
||||||
|
|
||||||
|
/* skip check, we may be in non-responsive bootstrap */
|
||||||
|
if (iforce)
|
||||||
|
return 0;
|
||||||
|
|
||||||
svc = client_svc_find(arg);
|
svc = client_svc_find(arg);
|
||||||
if (!svc)
|
if (!svc)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -262,6 +266,11 @@ int serv_enable(char *arg)
|
|||||||
return serv_list("available");
|
return serv_list("available");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (arg[0] == '/') {
|
||||||
|
WARNX("absolute paths not supported, this command manages %s/available/", finit_rcsd);
|
||||||
|
return serv_list("available");
|
||||||
|
}
|
||||||
|
|
||||||
len = strlen(arg);
|
len = strlen(arg);
|
||||||
serv = alloca(len + 6);
|
serv = alloca(len + 6);
|
||||||
if (!serv)
|
if (!serv)
|
||||||
@@ -322,6 +331,11 @@ int do_disable(char *arg, int check)
|
|||||||
return serv_list("enabled");
|
return serv_list("enabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (arg[0] == '/') {
|
||||||
|
WARNX("absolute paths not supported, this command manages %s/enabled/", finit_rcsd);
|
||||||
|
return serv_list("available");
|
||||||
|
}
|
||||||
|
|
||||||
len = strlen(arg);
|
len = strlen(arg);
|
||||||
serv = alloca(len + 6);
|
serv = alloca(len + 6);
|
||||||
if (!serv)
|
if (!serv)
|
||||||
|
|||||||
+149
-61
@@ -56,6 +56,12 @@
|
|||||||
#include "utmp-api.h"
|
#include "utmp-api.h"
|
||||||
#include "schedule.h"
|
#include "schedule.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* run tasks block other tasks/services from starting, we track the
|
||||||
|
* current run task here. For service_step() and service_start().
|
||||||
|
*/
|
||||||
|
static pid_t run_block_pid;
|
||||||
|
|
||||||
static struct wq work = {
|
static struct wq work = {
|
||||||
.cb = service_worker,
|
.cb = service_worker,
|
||||||
};
|
};
|
||||||
@@ -324,14 +330,14 @@ static int lredirect(svc_t *svc)
|
|||||||
|
|
||||||
snprintf(rot, sizeof(rot), "%d:%d", logfile_size_max, logfile_count_max);
|
snprintf(rot, sizeof(rot), "%d:%d", logfile_size_max, logfile_count_max);
|
||||||
snprintf(pid, sizeof(pid), "%d", svc_pid);
|
snprintf(pid, sizeof(pid), "%d", svc_pid);
|
||||||
execlp("logger", "logger", "-f", svc->log.file, "-b", "-t", tag, "-p", prio, "-I", pid, "-r", rot, NULL);
|
execlp("logger", "logger", "-f", svc->log.file, "-b", "-t", tag, "-p", prio, debug ? "-s" : "", "-I", pid, "-r", rot, NULL);
|
||||||
} else {
|
} else {
|
||||||
char sz[20], num[3];
|
char sz[20], num[3];
|
||||||
|
|
||||||
snprintf(sz, sizeof(sz), "%d", logfile_size_max);
|
snprintf(sz, sizeof(sz), "%d", logfile_size_max);
|
||||||
snprintf(num, sizeof(num), "%d", logfile_count_max);
|
snprintf(num, sizeof(num), "%d", logfile_count_max);
|
||||||
|
|
||||||
execlp(_PATH_LOGIT, "logit", "-f", svc->log.file, "-n", sz, "-r", num, NULL);
|
execlp(_PATH_LOGIT, "logit", "-f", svc->log.file, "-n", sz, "-r", num, debug ? "-s" : "", NULL);
|
||||||
}
|
}
|
||||||
_exit(1);
|
_exit(1);
|
||||||
}
|
}
|
||||||
@@ -345,9 +351,9 @@ static int lredirect(svc_t *svc)
|
|||||||
char pid[16];
|
char pid[16];
|
||||||
|
|
||||||
snprintf(pid, sizeof(pid), "%d", svc_pid);
|
snprintf(pid, sizeof(pid), "%d", svc_pid);
|
||||||
execlp("logger", "logger", "-t", tag, "-p", prio, "-I", pid, NULL);
|
execlp("logger", "logger", "-t", tag, "-p", prio, debug ? "-s" : "", "-I", pid, NULL);
|
||||||
} else {
|
} else {
|
||||||
execlp(_PATH_LOGIT, "logit", "-t", tag, "-p", prio, NULL);
|
execlp(_PATH_LOGIT, "logit", "-t", tag, "-p", prio, debug ? "-s" : "", NULL);
|
||||||
}
|
}
|
||||||
_exit(1);
|
_exit(1);
|
||||||
}
|
}
|
||||||
@@ -407,6 +413,7 @@ static void source_env(svc_t *svc)
|
|||||||
len = sizeof(buf);
|
len = sizeof(buf);
|
||||||
while (fgets(line, len, fp)) {
|
while (fgets(line, len, fp)) {
|
||||||
char *key = chomp(line);
|
char *key = chomp(line);
|
||||||
|
wordexp_t we = { 0 };
|
||||||
char *value, *end;
|
char *value, *end;
|
||||||
|
|
||||||
/* skip any leading whitespace */
|
/* skip any leading whitespace */
|
||||||
@@ -460,7 +467,19 @@ static void source_env(svc_t *svc)
|
|||||||
*end-- = 0;
|
*end-- = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
setenv(key, value, 1);
|
switch (wordexp(value, &we, 0)) {
|
||||||
|
case 0:
|
||||||
|
setenv(key, we.we_wordv[0], 1);
|
||||||
|
wordfree(&we);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WRDE_NOSPACE:
|
||||||
|
wordfree(&we);
|
||||||
|
/* fallthrough */
|
||||||
|
default:
|
||||||
|
setenv(key, value, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
@@ -560,6 +579,15 @@ static pid_t service_fork(svc_t *svc)
|
|||||||
source_env(svc);
|
source_env(svc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pid > 1) {
|
||||||
|
char grnam[80];
|
||||||
|
|
||||||
|
if (svc_is_tty(svc))
|
||||||
|
cgroup_user("getty", pid);
|
||||||
|
else
|
||||||
|
cgroup_service(group_name(svc, grnam, sizeof(grnam)), pid, &svc->cgroup);
|
||||||
|
}
|
||||||
|
|
||||||
return pid;
|
return pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -575,7 +603,6 @@ static int service_start(svc_t *svc)
|
|||||||
int result = 0, do_progress = 1;
|
int result = 0, do_progress = 1;
|
||||||
char cmdline[CMD_SIZE] = "";
|
char cmdline[CMD_SIZE] = "";
|
||||||
sigset_t nmask, omask;
|
sigset_t nmask, omask;
|
||||||
char grnam[80];
|
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
@@ -586,6 +613,10 @@ static int service_start(svc_t *svc)
|
|||||||
if (is_norespawn())
|
if (is_norespawn())
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
/* Waiting for a run task to complete */
|
||||||
|
if (run_block_pid)
|
||||||
|
return 1;
|
||||||
|
|
||||||
/* Don't try and start service if it doesn't exist. */
|
/* Don't try and start service if it doesn't exist. */
|
||||||
if (!whichp(svc->cmd)) {
|
if (!whichp(svc->cmd)) {
|
||||||
logit(LOG_WARNING, "%s: missing %s or not in $PATH", svc_ident(svc, NULL, 0), svc->cmd);
|
logit(LOG_WARNING, "%s: missing %s or not in $PATH", svc_ident(svc, NULL, 0), svc->cmd);
|
||||||
@@ -611,6 +642,9 @@ static int service_start(svc_t *svc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
compose_cmdline(svc, cmdline, sizeof(cmdline));
|
compose_cmdline(svc, cmdline, sizeof(cmdline));
|
||||||
|
if (bootstrap)
|
||||||
|
conf_save_exec_order(svc, cmdline, -1);
|
||||||
|
|
||||||
if (svc_is_sysv(svc))
|
if (svc_is_sysv(svc))
|
||||||
logit(LOG_CONSOLE | LOG_NOTICE, "Calling '%s start' ...", cmdline);
|
logit(LOG_CONSOLE | LOG_NOTICE, "Calling '%s start' ...", cmdline);
|
||||||
|
|
||||||
@@ -644,19 +678,15 @@ static int service_start(svc_t *svc)
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
if (pid > 1) {
|
if (pid > 1) {
|
||||||
|
dbg("Starting %s as PID %d", svc_ident(svc, NULL, 0), pid);
|
||||||
svc->pid = pid;
|
svc->pid = pid;
|
||||||
svc->start_time = jiffies();
|
svc->start_time = jiffies();
|
||||||
} else if (pid == 0) {
|
} else if (pid == 0) {
|
||||||
char *args[MAX_NUM_SVC_ARGS + 1];
|
char *args[MAX_NUM_SVC_ARGS + 1];
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
pid = getpid();
|
if (!svc_is_tty(svc))
|
||||||
if (svc_is_tty(svc)) {
|
|
||||||
cgroup_user("getty", pid);
|
|
||||||
} else {
|
|
||||||
cgroup_service(group_name(svc, grnam, sizeof(grnam)), pid, &svc->cgroup);
|
|
||||||
redirect(svc);
|
redirect(svc);
|
||||||
}
|
|
||||||
|
|
||||||
if (!svc_is_sysv(svc)) {
|
if (!svc_is_sysv(svc)) {
|
||||||
wordexp_t we = { 0 };
|
wordexp_t we = { 0 };
|
||||||
@@ -788,7 +818,7 @@ static int service_start(svc_t *svc)
|
|||||||
*/
|
*/
|
||||||
pid = setsid();
|
pid = setsid();
|
||||||
if (pid < 1)
|
if (pid < 1)
|
||||||
logit(LOG_ERR, "failed setsid(), pid %d: %s", pid, strerror(errno));
|
syslog(LOG_ERR, "failed setsid(), pid %d: %s", pid, strerror(errno));
|
||||||
|
|
||||||
sig_unblock();
|
sig_unblock();
|
||||||
|
|
||||||
@@ -799,6 +829,8 @@ static int service_start(svc_t *svc)
|
|||||||
else
|
else
|
||||||
status = execvp(args[0], &args[1]);
|
status = execvp(args[0], &args[1]);
|
||||||
|
|
||||||
|
syslog(LOG_ERR, "failed starting %s, exit code %d: %s", svc_ident(svc, NULL, 0),
|
||||||
|
status, strerror(errno));
|
||||||
_exit(status);
|
_exit(status);
|
||||||
} else if (debug) {
|
} else if (debug) {
|
||||||
dbg("Starting PID %d: %s", svc->pid, cmdline);
|
dbg("Starting PID %d: %s", svc->pid, cmdline);
|
||||||
@@ -809,35 +841,21 @@ static int service_start(svc_t *svc)
|
|||||||
|
|
||||||
switch (svc->type) {
|
switch (svc->type) {
|
||||||
case SVC_TYPE_RUN:
|
case SVC_TYPE_RUN:
|
||||||
svc->status = complete(svc->cmd, pid);
|
run_block_pid = pid;
|
||||||
dbg("collected %s(%d), normal exit: %d, signaled: %d, exit code: %d",
|
|
||||||
svc_ident(svc, NULL, 0), pid, WIFEXITED(svc->status),
|
|
||||||
WIFSIGNALED(svc->status), WEXITSTATUS(svc->status));
|
|
||||||
if (WIFEXITED(svc->status)) {
|
|
||||||
svc->started = 1;
|
|
||||||
result = WEXITSTATUS(svc->status);
|
|
||||||
} else {
|
|
||||||
svc->started = 0;
|
|
||||||
result = 1;
|
|
||||||
}
|
|
||||||
svc->start_time = svc->pid = 0;
|
|
||||||
svc->once++;
|
|
||||||
svc_mark_clean(svc); /* done, regardless of exit status */
|
|
||||||
svc_set_state(svc, SVC_STOPPING_STATE);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SVC_TYPE_SERVICE:
|
case SVC_TYPE_SERVICE:
|
||||||
pid_file_create(svc);
|
pid_file_create(svc);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||||
if (do_progress)
|
if (do_progress && !run_block_pid)
|
||||||
print_result(result);
|
print_result(result);
|
||||||
|
if (bootstrap && !run_block_pid)
|
||||||
|
conf_save_exec_order(svc, NULL, result);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -850,17 +868,26 @@ fail:
|
|||||||
*/
|
*/
|
||||||
static void service_kill(svc_t *svc)
|
static void service_kill(svc_t *svc)
|
||||||
{
|
{
|
||||||
|
char *nm, *id = svc_ident(svc, NULL, 0);
|
||||||
|
|
||||||
service_timeout_cancel(svc);
|
service_timeout_cancel(svc);
|
||||||
|
|
||||||
if (svc->pid <= 1) {
|
if (svc->pid <= 1) {
|
||||||
/* Avoid killing ourselves or all processes ... */
|
/* Avoid killing ourselves or all processes ... */
|
||||||
dbg("%s: Aborting SIGKILL, already terminated.", svc_ident(svc, NULL, 0));
|
dbg("%s: Aborting SIGKILL, already terminated.", id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dbg("%s: Sending SIGKILL to process group %d", pid_get_name(svc->pid, NULL, 0), svc->pid);
|
nm = pid_get_name(svc->pid, NULL, 0);
|
||||||
logit(LOG_CONSOLE | LOG_NOTICE, "Stopping %s[%d], sending SIGKILL ...",
|
if (!nm) {
|
||||||
svc_ident(svc, NULL, 0), svc->pid);
|
/* PID possibly monitored by someone else? */
|
||||||
|
dbg("%s: Aborting SIGKILL, PID[%d] no longer exists.", id, svc->pid);
|
||||||
|
service_monitor(svc->pid, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dbg("%s: Sending SIGKILL to process group %d", nm, svc->pid);
|
||||||
|
logit(LOG_CONSOLE | LOG_NOTICE, "Stopping %s[%d], sending SIGKILL ...", id, svc->pid);
|
||||||
if (runlevel != 1)
|
if (runlevel != 1)
|
||||||
print_desc("Killing ", svc->desc);
|
print_desc("Killing ", svc->desc);
|
||||||
|
|
||||||
@@ -928,13 +955,21 @@ int service_stop(svc_t *svc)
|
|||||||
|
|
||||||
compose_cmdline(svc, cmdline, sizeof(cmdline));
|
compose_cmdline(svc, cmdline, sizeof(cmdline));
|
||||||
if (!svc_is_sysv(svc)) {
|
if (!svc_is_sysv(svc)) {
|
||||||
|
char *nm = pid_get_name(svc->pid, NULL, 0);
|
||||||
|
const char *sig = sig_name(svc->sighalt);
|
||||||
|
char *id = svc_ident(svc, NULL, 0);
|
||||||
|
|
||||||
if (svc->pid <= 1)
|
if (svc->pid <= 1)
|
||||||
return 1;
|
return 1;
|
||||||
|
if (!nm) {
|
||||||
|
dbg("Skipping stop (%s) of %s, PID[%d] no longer exists.", sig, id, svc->pid);
|
||||||
|
service_cleanup(svc);
|
||||||
|
svc_set_state(svc, SVC_HALTED_STATE);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
dbg("Sending %s to pid:%d name:%s", sig_name(svc->sighalt),
|
dbg("Sending %s to pid:%d name:%s", sig, svc->pid, nm);
|
||||||
svc->pid, pid_get_name(svc->pid, NULL, 0));
|
logit(LOG_CONSOLE | LOG_NOTICE, "Stopping %s[%d], sending %s ...", id, svc->pid, sig);
|
||||||
logit(LOG_CONSOLE | LOG_NOTICE, "Stopping %s[%d], sending %s ...",
|
|
||||||
svc_ident(svc, NULL, 0), svc->pid, sig_name(svc->sighalt));
|
|
||||||
} else {
|
} else {
|
||||||
logit(LOG_CONSOLE | LOG_NOTICE, "Calling '%s stop' ...", cmdline);
|
logit(LOG_CONSOLE | LOG_NOTICE, "Calling '%s stop' ...", cmdline);
|
||||||
}
|
}
|
||||||
@@ -957,7 +992,11 @@ int service_stop(svc_t *svc)
|
|||||||
if (!svc->desc[0])
|
if (!svc->desc[0])
|
||||||
do_progress = 0;
|
do_progress = 0;
|
||||||
|
|
||||||
if (runlevel != 1 && do_progress)
|
/*
|
||||||
|
* Skip run/tasks in progress, would otherwise print silly stuff
|
||||||
|
* like: "Stopping Shutting down" ...
|
||||||
|
*/
|
||||||
|
if (runlevel != 1 && do_progress && (svc_is_daemon(svc) || svc_is_sysv(svc)))
|
||||||
print_desc("Stopping ", svc->desc);
|
print_desc("Stopping ", svc->desc);
|
||||||
|
|
||||||
if (!svc_is_sysv(svc)) {
|
if (!svc_is_sysv(svc)) {
|
||||||
@@ -1013,7 +1052,7 @@ int service_stop(svc_t *svc)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (runlevel != 1 && do_progress)
|
if (runlevel != 1 && do_progress && (svc_is_daemon(svc) || svc_is_sysv(svc)))
|
||||||
print_result(rc);
|
print_result(rc);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
@@ -1379,7 +1418,11 @@ static void parse_cmdline_args(svc_t *svc, char *cmd, char **args)
|
|||||||
* before they are started. Or restarted, or even SIGHUP'ed, when the
|
* before they are started. Or restarted, or even SIGHUP'ed, when the
|
||||||
* gateway changes or interfaces come and go. The special case when a
|
* gateway changes or interfaces come and go. The special case when a
|
||||||
* service is declared with <!> means it does not support SIGHUP but
|
* service is declared with <!> means it does not support SIGHUP but
|
||||||
* must be STOP/START'ed at system reconfiguration.
|
* must be STOP/START'ed at system reconfiguration. For run/task a <!>
|
||||||
|
* means Finit can relax its promise to run at least once per runlevel.
|
||||||
|
* I.e., for run/task conditions that would otherwise block bootstrap:
|
||||||
|
*
|
||||||
|
* task [S0123456789] <!sys/pwr/fail> name:pwrfail initctl poweroff -- Power failure, shutting down
|
||||||
*
|
*
|
||||||
* Conditions can for example be: pid/NAME:ID for process dependencies,
|
* Conditions can for example be: pid/NAME:ID for process dependencies,
|
||||||
* net/<IFNAME>/up or net/<IFNAME>/exists. The condition handling is
|
* net/<IFNAME>/up or net/<IFNAME>/exists. The condition handling is
|
||||||
@@ -1408,6 +1451,7 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
|||||||
char *id = NULL, *env = NULL, *cgroup = NULL;
|
char *id = NULL, *env = NULL, *cgroup = NULL;
|
||||||
char *pre_script = NULL, *post_script = NULL;
|
char *pre_script = NULL, *post_script = NULL;
|
||||||
char *ready_script = NULL, *conflict = NULL;
|
char *ready_script = NULL, *conflict = NULL;
|
||||||
|
char ident[MAX_IDENT_LEN];
|
||||||
char *ifstmt = NULL;
|
char *ifstmt = NULL;
|
||||||
char *notify = NULL;
|
char *notify = NULL;
|
||||||
struct tty tty = { 0 };
|
struct tty tty = { 0 };
|
||||||
@@ -1532,8 +1576,16 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
name = parse_name(cmd, name);
|
name = parse_name(cmd, name);
|
||||||
if (!id)
|
strlcpy(ident, name, sizeof(ident));
|
||||||
|
if (!id) {
|
||||||
id = "";
|
id = "";
|
||||||
|
} else {
|
||||||
|
strlcat(ident, ":", sizeof(ident));
|
||||||
|
strlcat(ident, id, sizeof(ident));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ifstmt && !svc_ifthen(1, ident, ifstmt))
|
||||||
|
return 0;
|
||||||
|
|
||||||
levels = conf_parse_runlevels(runlevels);
|
levels = conf_parse_runlevels(runlevels);
|
||||||
if (runlevel != INIT_LEVEL && !ISOTHER(levels, INIT_LEVEL)) {
|
if (runlevel != INIT_LEVEL && !ISOTHER(levels, INIT_LEVEL)) {
|
||||||
@@ -1878,6 +1930,17 @@ done:
|
|||||||
/* No longer running, update books. */
|
/* No longer running, update books. */
|
||||||
svc->start_time = svc->pid = 0;
|
svc->start_time = svc->pid = 0;
|
||||||
cont:
|
cont:
|
||||||
|
if (lost == run_block_pid) {
|
||||||
|
int result = WIFEXITED(status) ? WEXITSTATUS(status) : 1;
|
||||||
|
|
||||||
|
svc_mark_clean(svc); /* done, regardless of exit status */
|
||||||
|
run_block_pid = 0;
|
||||||
|
if (svc->desc[0])
|
||||||
|
print_result(result);
|
||||||
|
if (bootstrap)
|
||||||
|
conf_save_exec_order(svc, NULL, result);
|
||||||
|
}
|
||||||
|
|
||||||
if (!service_step(svc)) {
|
if (!service_step(svc)) {
|
||||||
/* Clean out any bootstrap tasks, they've had their time in the sun. */
|
/* Clean out any bootstrap tasks, they've had their time in the sun. */
|
||||||
if (svc_clean_bootstrap(svc))
|
if (svc_clean_bootstrap(svc))
|
||||||
@@ -1933,7 +1996,7 @@ void service_mark_unavail(void)
|
|||||||
if (!svc->ifstmt[0])
|
if (!svc->ifstmt[0])
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!svc_ifthen(svc_ident(svc, buf, sizeof(buf)), svc->ifstmt))
|
if (!svc_ifthen(1, svc_ident(svc, buf, sizeof(buf)), svc->ifstmt))
|
||||||
svc_mark(svc);
|
svc_mark(svc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2161,6 +2224,7 @@ static void service_retry(svc_t *svc)
|
|||||||
static void svc_set_state(svc_t *svc, svc_state_t new_state)
|
static void svc_set_state(svc_t *svc, svc_state_t new_state)
|
||||||
{
|
{
|
||||||
svc_state_t *state = (svc_state_t *)&svc->state;
|
svc_state_t *state = (svc_state_t *)&svc->state;
|
||||||
|
const svc_state_t old_state = svc->state;
|
||||||
|
|
||||||
/* if PID isn't collected within SVC_TERM_TIMEOUT msec, kill it! */
|
/* if PID isn't collected within SVC_TERM_TIMEOUT msec, kill it! */
|
||||||
if (new_state == SVC_STOPPING_STATE) {
|
if (new_state == SVC_STOPPING_STATE) {
|
||||||
@@ -2181,7 +2245,7 @@ static void svc_set_state(svc_t *svc, svc_state_t new_state)
|
|||||||
snprintf(failure, sizeof(failure), "%s/%s/failure", svc_typestr(svc), svc_ident(svc, NULL, 0));
|
snprintf(failure, sizeof(failure), "%s/%s/failure", svc_typestr(svc), svc_ident(svc, NULL, 0));
|
||||||
|
|
||||||
/* create success/failure condition when entering SVC_DONE_STATE. */
|
/* create success/failure condition when entering SVC_DONE_STATE. */
|
||||||
if (*state == SVC_DONE_STATE) {
|
if (new_state == SVC_DONE_STATE) {
|
||||||
if (svc->started && !WEXITSTATUS(svc->status))
|
if (svc->started && !WEXITSTATUS(svc->status))
|
||||||
cond_set_oneshot(success);
|
cond_set_oneshot(success);
|
||||||
else
|
else
|
||||||
@@ -2189,7 +2253,7 @@ static void svc_set_state(svc_t *svc, svc_state_t new_state)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* clear all conditions when entering SVC_HALTED_STATE. */
|
/* clear all conditions when entering SVC_HALTED_STATE. */
|
||||||
if (*state == SVC_HALTED_STATE) {
|
if (new_state == SVC_HALTED_STATE) {
|
||||||
cond_clear(success);
|
cond_clear(success);
|
||||||
cond_clear(failure);
|
cond_clear(failure);
|
||||||
}
|
}
|
||||||
@@ -2199,9 +2263,14 @@ static void svc_set_state(svc_t *svc, svc_state_t new_state)
|
|||||||
char cond[MAX_COND_LEN];
|
char cond[MAX_COND_LEN];
|
||||||
|
|
||||||
snprintf(cond, sizeof(cond), "service/%s/", svc_ident(svc, NULL, 0));
|
snprintf(cond, sizeof(cond), "service/%s/", svc_ident(svc, NULL, 0));
|
||||||
cond_clear(cond);
|
|
||||||
|
|
||||||
switch (svc->state) {
|
if ((old_state == SVC_RUNNING_STATE && new_state == SVC_PAUSED_STATE) ||
|
||||||
|
(old_state == SVC_PAUSED_STATE && new_state == SVC_RUNNING_STATE))
|
||||||
|
; /* only paused during reload, don't clear conds. */
|
||||||
|
else
|
||||||
|
cond_clear(cond);
|
||||||
|
|
||||||
|
switch (new_state) {
|
||||||
case SVC_HALTED_STATE:
|
case SVC_HALTED_STATE:
|
||||||
case SVC_RUNNING_STATE:
|
case SVC_RUNNING_STATE:
|
||||||
strlcat(cond, svc_status(svc), sizeof(cond));
|
strlcat(cond, svc_status(svc), sizeof(cond));
|
||||||
@@ -2251,11 +2320,11 @@ void service_ready(svc_t *svc)
|
|||||||
*/
|
*/
|
||||||
int service_step(svc_t *svc)
|
int service_step(svc_t *svc)
|
||||||
{
|
{
|
||||||
cond_state_t cond;
|
|
||||||
svc_state_t old_state;
|
|
||||||
svc_cmd_t enabled;
|
|
||||||
char *restart_cnt = (char *)&svc->restart_cnt;
|
char *restart_cnt = (char *)&svc->restart_cnt;
|
||||||
int changed = 0;
|
int changed = 0, waiting = 0;
|
||||||
|
svc_state_t old_state;
|
||||||
|
cond_state_t cond;
|
||||||
|
svc_cmd_t enabled;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
restart:
|
restart:
|
||||||
@@ -2272,9 +2341,11 @@ restart:
|
|||||||
svc_set_state(svc, SVC_WAITING_STATE);
|
svc_set_state(svc, SVC_WAITING_STATE);
|
||||||
else {
|
else {
|
||||||
if (svc_is_conflict(svc)) {
|
if (svc_is_conflict(svc)) {
|
||||||
|
#if 0
|
||||||
logit(svc->nowarn ? LOG_DEBUG : LOG_INFO,
|
logit(svc->nowarn ? LOG_DEBUG : LOG_INFO,
|
||||||
"%s in conflict with %s, checking again ...",
|
"%s in conflict with %s, checking again ...",
|
||||||
svc_ident(svc, NULL, 0), svc->conflict);
|
svc_ident(svc, NULL, 0), svc->conflict);
|
||||||
|
#endif
|
||||||
if (!svc_conflicts(svc))
|
if (!svc_conflicts(svc))
|
||||||
svc_unblock(svc);
|
svc_unblock(svc);
|
||||||
}
|
}
|
||||||
@@ -2372,6 +2443,10 @@ restart:
|
|||||||
|
|
||||||
err = service_start(svc);
|
err = service_start(svc);
|
||||||
if (err) {
|
if (err) {
|
||||||
|
/* Busy, waiting for run task, try again later */
|
||||||
|
if (run_block_pid)
|
||||||
|
break;
|
||||||
|
|
||||||
if (svc_is_missing(svc)) {
|
if (svc_is_missing(svc)) {
|
||||||
svc_set_state(svc, SVC_HALTED_STATE);
|
svc_set_state(svc, SVC_HALTED_STATE);
|
||||||
break;
|
break;
|
||||||
@@ -2413,6 +2488,7 @@ restart:
|
|||||||
|
|
||||||
if (svc_is_runtask(svc)) { /* only run/task, not sysv here */
|
if (svc_is_runtask(svc)) { /* only run/task, not sysv here */
|
||||||
svc_set_state(svc, SVC_STOPPING_STATE);
|
svc_set_state(svc, SVC_STOPPING_STATE);
|
||||||
|
svc->restart_tot++;
|
||||||
svc->once++;
|
svc->once++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -2432,7 +2508,7 @@ restart:
|
|||||||
|
|
||||||
case COND_ON:
|
case COND_ON:
|
||||||
if (svc_is_changed(svc)) {
|
if (svc_is_changed(svc)) {
|
||||||
if (svc_nohup(svc))
|
if (svc_nohup(svc) || !svc_is_daemon(svc))
|
||||||
service_stop(svc);
|
service_stop(svc);
|
||||||
else {
|
else {
|
||||||
/*
|
/*
|
||||||
@@ -2490,6 +2566,9 @@ restart:
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Are we waiting for a run task to complete? */
|
||||||
|
waiting = run_block_pid;
|
||||||
|
|
||||||
if (svc->state != old_state) {
|
if (svc->state != old_state) {
|
||||||
dbg("%20s(%4d): -> %8s", svc_ident(svc, NULL, 0), svc->pid, svc_status(svc));
|
dbg("%20s(%4d): -> %8s", svc_ident(svc, NULL, 0), svc->pid, svc_status(svc));
|
||||||
changed++;
|
changed++;
|
||||||
@@ -2501,7 +2580,7 @@ done:
|
|||||||
* When a run/task/service changes state, e.g. transitioning from
|
* When a run/task/service changes state, e.g. transitioning from
|
||||||
* waiting to running, other services may need to change state too.
|
* waiting to running, other services may need to change state too.
|
||||||
*/
|
*/
|
||||||
if (changed)
|
if (changed || waiting)
|
||||||
schedule_work(&work);
|
schedule_work(&work);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -2530,7 +2609,12 @@ void service_runtask_clean(void)
|
|||||||
if (!svc_is_runtask(svc))
|
if (!svc_is_runtask(svc))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
svc->once = 0;
|
/* run/task declared with <!> */
|
||||||
|
if (svc->sighup)
|
||||||
|
svc->once = 1;
|
||||||
|
else
|
||||||
|
svc->once = 0;
|
||||||
|
|
||||||
if (svc->state == SVC_DONE_STATE)
|
if (svc->state == SVC_DONE_STATE)
|
||||||
svc_set_state(svc, SVC_HALTED_STATE);
|
svc_set_state(svc, SVC_HALTED_STATE);
|
||||||
}
|
}
|
||||||
@@ -2538,6 +2622,7 @@ void service_runtask_clean(void)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* service_completed - Have run/task completed in current runlevel
|
* service_completed - Have run/task completed in current runlevel
|
||||||
|
* @svcp: On %FALSE return, this points to the first incomplete svc
|
||||||
*
|
*
|
||||||
* This function checks if all run/task have run once in the current
|
* This function checks if all run/task have run once in the current
|
||||||
* runlevel. E.g., at bootstrap we must wait for these scripts or
|
* runlevel. E.g., at bootstrap we must wait for these scripts or
|
||||||
@@ -2550,7 +2635,7 @@ void service_runtask_clean(void)
|
|||||||
* Returns:
|
* Returns:
|
||||||
* %TRUE(1) or %FALSE(0)
|
* %TRUE(1) or %FALSE(0)
|
||||||
*/
|
*/
|
||||||
int service_completed(void)
|
int service_completed(svc_t **svcp)
|
||||||
{
|
{
|
||||||
svc_t *svc, *iter = NULL;
|
svc_t *svc, *iter = NULL;
|
||||||
|
|
||||||
@@ -2572,6 +2657,8 @@ int service_completed(void)
|
|||||||
|
|
||||||
if (!svc->once) {
|
if (!svc->once) {
|
||||||
dbg("%s has not yet completed ...", svc_ident(svc, NULL, 0));
|
dbg("%s has not yet completed ...", svc_ident(svc, NULL, 0));
|
||||||
|
if (svcp)
|
||||||
|
*svcp = svc;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
dbg("%s has completed ...", svc_ident(svc, NULL, 0));
|
dbg("%s has completed ...", svc_ident(svc, NULL, 0));
|
||||||
@@ -2691,23 +2778,24 @@ static void service_interval_cb(uev_t *w, void *arg, int events)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
service_init();
|
service_init(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The service_interval may change (conf) between invocations, so we
|
* The service_interval may change (conf) between invocations, so we
|
||||||
* periodically reset the one-shot timer instead of using a periodic.
|
* periodically reset the one-shot timer instead of using a periodic.
|
||||||
*/
|
*/
|
||||||
void service_init(void)
|
void service_init(uev_ctx_t *ctx)
|
||||||
{
|
{
|
||||||
static int initialized = 0;
|
static int initialized = 0;
|
||||||
static uev_t watcher;
|
static uev_t watcher;
|
||||||
|
|
||||||
if (!initialized) {
|
if (!initialized)
|
||||||
uev_timer_init(ctx, &watcher, service_interval_cb, NULL, service_interval, 0);
|
uev_timer_init(ctx, &watcher, service_interval_cb, NULL, service_interval, 0);
|
||||||
initialized = 1;
|
else
|
||||||
} else
|
|
||||||
uev_timer_set(&watcher, service_interval, 0);
|
uev_timer_set(&watcher, service_interval, 0);
|
||||||
|
|
||||||
|
initialized = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+2
-2
@@ -49,10 +49,10 @@ int service_step (svc_t *svc);
|
|||||||
void service_step_all (int types);
|
void service_step_all (int types);
|
||||||
void service_worker (void *unused);
|
void service_worker (void *unused);
|
||||||
|
|
||||||
int service_completed (void);
|
int service_completed (svc_t **svc);
|
||||||
void service_notify_reconf (void);
|
void service_notify_reconf (void);
|
||||||
|
|
||||||
void service_init (void);
|
void service_init (uev_ctx_t *ctx);
|
||||||
|
|
||||||
#endif /* FINIT_SERVICE_H_ */
|
#endif /* FINIT_SERVICE_H_ */
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "private.h"
|
#include "private.h"
|
||||||
|
#include "schedule.h"
|
||||||
#include "service.h"
|
#include "service.h"
|
||||||
#include "sig.h"
|
#include "sig.h"
|
||||||
#include "tty.h"
|
#include "tty.h"
|
||||||
@@ -43,12 +44,61 @@ sm_t sm;
|
|||||||
#define FINIT_NOLOGIN_PATH _PATH_NOLOGIN /* Stop user logging in. */
|
#define FINIT_NOLOGIN_PATH _PATH_NOLOGIN /* Stop user logging in. */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void sm_init(sm_t *sm)
|
/*
|
||||||
|
* Wait for system bootstrap to complete, all SVC_TYPE_RUNTASK must be
|
||||||
|
* allowed to complete their work in [S], or timeout, before we switch
|
||||||
|
* to the configured runlevel and call finalize(), should not take more
|
||||||
|
* than 120 sec.
|
||||||
|
*/
|
||||||
|
static void sm_check_bootstrap(void *work)
|
||||||
{
|
{
|
||||||
sm->state = SM_BOOTSTRAP_STATE;
|
static int timeout = 120;
|
||||||
sm->newlevel = -1;
|
int bootstrap_done;
|
||||||
sm->reload = 0;
|
int level = cfglevel;
|
||||||
sm->in_teardown = 0;
|
svc_t *svc = NULL;
|
||||||
|
|
||||||
|
dbg("Step all services ...");
|
||||||
|
service_step_all(SVC_TYPE_ANY);
|
||||||
|
|
||||||
|
bootstrap_done = service_completed(&svc);
|
||||||
|
if (timeout-- > 0 && !bootstrap_done) {
|
||||||
|
dbg("Not all bootstrap run/tasks have completed yet ... %d", timeout);
|
||||||
|
schedule_work(work);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (timeout > 0) {
|
||||||
|
dbg("All run/task have completed, resuming bootstrap.");
|
||||||
|
} else {
|
||||||
|
dbg("Timeout, resuming bootstrap.");
|
||||||
|
if (svc)
|
||||||
|
print(2, "Timeout waiting for %s to run, resuming bootstrap", svc_ident(svc, NULL, 0));
|
||||||
|
else
|
||||||
|
print(2, "Timeout waiting for unknown run/task, resuming bootstrap");
|
||||||
|
}
|
||||||
|
|
||||||
|
dbg("Flushing pending .conf file events ...");
|
||||||
|
conf_flush_events();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Start all tasks/services in the configured runlevel, or jump
|
||||||
|
* into the runlevel selected from the command line.
|
||||||
|
*/
|
||||||
|
if (cmdlevel) {
|
||||||
|
dbg("Runlevel %d requested from command line, starting all services ...", cmdlevel);
|
||||||
|
level = cmdlevel;
|
||||||
|
} else
|
||||||
|
dbg("Change to default runlevel(%d), starting all services ...", cfglevel);
|
||||||
|
|
||||||
|
service_runlevel(level);
|
||||||
|
|
||||||
|
/* Clean up bootstrap-only tasks/services that never started */
|
||||||
|
dbg("Clean up all bootstrap-only tasks/services ...");
|
||||||
|
svc_prune_bootstrap();
|
||||||
|
|
||||||
|
/* All services/tasks/etc. in configure runlevel have started */
|
||||||
|
dbg("Running svc up hooks ...");
|
||||||
|
plugin_run_hooks(HOOK_SVC_UP);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *sm_status(sm_state_t state)
|
static char *sm_status(sm_state_t state)
|
||||||
@@ -100,6 +150,22 @@ static void nologin(void)
|
|||||||
erase(FINIT_NOLOGIN_PATH);
|
erase(FINIT_NOLOGIN_PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sm_init(sm_t *sm)
|
||||||
|
{
|
||||||
|
static struct wq work = {
|
||||||
|
.cb = sm_check_bootstrap,
|
||||||
|
.delay = 1000
|
||||||
|
};
|
||||||
|
|
||||||
|
sm->state = SM_BOOTSTRAP_STATE;
|
||||||
|
sm->newlevel = -1;
|
||||||
|
sm->reload = 0;
|
||||||
|
sm->in_teardown = 0;
|
||||||
|
|
||||||
|
dbg("Starting bootstrap finalize timer ...");
|
||||||
|
schedule_work(&work);
|
||||||
|
}
|
||||||
|
|
||||||
void sm_set_runlevel(sm_t *sm, int newlevel)
|
void sm_set_runlevel(sm_t *sm, int newlevel)
|
||||||
{
|
{
|
||||||
sm->newlevel = newlevel;
|
sm->newlevel = newlevel;
|
||||||
@@ -117,8 +183,8 @@ int sm_is_in_teardown(sm_t *sm)
|
|||||||
|
|
||||||
void sm_step(sm_t *sm)
|
void sm_step(sm_t *sm)
|
||||||
{
|
{
|
||||||
svc_t *svc;
|
|
||||||
sm_state_t old_state;
|
sm_state_t old_state;
|
||||||
|
svc_t *svc;
|
||||||
|
|
||||||
restart:
|
restart:
|
||||||
old_state = sm->state;
|
old_state = sm->state;
|
||||||
@@ -130,10 +196,49 @@ restart:
|
|||||||
case SM_BOOTSTRAP_STATE:
|
case SM_BOOTSTRAP_STATE:
|
||||||
dbg("Bootstrapping all services in runlevel S from %s", finit_conf);
|
dbg("Bootstrapping all services in runlevel S from %s", finit_conf);
|
||||||
service_step_all(SVC_TYPE_RUNTASK | SVC_TYPE_SERVICE);
|
service_step_all(SVC_TYPE_RUNTASK | SVC_TYPE_SERVICE);
|
||||||
|
|
||||||
|
sm->state = SM_BOOTSTRAP_WAIT_STATE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Handle bootstrap transition to configured runlevel, start TTYs
|
||||||
|
*
|
||||||
|
* This is the final stage of bootstrap. It changes to the default
|
||||||
|
* (configured) runlevel, calls all external start scripts and final
|
||||||
|
* bootstrap hooks before bringing up TTYs.
|
||||||
|
*
|
||||||
|
* We must ensure that all declared `task [S]` and `run [S]` jobs in
|
||||||
|
* finit.conf, or *.conf in finit.d/, run to completion before we
|
||||||
|
* finalize the bootstrap process by calling this function.
|
||||||
|
*/
|
||||||
|
case SM_BOOTSTRAP_WAIT_STATE:
|
||||||
|
/* We come here from bootstrap, runlevel change and conf reload */
|
||||||
|
service_step_all(SVC_TYPE_ANY);
|
||||||
|
|
||||||
|
/* Allow runparts to start */
|
||||||
|
cond_set("int/bootstrap");
|
||||||
|
|
||||||
|
if (sm->newlevel == -1)
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Hooks that should run at the very end */
|
||||||
|
dbg("Calling all system up hooks ...");
|
||||||
|
plugin_run_hooks(HOOK_SYSTEM_UP);
|
||||||
|
service_step_all(SVC_TYPE_ANY);
|
||||||
|
|
||||||
|
/* Disable progress output at normal runtime */
|
||||||
|
enable_progress(0);
|
||||||
|
|
||||||
|
/* System bootrapped, launch TTYs et al */
|
||||||
|
bootstrap = 0;
|
||||||
|
service_step_all(SVC_TYPE_RESPAWN);
|
||||||
sm->state = SM_RUNNING_STATE;
|
sm->state = SM_RUNNING_STATE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SM_RUNNING_STATE:
|
case SM_RUNNING_STATE:
|
||||||
|
/* We come here from bootstrap, runlevel change and conf reload */
|
||||||
|
service_step_all(SVC_TYPE_ANY);
|
||||||
|
|
||||||
/* runlevel changed? */
|
/* runlevel changed? */
|
||||||
if (sm->newlevel >= 0 && sm->newlevel <= 9) {
|
if (sm->newlevel >= 0 && sm->newlevel <= 9) {
|
||||||
if (runlevel == sm->newlevel) {
|
if (runlevel == sm->newlevel) {
|
||||||
@@ -143,6 +248,7 @@ restart:
|
|||||||
sm->state = SM_RUNLEVEL_CHANGE_STATE;
|
sm->state = SM_RUNLEVEL_CHANGE_STATE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* reload ? */
|
/* reload ? */
|
||||||
if (sm->reload) {
|
if (sm->reload) {
|
||||||
sm->reload = 0;
|
sm->reload = 0;
|
||||||
@@ -210,17 +316,18 @@ restart:
|
|||||||
/* Cleanup stale services */
|
/* Cleanup stale services */
|
||||||
svc_clean_dynamic(service_unregister);
|
svc_clean_dynamic(service_unregister);
|
||||||
|
|
||||||
|
/* Compat SysV init */
|
||||||
|
if (prevlevel == INIT_LEVEL && !rescue)
|
||||||
|
run_bg(FINIT_RC_LOCAL, NULL);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "I've seen things you people wouldn't believe. Attack ships on fire off
|
* "I've seen things you people wouldn't believe. Attack ships on fire off
|
||||||
* the shoulder of Orion. I watched C-beams glitter in the dark near the
|
* the shoulder of Orion. I watched C-beams glitter in the dark near the
|
||||||
* Tannhäuser Gate. All those .. moments .. will be lost in time, like
|
* Tannhäuser Gate. All those .. moments .. will be lost in time, like
|
||||||
* tears ... in ... rain."
|
* tears ... in ... rain."
|
||||||
*/
|
*/
|
||||||
if (runlevel == 0 || runlevel == 6) {
|
if (runlevel == 0 || runlevel == 6)
|
||||||
do_shutdown(halt);
|
do_shutdown(halt);
|
||||||
sm->state = SM_RUNNING_STATE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
sm->state = SM_RUNNING_STATE;
|
sm->state = SM_RUNNING_STATE;
|
||||||
break;
|
break;
|
||||||
@@ -266,9 +373,7 @@ restart:
|
|||||||
dbg("Update configuration generation of unmodified non-native services ...");
|
dbg("Update configuration generation of unmodified non-native services ...");
|
||||||
service_notify_reconf();
|
service_notify_reconf();
|
||||||
|
|
||||||
service_step_all(SVC_TYPE_ANY);
|
|
||||||
dbg("Reconfiguration done");
|
dbg("Reconfiguration done");
|
||||||
|
|
||||||
sm->state = SM_RUNNING_STATE;
|
sm->state = SM_RUNNING_STATE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SM_BOOTSTRAP_STATE = 0, /* Init state, bootstrap services */
|
SM_BOOTSTRAP_STATE = 0, /* Init state, bootstrap services */
|
||||||
|
SM_BOOTSTRAP_WAIT_STATE, /* Waiting for bootstrap to complete */
|
||||||
SM_RUNNING_STATE, /* Normal state, services running */
|
SM_RUNNING_STATE, /* Normal state, services running */
|
||||||
SM_RUNLEVEL_CHANGE_STATE, /* A runlevel change has occurred */
|
SM_RUNLEVEL_CHANGE_STATE, /* A runlevel change has occurred */
|
||||||
SM_RUNLEVEL_WAIT_STATE, /* Waiting for all stopped runlevel processes to be halted */
|
SM_RUNLEVEL_WAIT_STATE, /* Waiting for all stopped runlevel processes to be halted */
|
||||||
|
|||||||
+9
-3
@@ -21,6 +21,8 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include <crypt.h>
|
#include <crypt.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <paths.h>
|
#include <paths.h>
|
||||||
@@ -32,6 +34,10 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
|
#ifndef SULOGIN_USER
|
||||||
|
#define SULOGIN_USER "root"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* getpwnam() cannot be used when statically linked */
|
/* getpwnam() cannot be used when statically linked */
|
||||||
static int get_passwd(struct passwd *pw)
|
static int get_passwd(struct passwd *pw)
|
||||||
{
|
{
|
||||||
@@ -44,13 +50,13 @@ static int get_passwd(struct passwd *pw)
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
while ((tmp = fgets(buf, sizeof(buf), fp))) {
|
while ((tmp = fgets(buf, sizeof(buf), fp))) {
|
||||||
if (!strstr(buf, ":0:0:"))
|
|
||||||
continue; /* not uid 0 */
|
|
||||||
|
|
||||||
ptr = strsep(&tmp, ":");
|
ptr = strsep(&tmp, ":");
|
||||||
if (!ptr)
|
if (!ptr)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
pw->pw_name = strdup(ptr);
|
pw->pw_name = strdup(ptr);
|
||||||
|
if (!pw->pw_name || strcmp(pw->pw_name, SULOGIN_USER))
|
||||||
|
continue;
|
||||||
|
|
||||||
ptr = strsep(&tmp, ":");
|
ptr = strsep(&tmp, ":");
|
||||||
if (!ptr)
|
if (!ptr)
|
||||||
|
|||||||
@@ -634,17 +634,30 @@ int svc_enabled(svc_t *svc)
|
|||||||
if (!svc)
|
if (!svc)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!svc_in_runlevel(svc, runlevel))
|
if (!svc_in_runlevel(svc, runlevel)) {
|
||||||
|
// dbg("Not in runlevel");
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (svc_is_removed(svc) || svc_is_blocked(svc))
|
if (svc_is_removed(svc) || svc_is_blocked(svc)) {
|
||||||
|
// dbg("removed (%d) / blocked (%d)", svc->removed, svc->block);
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (svc_is_missing(svc))
|
if (svc_is_missing(svc)) {
|
||||||
|
// dbg("missing");
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (svc_is_tty(svc) && bootstrap)
|
if (!svc_ifthen(0, NULL, svc->ifstmt)) {
|
||||||
|
// dbg("ifthen:%s>", svc->ifstmt[0] ? svc->ifstmt : "<");
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (svc_is_tty(svc) && bootstrap) {
|
||||||
|
// dbg("is tty in bootstrap");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -688,14 +701,16 @@ int svc_conflicts(svc_t *svc)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* svc_ifthen - Check if: statement in declaration
|
* svc_ifthen - Check if: statement in declaration
|
||||||
|
* @is_conf: Set when called by service_mark_unavail()
|
||||||
* @ident: svc_t identififcation (name:id)
|
* @ident: svc_t identififcation (name:id)
|
||||||
* @stmt: if: statement from .conf file
|
* @stmt: if: statement from .conf file
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* %TRUE(1) yes, use this svc_t, %FALSE(0) prune
|
* %TRUE(1) yes, use this svc_t, %FALSE(0) prune
|
||||||
*/
|
*/
|
||||||
int svc_ifthen(const char *ident, char *stmt)
|
int svc_ifthen(int is_conf, const char *ident, char *stmt)
|
||||||
{
|
{
|
||||||
|
char stmts[MAX_IDENT_LEN];
|
||||||
int not = 0;
|
int not = 0;
|
||||||
svc_t *svc;
|
svc_t *svc;
|
||||||
|
|
||||||
@@ -707,40 +722,49 @@ int svc_ifthen(const char *ident, char *stmt)
|
|||||||
char *ptr = ++stmt;
|
char *ptr = ++stmt;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
if (stmt[0] == '!') {
|
if (is_conf)
|
||||||
stmt++;
|
return 1;
|
||||||
not++;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (ptr[i] != '>' && ptr[i] != 0)
|
while (ptr[i] != '>' && ptr[i] != 0)
|
||||||
i++;
|
i++;
|
||||||
ptr[i] = 0;
|
ptr[i] = 0;
|
||||||
|
|
||||||
cond = cond_get(stmt);
|
strlcpy(stmts, stmt, sizeof(stmts));
|
||||||
if (not && cond == COND_ON) {
|
for (stmt = strtok(stmts, ","); stmt; stmt = strtok(NULL, ","), not = 0) {
|
||||||
logit(LOG_NOTICE, "skipping %s, cond %s is on.", ident, stmt);
|
if (stmt[0] == '!') {
|
||||||
return 0;
|
stmt++;
|
||||||
}
|
not++;
|
||||||
if (!not && cond == COND_OFF) {
|
}
|
||||||
logit(LOG_NOTICE, "skipping %s, cond %s is off.", ident, stmt);
|
|
||||||
return 0;
|
cond = cond_get(stmt);
|
||||||
|
if (not && cond == COND_ON)
|
||||||
|
return 0;
|
||||||
|
if (!not && cond == COND_OFF)
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stmt[0] == '!') {
|
if (!is_conf)
|
||||||
stmt++;
|
return 1;
|
||||||
not++;
|
|
||||||
}
|
|
||||||
|
|
||||||
svc = svc_find_by_str(stmt);
|
strlcpy(stmts, stmt, sizeof(stmts));
|
||||||
if (not && svc) {
|
for (stmt = strtok(stmts, ","); stmt; stmt = strtok(NULL, ","), not = 0) {
|
||||||
logit(LOG_NOTICE, "skipping %s, %s already loaded.", ident, svc_ident(svc, NULL, 0));
|
if (stmt[0] == '!') {
|
||||||
return 0;
|
stmt++;
|
||||||
}
|
not++;
|
||||||
if (!not && !svc) {
|
}
|
||||||
logit(LOG_NOTICE, "skipping %s, %s not available.", ident, stmt);
|
|
||||||
return 0;
|
svc = svc_find_by_str(stmt);
|
||||||
|
if (not && svc) {
|
||||||
|
logit(LOG_NOTICE, "skipping %s, %s already loaded.", ident, svc_ident(svc, NULL, 0));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (!not && !svc) {
|
||||||
|
logit(LOG_NOTICE, "skipping %s, %s not available.", ident, stmt);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ typedef enum {
|
|||||||
|
|
||||||
#define MAX_ID_LEN 16
|
#define MAX_ID_LEN 16
|
||||||
#define MAX_ARG_LEN 64
|
#define MAX_ARG_LEN 64
|
||||||
|
#define MAX_CMD_LEN 256
|
||||||
#define MAX_IDENT_LEN (MAX_ARG_LEN + MAX_ID_LEN + 1)
|
#define MAX_IDENT_LEN (MAX_ARG_LEN + MAX_ID_LEN + 1)
|
||||||
#define MAX_STR_LEN 64
|
#define MAX_STR_LEN 64
|
||||||
#define MAX_COND_LEN (MAX_ARG_LEN * 3)
|
#define MAX_COND_LEN (MAX_ARG_LEN * 3)
|
||||||
@@ -118,7 +119,7 @@ typedef struct svc {
|
|||||||
int sighalt; /* Signal to stop process, default: SIGTERM */
|
int sighalt; /* Signal to stop process, default: SIGTERM */
|
||||||
int killdelay; /* Delay in msec before sending SIGKILL */
|
int killdelay; /* Delay in msec before sending SIGKILL */
|
||||||
pid_t oldpid, pid;
|
pid_t oldpid, pid;
|
||||||
char pidfile[256];
|
char pidfile[MAX_CMD_LEN];
|
||||||
long start_time; /* Start time, as seconds since boot, from sysinfo() */
|
long start_time; /* Start time, as seconds since boot, from sysinfo() */
|
||||||
int started; /* Set for run/task/sysv to track if started */
|
int started; /* Set for run/task/sysv to track if started */
|
||||||
int status; /* From waitpid() when process is collected */
|
int status; /* From waitpid() when process is collected */
|
||||||
@@ -181,15 +182,15 @@ typedef struct svc {
|
|||||||
char group[MAX_USER_LEN];
|
char group[MAX_USER_LEN];
|
||||||
|
|
||||||
/* Command, arguments and service description */
|
/* Command, arguments and service description */
|
||||||
char cmd[MAX_ARG_LEN];
|
char cmd[MAX_CMD_LEN];
|
||||||
char args[MAX_NUM_SVC_ARGS][MAX_ARG_LEN];
|
char args[MAX_NUM_SVC_ARGS][MAX_CMD_LEN];
|
||||||
int args_dirty;
|
int args_dirty;
|
||||||
char conflict[MAX_ARG_LEN];
|
char conflict[MAX_ARG_LEN];
|
||||||
char desc[MAX_STR_LEN];
|
char desc[MAX_STR_LEN];
|
||||||
char env[MAX_ARG_LEN];
|
char env[MAX_CMD_LEN];
|
||||||
char pre_script[MAX_ARG_LEN];
|
char pre_script[MAX_CMD_LEN];
|
||||||
char post_script[MAX_ARG_LEN];
|
char post_script[MAX_CMD_LEN];
|
||||||
char ready_script[MAX_ARG_LEN];
|
char ready_script[MAX_CMD_LEN];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Used to forcefully kill services that won't shutdown on
|
* Used to forcefully kill services that won't shutdown on
|
||||||
@@ -240,7 +241,7 @@ void svc_prune_bootstrap (void);
|
|||||||
void svc_enable (svc_t *svc);
|
void svc_enable (svc_t *svc);
|
||||||
int svc_enabled (svc_t *svc);
|
int svc_enabled (svc_t *svc);
|
||||||
int svc_conflicts (svc_t *svc);
|
int svc_conflicts (svc_t *svc);
|
||||||
int svc_ifthen (const char *ident, char *ifstm);
|
int svc_ifthen (int is_conf, const char *ident, char *stmt);
|
||||||
|
|
||||||
int svc_parse_jobstr (char *str, size_t len, void *user_data, int (*found)(svc_t *, void *), int (not_found)(char *, char *, void *));
|
int svc_parse_jobstr (char *str, size_t len, void *user_data, int (*found)(svc_t *, void *), int (not_found)(char *, char *, void *));
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -471,7 +471,7 @@ void tmpfilesd(void)
|
|||||||
/* in priority order */
|
/* in priority order */
|
||||||
char *dir[] = {
|
char *dir[] = {
|
||||||
FINIT_TMPFILES "/*.conf",
|
FINIT_TMPFILES "/*.conf",
|
||||||
TMPFILES_PATH "/*.conf",
|
TMPFILES_PATH_ "/*.conf",
|
||||||
"/usr/lib/tmpfiles.d/*.conf",
|
"/usr/lib/tmpfiles.d/*.conf",
|
||||||
"/run/tmpfiles.d/*.conf",
|
"/run/tmpfiles.d/*.conf",
|
||||||
"/etc/tmpfiles.d/*.conf", /* local admin overrides */
|
"/etc/tmpfiles.d/*.conf", /* local admin overrides */
|
||||||
|
|||||||
@@ -42,7 +42,10 @@ extern int ttcols;
|
|||||||
extern char *prognm;
|
extern char *prognm;
|
||||||
|
|
||||||
/* Define for printheader() from conio.h, used in initctl */
|
/* Define for printheader() from conio.h, used in initctl */
|
||||||
|
#ifndef SCREEN_WIDTH
|
||||||
#define SCREEN_WIDTH ttcols
|
#define SCREEN_WIDTH ttcols
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _LIBITE_LITE
|
#ifdef _LIBITE_LITE
|
||||||
# include <libite/conio.h>
|
# include <libite/conio.h>
|
||||||
# include <libite/lite.h>
|
# include <libite/lite.h>
|
||||||
|
|||||||
@@ -60,7 +60,6 @@ static int init(char *progname, char *devnode)
|
|||||||
signal(SIGPWR, sighandler);
|
signal(SIGPWR, sighandler);
|
||||||
|
|
||||||
openlog(&progname[1], LOG_CONS | LOG_PID, LOG_DAEMON);
|
openlog(&progname[1], LOG_CONS | LOG_PID, LOG_DAEMON);
|
||||||
syslog(LOG_INFO, "Finit v%s watchdog %s starting ...", VERSION, devnode);
|
|
||||||
|
|
||||||
fd = open(devnode, O_WRONLY);
|
fd = open(devnode, O_WRONLY);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
|
|||||||
@@ -1,2 +1,4 @@
|
|||||||
Makefile
|
Makefile
|
||||||
Makefile.in
|
Makefile.in
|
||||||
|
# generated
|
||||||
|
10-hotplug.conf
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
# System hotplug handled by udev, mdevd, or mdev (preferred order)
|
||||||
|
#
|
||||||
|
# Your system usually has either udevd, mdev, or mdevd. They probe the system
|
||||||
|
# for devices, loading modules and any firmware needed. Since the bootstrap
|
||||||
|
# often needs to be synchronized carefully, we suggest using your system log
|
||||||
|
# daemon as the barrier for all other services. E.g.:
|
||||||
|
#
|
||||||
|
# service if:udevd <run/udevadm:5/success> [S0123456789] syslogd -F -- System log daemon
|
||||||
|
# service if:mdev <run/coldplug/success> [S0123456789] syslogd -F -- System log daemon
|
||||||
|
# service if:mdevd <run/coldplug/success> [S0123456789] syslogd -F -- System log daemon
|
||||||
|
#
|
||||||
|
# This provdes a <pid/syslogd> condition that can act as a barrier for all
|
||||||
|
# other services. Notice the `if:` statement and the condition for starting
|
||||||
|
# syslogd is only considered if either udevd or mdev (service) is loaded and
|
||||||
|
# is guaranteed to run after each respective run stanza have completed.
|
||||||
|
#
|
||||||
|
# Override this file by copying it to /etc/finit.d/, using the same name, then
|
||||||
|
# change the contents any way you like, it can even be empty.
|
||||||
|
|
||||||
|
# Check for systemd-udevd and eudev, if we find both, we opt for the latter.
|
||||||
|
service nowarn [S12345789] cgroup.system name:udevd pid:udevd log /lib/systemd/systemd-udevd -- Device event daemon (udev)
|
||||||
|
service nowarn [S12345789] cgroup.system name:udevd pid:udevd log udevd -D -- Device event daemon (udev)
|
||||||
|
|
||||||
|
# Wait for udevd to start, then trigger coldplug events and module loading.
|
||||||
|
# The last 'settle' call waits for it to finalize processing all uevents.
|
||||||
|
run nowarn if:udevd cgroup.init :1 [S] <pid/udevd> log udevadm settle -t 0 --
|
||||||
|
run nowarn if:udevd cgroup.init :2 [S] <pid/udevd> log udevadm control --reload --
|
||||||
|
run nowarn if:udevd cgroup.init :3 [S] <pid/udevd> log udevadm trigger -c add -t devices -- Requesting device events
|
||||||
|
run nowarn if:udevd cgroup.init :4 [S] <pid/udevd> log udevadm trigger -c add -t subsystems -- Requesting subsystem events
|
||||||
|
run nowarn if:udevd cgroup.init :5 [S] <pid/udevd> log udevadm settle -t 30 -- Waiting for udev to finish
|
||||||
|
|
||||||
|
# If udevd is not available, check for mdevd. Unlike plain 'mdev -df', the
|
||||||
|
# mdevd-coldplug process exits when mdevd has completed. So the condition
|
||||||
|
# <run/coldplug/success> (same as for plain mdev below) can be relied on as a
|
||||||
|
# barrier for services that, e.g., need to probe for switchcore ports or PHYs
|
||||||
|
# that require firmware loading before they show up.
|
||||||
|
service nowarn conflict:udevd,mdev cgroup.init if:!udevd \
|
||||||
|
[S12345789] notify:s6 mdevd -O 4 -D %n -- Device event daemon (mdevd)
|
||||||
|
run nowarn conflict:udevd,mdev cgroup.init name:coldplug <service/mdevd/ready> \
|
||||||
|
[S] mdevd-coldplug -- Cold plugging system
|
||||||
|
|
||||||
|
# If neither udevd or mdevd are available, fall back to mdev. The new daemon
|
||||||
|
# mode calls `mdev -s` internally but does not create a PID file when that is
|
||||||
|
# done, so synchronization with coldplug is fragile.
|
||||||
|
service nowarn conflict:udevd,mdevd cgroup.init if:!udevd,!mdevd \
|
||||||
|
[S12345789] mdev -df -S -- Device event daemon (mdev)
|
||||||
|
|
||||||
|
# Trigger a replay of all uevents from boot, before userspace was up and the
|
||||||
|
# filesystem mounted. Compared to udevd, we don't know when 'mdev -df' has
|
||||||
|
# finished processing all events, i.e., depending on <run/coldplug/success> is
|
||||||
|
# not an indicator of all devices having been (re)discovered and fully set up.
|
||||||
|
run nowarn conflict:udevd,mdevd cgroup.init name:coldplug if:mdev <service/mdev/running> \
|
||||||
|
[S] @pkglibexecdir@/coldplug -- Cold plugging system
|
||||||
+4
-2
@@ -1,10 +1,12 @@
|
|||||||
|
EXTRA_DIST = 10-hotplug.conf.in
|
||||||
systemdir = $(system_path)
|
systemdir = $(system_path)
|
||||||
|
system_DATA =
|
||||||
dist_system_DATA =
|
dist_system_DATA =
|
||||||
|
|
||||||
if BUILD_HOTPLUG_PLUGIN
|
if BUILD_HOTPLUG_PLUGIN
|
||||||
dist_system_DATA += hotplug.conf
|
system_DATA += 10-hotplug.conf
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if BUILD_TESTSERV_PLUGIN
|
if BUILD_TESTSERV_PLUGIN
|
||||||
dist_system_DATA += testserv.conf
|
dist_system_DATA += 90-testserv.conf
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
# System hotplug can be handled by udev or mdev
|
|
||||||
|
|
||||||
# Either we have systemd-udevd or eudev, on the rare occasion we find
|
|
||||||
# both, we opt for the latter. Remember, you can override this by a
|
|
||||||
# custom hotplug.conf in /etc/finit.d/ or /etc/finit.d/enabled/.
|
|
||||||
service nowarn [S12345789] cgroup.system name:udevd pid:udevd log /lib/systemd/systemd-udevd -- Device event managing daemon
|
|
||||||
service nowarn [S12345789] cgroup.system name:udevd pid:udevd log udevd -- Device event managing daemon
|
|
||||||
|
|
||||||
# Wait for udevd to start, then wait a couple of seconds for it to become ready
|
|
||||||
run nowarn if:udevd cgroup.init [S] <pid/udevd> udevadm settle -t 0 --
|
|
||||||
run nowarn if:udevd cgroup.init [S] <pid/udevd> log udevadm control --reload
|
|
||||||
run nowarn if:udevd cgroup.init :1 [S] <pid/udevd> log udevadm trigger -c add -t devices -- Requesting device events
|
|
||||||
run nowarn if:udevd cgroup.init :2 [S] <pid/udevd> log udevadm trigger -c add -t subsystems -- Requesting subsystem events
|
|
||||||
run nowarn if:udevd cgroup.init [S] <pid/udevd> log udevadm settle -t 5 -- Waiting for udev to finish
|
|
||||||
|
|
||||||
# If udevd is not available, try mdev
|
|
||||||
run nowarn conflict:udevd [S] mdev -s -- Populating device tree
|
|
||||||
+17
-1
@@ -2,7 +2,12 @@ SUBDIRS = lib src
|
|||||||
|
|
||||||
EXTRA_DIST = skel/bin/busybox-x86_64.sha256 skel/sbin/service.sh skel/etc/env \
|
EXTRA_DIST = skel/bin/busybox-x86_64.sha256 skel/sbin/service.sh skel/etc/env \
|
||||||
skel/bin/pre.sh skel/bin/post.sh skel/bin/ready.sh skel/bin/slay \
|
skel/bin/pre.sh skel/bin/post.sh skel/bin/ready.sh skel/bin/slay \
|
||||||
skel/sbin/fail.sh \
|
skel/sbin/fail.sh skel/usr/share/runparts/ref.log \
|
||||||
|
skel/usr/share/runparts/sysv.log \
|
||||||
|
skel/etc/rc.d/foo.sh skel/etc/rc.d/S01abc.sh \
|
||||||
|
skel/etc/rc.d/test.sh skel/etc/rc.d/S02def.sh \
|
||||||
|
skel/etc/rcS.d/foo.sh skel/etc/rcS.d/test.sh \
|
||||||
|
skel/etc/rcS.d/S01abc.sh skel/etc/rcS.d/S02def.sh \
|
||||||
skel/cdrom/.empty skel/dev/shm/.empty skel/dev/pts/.empty \
|
skel/cdrom/.empty skel/dev/shm/.empty skel/dev/pts/.empty \
|
||||||
skel/etc/inittab skel/etc/hostname skel/etc/fstab \
|
skel/etc/inittab skel/etc/hostname skel/etc/fstab \
|
||||||
skel/etc/init.d/rcS skel/etc/init.d/rcK skel/tmp/.empty \
|
skel/etc/init.d/rcS skel/etc/init.d/rcK skel/tmp/.empty \
|
||||||
@@ -27,6 +32,7 @@ EXTRA_DIST += crashing.sh
|
|||||||
EXTRA_DIST += depserv.sh
|
EXTRA_DIST += depserv.sh
|
||||||
EXTRA_DIST += devmon.sh
|
EXTRA_DIST += devmon.sh
|
||||||
EXTRA_DIST += failing-sysv.sh
|
EXTRA_DIST += failing-sysv.sh
|
||||||
|
EXTRA_DIST += svc-env.sh
|
||||||
EXTRA_DIST += global-envs.sh
|
EXTRA_DIST += global-envs.sh
|
||||||
EXTRA_DIST += initctl-status-subset.sh
|
EXTRA_DIST += initctl-status-subset.sh
|
||||||
EXTRA_DIST += notify.sh
|
EXTRA_DIST += notify.sh
|
||||||
@@ -37,6 +43,9 @@ EXTRA_DIST += ready-serv.sh
|
|||||||
EXTRA_DIST += restart-self.sh
|
EXTRA_DIST += restart-self.sh
|
||||||
EXTRA_DIST += runlevel.sh
|
EXTRA_DIST += runlevel.sh
|
||||||
EXTRA_DIST += run-restart-forever.sh
|
EXTRA_DIST += run-restart-forever.sh
|
||||||
|
EXTRA_DIST += run-task-tricks.sh
|
||||||
|
EXTRA_DIST += runparts.sh
|
||||||
|
EXTRA_DIST += sysvparts.sh
|
||||||
EXTRA_DIST += start-stop-service.sh
|
EXTRA_DIST += start-stop-service.sh
|
||||||
EXTRA_DIST += start-stop-service-sub-config.sh
|
EXTRA_DIST += start-stop-service-sub-config.sh
|
||||||
EXTRA_DIST += start-kill-service.sh
|
EXTRA_DIST += start-kill-service.sh
|
||||||
@@ -45,6 +54,7 @@ EXTRA_DIST += start-stop-sysv.sh
|
|||||||
EXTRA_DIST += start-stop-serv.sh
|
EXTRA_DIST += start-stop-serv.sh
|
||||||
EXTRA_DIST += signal-service.sh
|
EXTRA_DIST += signal-service.sh
|
||||||
EXTRA_DIST += testserv.sh
|
EXTRA_DIST += testserv.sh
|
||||||
|
EXTRA_DIST += unexpected-restart.sh
|
||||||
|
|
||||||
AM_TESTS_ENVIRONMENT = SYSROOT='$(abs_builddir)/sysroot/';
|
AM_TESTS_ENVIRONMENT = SYSROOT='$(abs_builddir)/sysroot/';
|
||||||
AM_TESTS_ENVIRONMENT += export SYSROOT;
|
AM_TESTS_ENVIRONMENT += export SYSROOT;
|
||||||
@@ -61,11 +71,13 @@ TEST_EXTENSIONS = .sh
|
|||||||
TESTS = checkself.sh
|
TESTS = checkself.sh
|
||||||
TESTS += add-remove-dynamic-service.sh
|
TESTS += add-remove-dynamic-service.sh
|
||||||
TESTS += add-remove-dynamic-service-sub-config.sh
|
TESTS += add-remove-dynamic-service-sub-config.sh
|
||||||
|
TESTS += bootstrap-crash.sh
|
||||||
TESTS += cond-start-task.sh
|
TESTS += cond-start-task.sh
|
||||||
TESTS += crashing.sh
|
TESTS += crashing.sh
|
||||||
TESTS += depserv.sh
|
TESTS += depserv.sh
|
||||||
TESTS += devmon.sh
|
TESTS += devmon.sh
|
||||||
TESTS += failing-sysv.sh
|
TESTS += failing-sysv.sh
|
||||||
|
TESTS += svc-env.sh
|
||||||
TESTS += global-envs.sh
|
TESTS += global-envs.sh
|
||||||
TESTS += initctl-status-subset.sh
|
TESTS += initctl-status-subset.sh
|
||||||
TESTS += notify.sh
|
TESTS += notify.sh
|
||||||
@@ -75,7 +87,10 @@ TESTS += rclocal.sh
|
|||||||
TESTS += ready-serv.sh
|
TESTS += ready-serv.sh
|
||||||
TESTS += restart-self.sh
|
TESTS += restart-self.sh
|
||||||
TESTS += runlevel.sh
|
TESTS += runlevel.sh
|
||||||
|
TESTS += sysvparts.sh
|
||||||
TESTS += run-restart-forever.sh
|
TESTS += run-restart-forever.sh
|
||||||
|
TESTS += run-task-tricks.sh
|
||||||
|
TESTS += runparts.sh
|
||||||
TESTS += start-stop-service.sh
|
TESTS += start-stop-service.sh
|
||||||
TESTS += start-stop-service-sub-config.sh
|
TESTS += start-stop-service-sub-config.sh
|
||||||
TESTS += start-kill-service.sh
|
TESTS += start-kill-service.sh
|
||||||
@@ -86,6 +101,7 @@ TESTS += signal-service.sh
|
|||||||
if TESTSERV
|
if TESTSERV
|
||||||
TESTS += testserv.sh
|
TESTS += testserv.sh
|
||||||
endif
|
endif
|
||||||
|
TESTS += unexpected-restart.sh
|
||||||
|
|
||||||
check-recursive: setup-chroot
|
check-recursive: setup-chroot
|
||||||
|
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ TEST_DIR=$(dirname "$0")
|
|||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
|
|
||||||
say "Running test teardown."
|
say "Running test teardown."
|
||||||
run "rm -f $FINIT_RCSD/service.conf"
|
run "rm -f $FINIT_RCSD/service.conf"
|
||||||
}
|
}
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ TEST_DIR=$(dirname "$0")
|
|||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
|
|
||||||
say "Running test teardown."
|
say "Running test teardown."
|
||||||
run "rm -f $FINIT_CONF"
|
run "rm -f $FINIT_CONF"
|
||||||
}
|
}
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
|
|||||||
+6
-10
@@ -4,7 +4,8 @@
|
|||||||
#set -eu
|
#set -eu
|
||||||
|
|
||||||
TEST_DIR=$(dirname "$0")
|
TEST_DIR=$(dirname "$0")
|
||||||
DEBUG=1
|
#DEBUG=1
|
||||||
|
# shellcheck disable=SC2034
|
||||||
BOOTSTRAP="run [S] crasher.sh -- Party crasher"
|
BOOTSTRAP="run [S] crasher.sh -- Party crasher"
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
@@ -12,22 +13,17 @@ BOOTSTRAP="run [S] crasher.sh -- Party crasher"
|
|||||||
|
|
||||||
test_setup()
|
test_setup()
|
||||||
{
|
{
|
||||||
say "Test start $(date)"
|
say "Test start $(date)"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
say "Running test teardown."
|
|
||||||
run "rm -f $TEST_CONF"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
say "Hello SMTP Spoken here"
|
say "Hello SMTP Spoken here"
|
||||||
|
run initctl
|
||||||
|
run initctl status crasher.sh
|
||||||
|
|
||||||
sleep 10
|
sleep 10
|
||||||
say "We are done"
|
say "We are done"
|
||||||
#run initctl
|
|
||||||
#run initctl status crasher.sh
|
|
||||||
|
|
||||||
|
|
||||||
exit 0
|
|
||||||
|
|||||||
+53
-53
@@ -9,77 +9,77 @@ TEST_DIR=$(dirname "$0")
|
|||||||
|
|
||||||
test_setup()
|
test_setup()
|
||||||
{
|
{
|
||||||
say "Test start $(date)"
|
say "Test start $(date)"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
say "Running test teardown."
|
say "Running test teardown."
|
||||||
run "rm -f $TEST_CONF"
|
run "rm -f $TEST_CONF"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_one()
|
test_one()
|
||||||
{
|
{
|
||||||
cond=$1
|
cond=$1
|
||||||
stanza=$2
|
stanza=$2
|
||||||
|
|
||||||
sleep 5
|
sleep 5
|
||||||
say 'Enable finit debug, try to figure out what is going on ...'
|
say 'Enable finit debug, try to figure out what is going on ...'
|
||||||
run "initctl debug"
|
run "initctl debug"
|
||||||
|
|
||||||
say "Add stanza '$stanza' to $TEST_CONF ..."
|
say "Add stanza '$stanza' to $TEST_CONF ..."
|
||||||
run "echo '$stanza' > $TEST_CONF"
|
run "echo '$stanza' > $TEST_CONF"
|
||||||
|
|
||||||
run "ls -l /run/ /run/finit/"
|
run "ls -l /run/ /run/finit/"
|
||||||
say 'Reload Finit'
|
say 'Reload Finit'
|
||||||
run "initctl ls"
|
run "initctl ls"
|
||||||
run "initctl reload"
|
run "initctl reload"
|
||||||
run "initctl status"
|
run "initctl status"
|
||||||
run "ps"
|
run "ps"
|
||||||
|
|
||||||
date
|
date
|
||||||
sleep 2
|
sleep 2
|
||||||
date
|
date
|
||||||
run "ls -l /run/ /run/finit/"
|
run "ls -l /run/ /run/finit/"
|
||||||
say 'Asserting condition'
|
say 'Asserting condition'
|
||||||
run "initctl cond set $cond"
|
run "initctl cond set $cond"
|
||||||
|
|
||||||
date
|
date
|
||||||
sleep 2
|
sleep 2
|
||||||
date
|
date
|
||||||
run "ls -l /run/ /run/finit/"
|
run "ls -l /run/ /run/finit/"
|
||||||
run "initctl status"
|
run "initctl status"
|
||||||
run "ps"
|
run "ps"
|
||||||
run "initctl status task.sh"
|
run "initctl status task.sh"
|
||||||
|
|
||||||
sleep 1
|
sleep 1
|
||||||
run "echo Hej; cat /run/task.state"
|
run "echo Hej; cat /run/task.state"
|
||||||
|
|
||||||
assert_file_contains /run/task.state 1
|
assert_file_contains /run/task.state 1
|
||||||
|
|
||||||
say 'Reload Finit'
|
say 'Reload Finit'
|
||||||
run "initctl reload"
|
run "initctl reload"
|
||||||
sleep 1
|
sleep 1
|
||||||
say 'Ensure task has not run again ...'
|
say 'Ensure task has not run again ...'
|
||||||
assert_file_contains /run/task.state 1
|
assert_file_contains /run/task.state 1
|
||||||
|
|
||||||
say 'Switch to another runlevel ...'
|
say 'Switch to another runlevel ...'
|
||||||
run "initctl runlevel 3"
|
run "initctl runlevel 3"
|
||||||
sleep 1
|
sleep 1
|
||||||
say 'Ensure task has run again ...'
|
say 'Ensure task has run again ...'
|
||||||
assert_file_contains /run/task.state 2
|
assert_file_contains /run/task.state 2
|
||||||
|
|
||||||
say 'Touch task.sh .conf file and reload Finit ...'
|
say 'Touch task.sh .conf file and reload Finit ...'
|
||||||
run "touch $TEST_CONF"
|
run "touch $TEST_CONF"
|
||||||
run "initctl reload"
|
run "initctl reload"
|
||||||
sleep 1
|
sleep 1
|
||||||
# run "initctl status task.sh"
|
# run "initctl status task.sh"
|
||||||
assert_file_contains /run/task.state 3
|
assert_file_contains /run/task.state 3
|
||||||
|
|
||||||
say "Done, drop stanza from $TEST_CONF ..."
|
say "Done, drop stanza from $TEST_CONF ..."
|
||||||
run "rm $TEST_CONF"
|
run "rm $TEST_CONF"
|
||||||
run "initctl reload"
|
run "initctl reload"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+33
-33
@@ -7,57 +7,57 @@ TEST_DIR=$(dirname "$0")
|
|||||||
|
|
||||||
test_setup()
|
test_setup()
|
||||||
{
|
{
|
||||||
say "Test start $(date)"
|
say "Test start $(date)"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
|
|
||||||
say "Running test teardown."
|
say "Running test teardown."
|
||||||
run "rm -f $FINIT_CONF" "/tmp/post"
|
run "rm -f $FINIT_CONF" "/tmp/post"
|
||||||
}
|
}
|
||||||
|
|
||||||
crashit()
|
crashit()
|
||||||
{
|
{
|
||||||
nm=$1
|
nm=$1
|
||||||
|
|
||||||
say 'Simulate service crash (kill -9 ..)'
|
say 'Simulate service crash (kill -9 ..)'
|
||||||
i=0
|
i=0
|
||||||
laps=100
|
laps=100
|
||||||
while [ $i -lt $laps ]; do
|
while [ $i -lt $laps ]; do
|
||||||
i=$((i + 1))
|
i=$((i + 1))
|
||||||
say "Lap $i/$laps, killing service $nm ..." # we have this, no sleep needed
|
say "Lap $i/$laps, killing service $nm ..." # we have this, no sleep needed
|
||||||
if ! run "slay $nm"; then
|
if ! run "slay $nm"; then
|
||||||
break;
|
break;
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
test_one()
|
test_one()
|
||||||
{
|
{
|
||||||
type=$1
|
type=$1
|
||||||
shift
|
shift
|
||||||
nm=$1
|
nm=$1
|
||||||
shift
|
shift
|
||||||
args=$*
|
args=$*
|
||||||
|
|
||||||
say "Add service stanza in $FINIT_CONF"
|
say "Add service stanza in $FINIT_CONF"
|
||||||
run "echo service log:stderr oncrash:script post:/bin/post.sh $nm $args > $FINIT_CONF"
|
run "echo service log:stderr oncrash:script post:/bin/post.sh $nm $args > $FINIT_CONF"
|
||||||
|
|
||||||
say 'Reload Finit'
|
say 'Reload Finit'
|
||||||
run "initctl reload"
|
run "initctl reload"
|
||||||
|
|
||||||
if [ "$type" = "sig" ]; then
|
if [ "$type" = "sig" ]; then
|
||||||
retry "assert_num_children 1 $nm"
|
retry "assert_num_children 1 $nm"
|
||||||
run "initctl status $nm"
|
run "initctl status $nm"
|
||||||
crashit "$nm"
|
crashit "$nm"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
retry "assert_status $nm crashed" 500
|
retry "assert_status $nm crashed" 500
|
||||||
run "cat /tmp/post"
|
run "cat /tmp/post"
|
||||||
assert_file_contains "/tmp/post" "POST"
|
assert_file_contains "/tmp/post" "POST"
|
||||||
run "rm -f /tmp/post"
|
run "rm -f /tmp/post"
|
||||||
}
|
}
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
|
|||||||
+30
-30
@@ -16,15 +16,15 @@ TEST_DIR=$(dirname "$0")
|
|||||||
|
|
||||||
test_setup()
|
test_setup()
|
||||||
{
|
{
|
||||||
say "Test start $(date)"
|
say "Test start $(date)"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
say "Running test teardown."
|
say "Running test teardown."
|
||||||
|
|
||||||
run "rm -f $FINIT_CONF" "/tmp/post"
|
run "rm -f $FINIT_CONF" "/tmp/post"
|
||||||
}
|
}
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
@@ -35,36 +35,36 @@ test_teardown()
|
|||||||
|
|
||||||
test_one()
|
test_one()
|
||||||
{
|
{
|
||||||
cond=$1
|
cond=$1
|
||||||
say "Verifying foo -> <$cond> bar ..."
|
say "Verifying foo -> <$cond> bar ..."
|
||||||
run "echo service log:stderr name:foo serv -np -i foo -f /tmp/arrakis > $FINIT_CONF"
|
run "echo service log:stderr name:foo serv -np -i foo -f /tmp/arrakis > $FINIT_CONF"
|
||||||
run "echo service log:stderr name:bar \<!$cond\> serv -np -i bar -F /tmp/arrakis >> $FINIT_CONF"
|
run "echo service log:stderr name:bar \<!$cond\> serv -np -i bar -F /tmp/arrakis >> $FINIT_CONF"
|
||||||
run "cat $FINIT_CONF"
|
run "cat $FINIT_CONF"
|
||||||
|
|
||||||
say 'Reload Finit'
|
say 'Reload Finit'
|
||||||
run "initctl reload"
|
run "initctl reload"
|
||||||
|
|
||||||
run "initctl status"
|
run "initctl status"
|
||||||
assert_status "foo" "running"
|
assert_status "foo" "running"
|
||||||
assert_cond "$cond"
|
assert_cond "$cond"
|
||||||
assert_status "bar" "running"
|
assert_status "bar" "running"
|
||||||
|
|
||||||
say "Verify bar is restarted when foo is ..."
|
say "Verify bar is restarted when foo is ..."
|
||||||
pid=$(texec initctl |grep bar | awk '{print $1;}')
|
pid=$(texec initctl |grep bar | awk '{print $1;}')
|
||||||
run "initctl restart foo"
|
run "initctl restart foo"
|
||||||
run "initctl status"
|
run "initctl status"
|
||||||
assert "bar is restarted" "$(texec initctl |grep bar | awk '{print $1;}')" != "$pid"
|
assert "bar is restarted" "$(texec initctl |grep bar | awk '{print $1;}')" != "$pid"
|
||||||
|
|
||||||
# Wait for spice to be stolen by the Harkonnen
|
# Wait for spice to be stolen by the Harkonnen
|
||||||
sleep 3
|
sleep 3
|
||||||
# bar should now have detected the loss of spice and be in restart
|
# bar should now have detected the loss of spice and be in restart
|
||||||
run "initctl status"
|
run "initctl status"
|
||||||
assert_status "bar" "restart"
|
assert_status "bar" "restart"
|
||||||
# verify bar is stopped->waiting and no longer in restart after stopping foo
|
# verify bar is stopped->waiting and no longer in restart after stopping foo
|
||||||
run "initctl stop foo"
|
run "initctl stop foo"
|
||||||
run "initctl status"
|
run "initctl status"
|
||||||
run "initctl status bar"
|
run "initctl status bar"
|
||||||
assert_status "bar" "waiting"
|
assert_status "bar" "waiting"
|
||||||
}
|
}
|
||||||
|
|
||||||
sep
|
sep
|
||||||
|
|||||||
+22
-22
@@ -9,52 +9,52 @@ TEST_DIR=$(dirname "$0")
|
|||||||
|
|
||||||
test_setup()
|
test_setup()
|
||||||
{
|
{
|
||||||
say "Test start $(date)"
|
say "Test start $(date)"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
say "Running test teardown."
|
say "Running test teardown."
|
||||||
|
|
||||||
run "rm -f $FINIT_CONF /tmp/post"
|
run "rm -f $FINIT_CONF /tmp/post"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Cannot run mknod as non-root even in a chroot
|
# Cannot run mknod as non-root even in a chroot
|
||||||
# touch is close enough for our needs
|
# touch is close enough for our needs
|
||||||
mkdev()
|
mkdev()
|
||||||
{
|
{
|
||||||
dir=$(dirname "$1")
|
dir=$(dirname "$1")
|
||||||
run "mkdir -p $dir"
|
run "mkdir -p $dir"
|
||||||
run "touch $1"
|
run "touch $1"
|
||||||
}
|
}
|
||||||
|
|
||||||
rmdev()
|
rmdev()
|
||||||
{
|
{
|
||||||
run "rm $1"
|
run "rm $1"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_one()
|
test_one()
|
||||||
{
|
{
|
||||||
cond="$1"
|
cond="$1"
|
||||||
node="/$cond"
|
node="/$cond"
|
||||||
|
|
||||||
say "Checking cond $cond and device $node ..."
|
say "Checking cond $cond and device $node ..."
|
||||||
run "echo service log:null \<$cond\> serv -np >> $FINIT_CONF"
|
run "echo service log:null \<$cond\> serv -np >> $FINIT_CONF"
|
||||||
run "cat $FINIT_CONF"
|
run "cat $FINIT_CONF"
|
||||||
run "initctl reload"
|
run "initctl reload"
|
||||||
|
|
||||||
assert_status "serv" "waiting"
|
assert_status "serv" "waiting"
|
||||||
|
|
||||||
mkdev "$node"
|
mkdev "$node"
|
||||||
assert_status "serv" "running"
|
assert_status "serv" "running"
|
||||||
|
|
||||||
rmdev "$node"
|
rmdev "$node"
|
||||||
assert_status "serv" "waiting"
|
assert_status "serv" "waiting"
|
||||||
|
|
||||||
say "Cleaning up ..."
|
say "Cleaning up ..."
|
||||||
run "rm $FINIT_CONF"
|
run "rm $FINIT_CONF"
|
||||||
run "initctl reload"
|
run "initctl reload"
|
||||||
}
|
}
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
|
|||||||
@@ -8,16 +8,16 @@ TEST_DIR=$(dirname "$0")
|
|||||||
|
|
||||||
test_setup()
|
test_setup()
|
||||||
{
|
{
|
||||||
say "Test start $(date)"
|
say "Test start $(date)"
|
||||||
run "mkdir -p /etc/default"
|
run "mkdir -p /etc/default"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
|
|
||||||
say "Running test teardown."
|
say "Running test teardown."
|
||||||
run "rm -f $FINIT_CONF"
|
run "rm -f $FINIT_CONF"
|
||||||
}
|
}
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
|
|||||||
+4
-4
@@ -5,15 +5,15 @@ TEST_DIR=$(dirname "$0")
|
|||||||
|
|
||||||
test_setup()
|
test_setup()
|
||||||
{
|
{
|
||||||
say "Test start $(date)"
|
say "Test start $(date)"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
|
|
||||||
say "Running test teardown."
|
say "Running test teardown."
|
||||||
run "rm -f $FINIT_CONF"
|
run "rm -f $FINIT_CONF"
|
||||||
}
|
}
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
|
|||||||
@@ -9,28 +9,28 @@ TEST_DIR=$(dirname "$0")
|
|||||||
|
|
||||||
test_setup()
|
test_setup()
|
||||||
{
|
{
|
||||||
say "Test start $(date)"
|
say "Test start $(date)"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
|
|
||||||
say "Running test teardown."
|
say "Running test teardown."
|
||||||
run "rm -f $FINIT_CONF"
|
run "rm -f $FINIT_CONF"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_init()
|
test_init()
|
||||||
{
|
{
|
||||||
run "echo '# Three foo and one bar enter Finit' > $FINIT_CONF"
|
run "echo '# Three foo and one bar enter Finit' > $FINIT_CONF"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_add_one()
|
test_add_one()
|
||||||
{
|
{
|
||||||
service=$1
|
service=$1
|
||||||
|
|
||||||
say "Add service stanza '$service' to $FINIT_CONF ..."
|
say "Add service stanza '$service' to $FINIT_CONF ..."
|
||||||
run "echo '$service' >> $FINIT_CONF"
|
run "echo '$service' >> $FINIT_CONF"
|
||||||
}
|
}
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
|
|||||||
+7
-7
@@ -4,10 +4,10 @@ set -eu
|
|||||||
|
|
||||||
cmd=""
|
cmd=""
|
||||||
if [ "$#" -lt 1 ]; then
|
if [ "$#" -lt 1 ]; then
|
||||||
cmd="/bin/sh"
|
cmd="/bin/sh"
|
||||||
else
|
else
|
||||||
cmd=$1
|
cmd=$1
|
||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
|
|
||||||
TEST_DIR=$(dirname "$0")/..
|
TEST_DIR=$(dirname "$0")/..
|
||||||
@@ -15,11 +15,11 @@ SYSROOT="${SYSROOT:-$(pwd)/${TEST_DIR}/sysroot}"
|
|||||||
PID_FILE="$SYSROOT/running_test.pid"
|
PID_FILE="$SYSROOT/running_test.pid"
|
||||||
|
|
||||||
if [ -f "$PID_FILE" ] ; then
|
if [ -f "$PID_FILE" ] ; then
|
||||||
target=$(cat "$PID_FILE")
|
target=$(cat "$PID_FILE")
|
||||||
target=$(pgrep -P "$target")
|
target=$(pgrep -P "$target")
|
||||||
else
|
else
|
||||||
echo "No test running!"
|
echo "No test running!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# shellcheck disable=SC1091
|
# shellcheck disable=SC1091
|
||||||
|
|||||||
+12
-12
@@ -24,9 +24,9 @@
|
|||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
if [ "$#" -lt 2 ]; then
|
if [ "$#" -lt 2 ]; then
|
||||||
echo "Usage:"
|
echo "Usage:"
|
||||||
echo " $0 [target-pid] [command [arguments]]"
|
echo " $0 [target-pid] [command [arguments]]"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
target="$1"
|
target="$1"
|
||||||
shift
|
shift
|
||||||
@@ -46,12 +46,12 @@ PATH="$TESTENV_PATH"
|
|||||||
export PATH
|
export PATH
|
||||||
|
|
||||||
"$nsenter" \
|
"$nsenter" \
|
||||||
--preserve-credentials \
|
--preserve-credentials \
|
||||||
--user \
|
--user \
|
||||||
--mount \
|
--mount \
|
||||||
--uts \
|
--uts \
|
||||||
--ipc \
|
--ipc \
|
||||||
--net \
|
--net \
|
||||||
--pid \
|
--pid \
|
||||||
-w -t "$target" \
|
-w -t "$target" \
|
||||||
"$chroot" "$SYSROOT" "$@"
|
"$chroot" "$SYSROOT" "$@"
|
||||||
|
|||||||
+56
-21
@@ -52,6 +52,11 @@ assert_new_pid()
|
|||||||
assert "Finit has registered new PID" "$(texec initctl |grep $1 | awk '{print $1;}')" -eq "$(texec cat $2)"
|
assert "Finit has registered new PID" "$(texec initctl |grep $1 | awk '{print $1;}')" -eq "$(texec cat $2)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert_pidiff()
|
||||||
|
{
|
||||||
|
assert "PID has changed (old PID $2)" "$(texec initctl |awk -v svc="$1" '$0 ~ svc {print $1}')" -ne "$2"
|
||||||
|
}
|
||||||
|
|
||||||
assert_restarts()
|
assert_restarts()
|
||||||
{
|
{
|
||||||
assert "Finit has registered restarts" "$(texec initctl status "$2" | awk '/Restarts/{print $3;}')" -ge "$1"
|
assert "Finit has registered restarts" "$(texec initctl status "$2" | awk '/Restarts/{print $3;}')" -ge "$1"
|
||||||
@@ -59,7 +64,7 @@ assert_restarts()
|
|||||||
|
|
||||||
assert_restart_cnt()
|
assert_restart_cnt()
|
||||||
{
|
{
|
||||||
assert "Finit restart cnt $1" "$(texec initctl status "$2" | awk '/Restarts/{print $4;}')" = "($1)"
|
assert "Finit restart total $1 cnt $2" "$(texec initctl status "$3" | awk '/Restarts/{print $3 $4;}')" = "$1($2)"
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_norestart()
|
assert_norestart()
|
||||||
@@ -138,7 +143,15 @@ log()
|
|||||||
|
|
||||||
sep()
|
sep()
|
||||||
{
|
{
|
||||||
printf "\e[2m――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――\e[0m\n"
|
heading=${1:-}
|
||||||
|
if [ -n "$heading" ]; then
|
||||||
|
num=$((72 - ${#heading} - 1))
|
||||||
|
printf "\e[1m%s " "$heading"
|
||||||
|
printf -- "―%.0s" $(seq 1 $num)
|
||||||
|
printf "\e[0m\n"
|
||||||
|
else
|
||||||
|
printf "\e[1m――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――\e[0m\n"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
say()
|
say()
|
||||||
@@ -226,7 +239,8 @@ wdstart()
|
|||||||
|
|
||||||
wdkill()
|
wdkill()
|
||||||
{
|
{
|
||||||
kill -KILL $wdpid
|
say "Stopping test watchdog, pid $wdpid"
|
||||||
|
kill -KILL $wdpid
|
||||||
}
|
}
|
||||||
|
|
||||||
teardown()
|
teardown()
|
||||||
@@ -247,11 +261,15 @@ teardown()
|
|||||||
log "$fg_red" 'TEST FAIL' ''
|
log "$fg_red" 'TEST FAIL' ''
|
||||||
fi
|
fi
|
||||||
|
|
||||||
say "Telling Finit to shut down (set -$-) ..."
|
|
||||||
set +e
|
set +e
|
||||||
if [ -n "${finit_pid+x}" ]; then
|
say "Telling Finit to shut down (set -$-) ..."
|
||||||
texec kill -SIGUSR2 1
|
while [ -n "${finit_pid+x}" ]; do
|
||||||
fi
|
if ! kill -USR2 "${finit_pid}" 2>/dev/null; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
say "Retrying shutdown ..."
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
|
||||||
say "Waiting for Finit to shut down ..."
|
say "Waiting for Finit to shut down ..."
|
||||||
wait
|
wait
|
||||||
@@ -259,6 +277,7 @@ teardown()
|
|||||||
say "Final cleanup ..."
|
say "Final cleanup ..."
|
||||||
rm -f "$SYSROOT"/running_test.pid
|
rm -f "$SYSROOT"/running_test.pid
|
||||||
rm -f "$SYSROOT$FINIT_CONF"
|
rm -f "$SYSROOT$FINIT_CONF"
|
||||||
|
rm -f "$SYSROOT/etc/rc.local"
|
||||||
|
|
||||||
say "EXIT: $test_status"
|
say "EXIT: $test_status"
|
||||||
exit $test_status
|
exit $test_status
|
||||||
@@ -287,14 +306,30 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
set +u
|
set +u
|
||||||
|
rm -f "$SYSROOT$FINIT_CONF"
|
||||||
|
touch "$SYSROOT$FINIT_CONF"
|
||||||
|
|
||||||
if [ -n "$BOOTSTRAP" ]; then
|
if [ -n "$BOOTSTRAP" ]; then
|
||||||
say "Setting up bootstrap tasks ..."
|
say "Setting up bootstrap tasks ..."
|
||||||
echo "$BOOTSTRAP" > "$SYSROOT$FINIT_CONF"
|
echo "$BOOTSTRAP" >> "$SYSROOT$FINIT_CONF"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -n "$RUNPARTS" ]; then
|
||||||
|
say "Setting up runparts task ..."
|
||||||
|
echo "runparts /etc/rc.d" >> "$SYSROOT$FINIT_CONF"
|
||||||
|
mkdir "$SYSROOT/etc/rc.d"
|
||||||
|
echo "$RUNPARTS" > "$SYSROOT/etc/rc.d/start.sh"
|
||||||
|
chmod +x "$SYSROOT/etc/rc.d/start.sh"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -n "$RCLOCAL" ]; then
|
if [ -n "$RCLOCAL" ]; then
|
||||||
say "Setting up /etc/rc.local ..."
|
while [ -f "$SYSROOT/etc/rc.local" ]; do
|
||||||
echo "$RCLOCAL" > "$SYSROOT/etc/rc.local"
|
echo "$SYSROOT/etc/rc.local busy ... waiting ..."
|
||||||
chmod +x "$SYSROOT/etc/rc.local"
|
sleep 1
|
||||||
|
done
|
||||||
|
say "Setting up /etc/rc.local ..."
|
||||||
|
echo "$RCLOCAL" > "$SYSROOT/etc/rc.local"
|
||||||
|
chmod +x "$SYSROOT/etc/rc.local"
|
||||||
fi
|
fi
|
||||||
set -u
|
set -u
|
||||||
|
|
||||||
@@ -307,7 +342,7 @@ echo "$finit_ppid" > "$SYSROOT"/running_test.pid
|
|||||||
log "$color_reset" 'Setup of test environment done, waiting for Finit ...' ''
|
log "$color_reset" 'Setup of test environment done, waiting for Finit ...' ''
|
||||||
|
|
||||||
finit_pid=$(retry "pgrep -P $finit_ppid")
|
finit_pid=$(retry "pgrep -P $finit_ppid")
|
||||||
echo "Finit running as $finit_pid"
|
echo "Finit running as PID $finit_pid"
|
||||||
#tty=/dev/$(texec cat /sys/class/tty/console/active)
|
#tty=/dev/$(texec cat /sys/class/tty/console/active)
|
||||||
#texec cat "$tty" &
|
#texec cat "$tty" &
|
||||||
|
|
||||||
@@ -315,17 +350,17 @@ echo "Finit running as $finit_pid"
|
|||||||
i=0
|
i=0
|
||||||
set +u
|
set +u
|
||||||
while [ -z "$BOOTSTRAP" ] && [ $i -lt 10 ]; do
|
while [ -z "$BOOTSTRAP" ] && [ $i -lt 10 ]; do
|
||||||
lvl=$(texec sh -c "initctl runlevel | awk '{print \$2;}'")
|
lvl=$(texec sh -c "initctl runlevel | awk '{print \$2;}'")
|
||||||
if [ "$lvl" = "$FINIT_RUNLEVEL" ]; then
|
if [ "$lvl" = "$FINIT_RUNLEVEL" ]; then
|
||||||
say "Reached runlevel $FINIT_RUNLEVEL, releasing test."
|
say "Reached runlevel $FINIT_RUNLEVEL, releasing test."
|
||||||
break;
|
break;
|
||||||
fi
|
fi
|
||||||
i=$((i + 1))
|
i=$((i + 1))
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
set -u
|
set -u
|
||||||
|
|
||||||
if type test_setup > /dev/null 2>&1 ; then
|
if type test_setup > /dev/null 2>&1 ; then
|
||||||
test_setup
|
test_setup
|
||||||
fi
|
fi
|
||||||
wdstart $TEST_TIMEOUT
|
wdstart $TEST_TIMEOUT
|
||||||
|
|||||||
+18
-18
@@ -8,16 +8,16 @@ TEST_DIR=$(dirname "$0")
|
|||||||
|
|
||||||
test_setup()
|
test_setup()
|
||||||
{
|
{
|
||||||
say "Test start $(date)"
|
say "Test start $(date)"
|
||||||
run "mkdir -p /etc/default"
|
run "mkdir -p /etc/default"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
say "Running test teardown."
|
say "Running test teardown."
|
||||||
|
|
||||||
run "rm -f $FINIT_CONF"
|
run "rm -f $FINIT_CONF"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_one()
|
test_one()
|
||||||
@@ -37,11 +37,11 @@ test_one()
|
|||||||
run "initctl reload"
|
run "initctl reload"
|
||||||
|
|
||||||
sleep 1
|
sleep 1
|
||||||
# run "initctl status serv"
|
# run "initctl status serv"
|
||||||
assert_status "serv" "running"
|
assert_status "serv" "running"
|
||||||
|
|
||||||
sleep 2
|
sleep 2
|
||||||
# run "initctl cond dump"
|
# run "initctl cond dump"
|
||||||
assert_cond "service/serv/ready"
|
assert_cond "service/serv/ready"
|
||||||
|
|
||||||
say "Verify 'ready' is set after SIGHUP ..."
|
say "Verify 'ready' is set after SIGHUP ..."
|
||||||
@@ -52,7 +52,7 @@ test_one()
|
|||||||
|
|
||||||
# Issue #343
|
# Issue #343
|
||||||
say "Verify 'ready' is reasserted if service crashes and is restarted ..."
|
say "Verify 'ready' is reasserted if service crashes and is restarted ..."
|
||||||
# run "initctl status serv"
|
# run "initctl status serv"
|
||||||
run "initctl signal serv 9"
|
run "initctl signal serv 9"
|
||||||
retry 'assert_status "serv" "running"' 2 1
|
retry 'assert_status "serv" "running"' 2 1
|
||||||
retry 'assert_cond "service/serv/ready"' 3 1
|
retry 'assert_cond "service/serv/ready"' 3 1
|
||||||
@@ -67,7 +67,7 @@ test_one()
|
|||||||
say "Verify 'ready' is reasserted on 'initctl reload' ..."
|
say "Verify 'ready' is reasserted on 'initctl reload' ..."
|
||||||
run "initctl reload"
|
run "initctl reload"
|
||||||
sleep 1
|
sleep 1
|
||||||
# run "initctl; initctl cond dump"
|
# run "initctl; initctl cond dump"
|
||||||
assert_status "serv" "running"
|
assert_status "serv" "running"
|
||||||
assert_cond "service/serv/ready"
|
assert_cond "service/serv/ready"
|
||||||
|
|
||||||
@@ -75,12 +75,12 @@ test_one()
|
|||||||
# 'started' when they created their PID file. The serv test daemon
|
# 'started' when they created their PID file. The serv test daemon
|
||||||
# waits 3 sec between pidfile and notify to trigger this bug.
|
# waits 3 sec between pidfile and notify to trigger this bug.
|
||||||
if [ "$type" != "native" ]; then
|
if [ "$type" != "native" ]; then
|
||||||
say "Verify 'ready' is *not* asserted immediately on restart + reload"
|
say "Verify 'ready' is *not* asserted immediately on restart + reload"
|
||||||
run "initctl restart serv"
|
run "initctl restart serv"
|
||||||
run "initctl reload"
|
run "initctl reload"
|
||||||
sleep 1
|
sleep 1
|
||||||
assert_nocond "service/serv/ready"
|
assert_nocond "service/serv/ready"
|
||||||
retry 'assert_cond "service/serv/ready"' 5 0.5
|
retry 'assert_cond "service/serv/ready"' 5 0.5
|
||||||
fi
|
fi
|
||||||
|
|
||||||
say "Verify 'ready' is deasserted on stop ..."
|
say "Verify 'ready' is deasserted on stop ..."
|
||||||
@@ -93,9 +93,9 @@ test_one()
|
|||||||
run "rm -f $FINIT_CONF"
|
run "rm -f $FINIT_CONF"
|
||||||
run "initctl reload"
|
run "initctl reload"
|
||||||
|
|
||||||
# sleep 2
|
# sleep 2
|
||||||
# num=$(run "find /proc/1/fd |wc -l")
|
# num=$(run "find /proc/1/fd |wc -l")
|
||||||
# say "finit: number of open file descriptors after test: $num"
|
# say "finit: number of open file descriptors after test: $num"
|
||||||
}
|
}
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
|
|||||||
+14
-14
@@ -7,32 +7,32 @@ TEST_DIR=$(dirname "$0")
|
|||||||
|
|
||||||
test_setup()
|
test_setup()
|
||||||
{
|
{
|
||||||
say "Test start $(date)"
|
say "Test start $(date)"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
say "Running test teardown."
|
say "Running test teardown."
|
||||||
|
|
||||||
run "rm -f $FINIT_CONF" "/tmp/post"
|
run "rm -f $FINIT_CONF" "/tmp/post"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_one()
|
test_one()
|
||||||
{
|
{
|
||||||
pidfn=$1
|
pidfn=$1
|
||||||
service=$2
|
service=$2
|
||||||
|
|
||||||
sep
|
sep
|
||||||
say "Add service stanza '$service' to $FINIT_CONF ..."
|
say "Add service stanza '$service' to $FINIT_CONF ..."
|
||||||
run "echo '$service' > $FINIT_CONF"
|
run "echo '$service' > $FINIT_CONF"
|
||||||
run "initctl reload"
|
run "initctl reload"
|
||||||
|
|
||||||
assert_is_pidfile "serv" "$pidfn"
|
assert_is_pidfile "serv" "$pidfn"
|
||||||
|
|
||||||
say "Done, drop service from $FINIT_CONF ..."
|
say "Done, drop service from $FINIT_CONF ..."
|
||||||
run "rm $FINIT_CONF"
|
run "rm $FINIT_CONF"
|
||||||
run "initctl reload"
|
run "initctl reload"
|
||||||
}
|
}
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
|
|||||||
+28
-28
@@ -5,49 +5,49 @@ TEST_DIR=$(dirname "$0")
|
|||||||
|
|
||||||
test_setup()
|
test_setup()
|
||||||
{
|
{
|
||||||
say "Test start $(date)"
|
say "Test start $(date)"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
|
|
||||||
say "Running test teardown."
|
say "Running test teardown."
|
||||||
run "rm -f $FINIT_CONF"
|
run "rm -f $FINIT_CONF"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_one()
|
test_one()
|
||||||
{
|
{
|
||||||
pre=$1
|
pre=$1
|
||||||
precont=$2
|
precont=$2
|
||||||
service=$3
|
service=$3
|
||||||
post=$4
|
post=$4
|
||||||
postcont=$5
|
postcont=$5
|
||||||
|
|
||||||
say "Add service stanza '$service' to $FINIT_CONF ..."
|
say "Add service stanza '$service' to $FINIT_CONF ..."
|
||||||
run "echo '$service' > $FINIT_CONF"
|
run "echo '$service' > $FINIT_CONF"
|
||||||
|
|
||||||
say 'Reload Finit'
|
say 'Reload Finit'
|
||||||
run "initctl reload"
|
run "initctl reload"
|
||||||
|
|
||||||
retry 'assert_num_children 1 serv'
|
retry 'assert_num_children 1 serv'
|
||||||
if [ -n "$pre" ]; then
|
if [ -n "$pre" ]; then
|
||||||
assert_file_contains "$pre" "$precont"
|
assert_file_contains "$pre" "$precont"
|
||||||
run "rm -f $pre"
|
run "rm -f $pre"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
say 'Stop the service'
|
say 'Stop the service'
|
||||||
run "initctl stop serv"
|
run "initctl stop serv"
|
||||||
|
|
||||||
retry 'assert_num_children 0 serv'
|
retry 'assert_num_children 0 serv'
|
||||||
if [ -n "$post" ]; then
|
if [ -n "$post" ]; then
|
||||||
assert_file_contains "$post" "$postcont"
|
assert_file_contains "$post" "$postcont"
|
||||||
run "rm -f $post"
|
run "rm -f $post"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
say "Done, drop service from $FINIT_CONF ..."
|
say "Done, drop service from $FINIT_CONF ..."
|
||||||
run "rm $FINIT_CONF"
|
run "rm $FINIT_CONF"
|
||||||
run "initctl reload"
|
run "initctl reload"
|
||||||
}
|
}
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
|
|||||||
+2
-3
@@ -12,13 +12,12 @@ RCLOCAL="echo 'KILROY WAS HERE' > /tmp/rclocal"
|
|||||||
|
|
||||||
test_setup()
|
test_setup()
|
||||||
{
|
{
|
||||||
say "Test start $(date)"
|
say "Test start $(date)"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
run "rm -f $SYSROOT/etc/rc.local"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sleep 1
|
sleep 1
|
||||||
|
|||||||
+19
-19
@@ -6,39 +6,39 @@ TEST_DIR=$(dirname "$0")
|
|||||||
|
|
||||||
test_setup()
|
test_setup()
|
||||||
{
|
{
|
||||||
say "Test start $(date)"
|
say "Test start $(date)"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
|
|
||||||
say "Running test teardown."
|
say "Running test teardown."
|
||||||
run "rm -f $FINIT_CONF"
|
run "rm -f $FINIT_CONF"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_one()
|
test_one()
|
||||||
{
|
{
|
||||||
service=$1
|
service=$1
|
||||||
file=/tmp/ready
|
file=/tmp/ready
|
||||||
|
|
||||||
say "Add service stanza '$service' to $FINIT_CONF ..."
|
say "Add service stanza '$service' to $FINIT_CONF ..."
|
||||||
run "echo '$service' > $FINIT_CONF"
|
run "echo '$service' > $FINIT_CONF"
|
||||||
|
|
||||||
say 'Reload Finit'
|
say 'Reload Finit'
|
||||||
run "initctl reload"
|
run "initctl reload"
|
||||||
|
|
||||||
retry 'assert_num_children 1 serv'
|
retry 'assert_num_children 1 serv'
|
||||||
assert_file_contains "$file" "READY"
|
assert_file_contains "$file" "READY"
|
||||||
run "rm -f $file"
|
run "rm -f $file"
|
||||||
|
|
||||||
say 'Stop the service'
|
say 'Stop the service'
|
||||||
run "initctl stop serv"
|
run "initctl stop serv"
|
||||||
retry 'assert_num_children 0 serv'
|
retry 'assert_num_children 0 serv'
|
||||||
|
|
||||||
say "Done, drop service from $FINIT_CONF ..."
|
say "Done, drop service from $FINIT_CONF ..."
|
||||||
run "rm $FINIT_CONF"
|
run "rm $FINIT_CONF"
|
||||||
run "initctl reload"
|
run "initctl reload"
|
||||||
}
|
}
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
|
|||||||
@@ -6,21 +6,21 @@ TEST_DIR=$(dirname "$0")
|
|||||||
|
|
||||||
test_setup()
|
test_setup()
|
||||||
{
|
{
|
||||||
say "Test start $(date)"
|
say "Test start $(date)"
|
||||||
run "mkdir -p /etc/default"
|
run "mkdir -p /etc/default"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
|
|
||||||
say "Running test teardown."
|
say "Running test teardown."
|
||||||
run "rm -f $FINIT_CONF"
|
run "rm -f $FINIT_CONF"
|
||||||
}
|
}
|
||||||
|
|
||||||
check_restarts()
|
check_restarts()
|
||||||
{
|
{
|
||||||
assert "serv restarts" "$(texec cat "$1" | awk '{print $1;}')" -ge "$2"
|
assert "serv restarts" "$(texec cat "$1" | awk '{print $1;}')" -ge "$2"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,25 +9,19 @@ TEST_DIR=$(dirname "$0")
|
|||||||
|
|
||||||
test_setup()
|
test_setup()
|
||||||
{
|
{
|
||||||
say "Test start $(date)"
|
say "Test start $(date)"
|
||||||
run "mkdir -p /etc/default"
|
run "mkdir -p /etc/default"
|
||||||
export TEST_TIMEOUT=5
|
export TEST_TIMEOUT=5
|
||||||
}
|
}
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
|
|
||||||
say "Running test teardown."
|
say "Running test teardown."
|
||||||
run "rm -f $FINIT_CONF"
|
run "rm -f $FINIT_CONF"
|
||||||
}
|
}
|
||||||
|
|
||||||
check_restarts()
|
|
||||||
{
|
|
||||||
assert "serv restarts" "$(texec cat "$1" | awk '{print $1;}')" -ge "$2"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
. "$TEST_DIR/lib/setup.sh"
|
. "$TEST_DIR/lib/setup.sh"
|
||||||
|
|
||||||
@@ -43,7 +37,7 @@ test_one()
|
|||||||
run "initctl reload"
|
run "initctl reload"
|
||||||
# run "initctl status fail.sh"
|
# run "initctl status fail.sh"
|
||||||
|
|
||||||
assert_restart_cnt "$num/10" fail.sh
|
assert_restart_cnt "$num" "0/10" fail.sh
|
||||||
}
|
}
|
||||||
|
|
||||||
sep
|
sep
|
||||||
|
|||||||
Executable
+59
@@ -0,0 +1,59 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Verifies that a run task can call initctl at bootstrap and runlevel 2,
|
||||||
|
# without blocking, performing serveral tasks:
|
||||||
|
#
|
||||||
|
# 1. Query running services
|
||||||
|
# 2. Stop/Start a running service
|
||||||
|
# 3. Restart a service
|
||||||
|
#
|
||||||
|
|
||||||
|
TEST_DIR=$(dirname "$0")
|
||||||
|
#DEBUG=1
|
||||||
|
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
BOOTSTRAP="run [S] /bin/ready.sh -- Ready steady go\n\
|
||||||
|
run [S] name:one initctl -- Query status\n\
|
||||||
|
service [S234] /sbin/service.sh -- Background service\n\
|
||||||
|
run [2] name:two initctl stop service.sh -- Stopping service\n\
|
||||||
|
run [3] name:three initctl start service.sh -- Starting service again\n\
|
||||||
|
run [4] name:four initctl restart service.sh -- Restart service"
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
RCLOCAL="echo \"$0 ==============\" &1>2"
|
||||||
|
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
. "$TEST_DIR/lib/setup.sh"
|
||||||
|
|
||||||
|
test_setup()
|
||||||
|
{
|
||||||
|
say "Test start $(date)"
|
||||||
|
}
|
||||||
|
|
||||||
|
test_teardown()
|
||||||
|
{
|
||||||
|
say "Test done $(date)"
|
||||||
|
}
|
||||||
|
|
||||||
|
say "$FINIT_CONF:"
|
||||||
|
run "cat $FINIT_CONF"
|
||||||
|
say "/etc/rc.local:"
|
||||||
|
run "cat /etc/rc.local"
|
||||||
|
|
||||||
|
say "Waiting for runlevel 2"
|
||||||
|
sleep 2
|
||||||
|
assert_status "service.sh" "stopped"
|
||||||
|
|
||||||
|
say "Changing to runlevel 3"
|
||||||
|
run "initctl runlevel 3"
|
||||||
|
sleep 2
|
||||||
|
assert_status "service.sh" "running"
|
||||||
|
run "initctl"
|
||||||
|
oldpid=$(texec initctl |awk '/service.sh/{print $1}')
|
||||||
|
|
||||||
|
say "Changing to runlevel 4"
|
||||||
|
run "initctl runlevel 4"
|
||||||
|
sleep 2
|
||||||
|
assert_status "service.sh" "running"
|
||||||
|
assert_pidiff "service.sh" "$oldpid"
|
||||||
|
|
||||||
|
run "initctl"
|
||||||
+3
-3
@@ -9,12 +9,12 @@ FINIT_RUNLEVEL=9
|
|||||||
|
|
||||||
test_setup()
|
test_setup()
|
||||||
{
|
{
|
||||||
say "Test start $(date)"
|
say "Test start $(date)"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
}
|
}
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
@@ -23,7 +23,7 @@ test_teardown()
|
|||||||
say 'Check runlevel'
|
say 'Check runlevel'
|
||||||
lvl=$(run "initctl runlevel | awk '{print \$2;}'")
|
lvl=$(run "initctl runlevel | awk '{print \$2;}'")
|
||||||
if [ "$lvl" -eq "9" ]; then
|
if [ "$lvl" -eq "9" ]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|||||||
Executable
+42
@@ -0,0 +1,42 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Verifies basic runparts behavior: to run all scripts in a directory at
|
||||||
|
# the end of system bootstrap, right before calling /etc/rc.local:
|
||||||
|
#
|
||||||
|
# - only executable scripts should be called
|
||||||
|
# - always in alphabetical order
|
||||||
|
# - SNNfoo should be called with a 'start' argument
|
||||||
|
# - KNNfoo should be called with a 'stop' argument
|
||||||
|
#
|
||||||
|
|
||||||
|
TEST_DIR=$(dirname "$0")
|
||||||
|
#DEBUG=1
|
||||||
|
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
BOOTSTRAP="runparts /etc/rc.d"
|
||||||
|
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
. "$TEST_DIR/lib/setup.sh"
|
||||||
|
|
||||||
|
test_setup()
|
||||||
|
{
|
||||||
|
say "Test start $(date)"
|
||||||
|
}
|
||||||
|
|
||||||
|
test_teardown()
|
||||||
|
{
|
||||||
|
say "Test done $(date)"
|
||||||
|
}
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
lvl=$(texec initctl runlevel)
|
||||||
|
say "Current runlevel $lvl"
|
||||||
|
if [ "$lvl" = "N 2" ]; then
|
||||||
|
break;
|
||||||
|
fi
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
|
||||||
|
sleep 1
|
||||||
|
texec diff -u /usr/share/runparts/ref.log /tmp/runparts.log
|
||||||
|
texec cmp /usr/share/runparts/ref.log /tmp/runparts.log || fail "runparts in wrong order"
|
||||||
@@ -12,12 +12,12 @@ cp "$top_builddir/test/src/serv" "$SYSROOT/sbin/"
|
|||||||
FINITBIN="$(pwd)/$top_builddir/src/finit" DEST="$SYSROOT" make -f "$srcdir/lib/sysroot.mk"
|
FINITBIN="$(pwd)/$top_builddir/src/finit" DEST="$SYSROOT" make -f "$srcdir/lib/sysroot.mk"
|
||||||
|
|
||||||
# Drop plugins we don't need in test, only causes confusing FAIL in logs.
|
# Drop plugins we don't need in test, only causes confusing FAIL in logs.
|
||||||
for plugin in tty.so urandom.so rtc.so modprobe.so hotplug.so; do
|
for plugin in tty.so urandom.so rtc.so modprobe.so; do
|
||||||
find "$SYSROOT" -name $plugin -delete
|
find "$SYSROOT" -name $plugin -delete
|
||||||
done
|
done
|
||||||
|
|
||||||
# Drop system .conf files we don't need in test, same as above
|
# Drop system .conf files we don't need in test, same as above
|
||||||
for conf in hotplug.conf; do
|
# shellcheck disable=SC2043
|
||||||
find "$SYSROOT" -name $conf -delete
|
for conf in 10-hotplug.conf; do
|
||||||
|
find "$SYSROOT" -name $conf -delete
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ TEST_DIR=$(dirname "$0")
|
|||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
|
|
||||||
say "Running test teardown."
|
say "Running test teardown."
|
||||||
run "rm -f $FINIT_CONF"
|
run "rm -f $FINIT_CONF"
|
||||||
}
|
}
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
|
|||||||
+32
-31
@@ -2,50 +2,51 @@
|
|||||||
|
|
||||||
nm=$1
|
nm=$1
|
||||||
|
|
||||||
# shellcheck disable=SC2046
|
|
||||||
getpid()
|
getpid()
|
||||||
{
|
{
|
||||||
initctl status "$1" |awk '/PID :/{ print $3; }'
|
initctl status "$1" |awk '/PID :/{ print $3; }'
|
||||||
}
|
}
|
||||||
|
|
||||||
pid=$(getpid "$nm")
|
pid=$(getpid "$nm")
|
||||||
if [ -f oldpid ]; then
|
if [ -f oldpid ]; then
|
||||||
oldpid=$(cat oldpid)
|
oldpid=$(cat oldpid)
|
||||||
|
if [ "$oldpid" = "$pid" ]; then
|
||||||
|
echo "Looks bad, wait for it ..."
|
||||||
|
sleep 3
|
||||||
|
pid=$(getpid "$nm")
|
||||||
if [ "$oldpid" = "$pid" ]; then
|
if [ "$oldpid" = "$pid" ]; then
|
||||||
echo "Looks bad, wait for it ..."
|
echo "Finit did not deregister old PID $oldpid vs $pid"
|
||||||
sleep 3
|
initctl status "$nm"
|
||||||
pid=$(getpid "$nm")
|
ps
|
||||||
if [ "$oldpid" = "$pid" ]; then
|
echo "Reloading finit ..."
|
||||||
echo "Finit did not deregister old PID $oldpid vs $pid"
|
initctl reload
|
||||||
initctl status "$nm"
|
sleep 1
|
||||||
ps
|
initctl status "$nm"
|
||||||
echo "Reloading finit ..."
|
exit 1
|
||||||
initctl reload
|
|
||||||
sleep 1
|
|
||||||
initctl status "$nm"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
timeout=50
|
timeout=50
|
||||||
while [ "$pid" -le 1 ]; do
|
while [ "$pid" -le 1 ]; do
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
pid=$(getpid "$nm")
|
pid=$(getpid "$nm")
|
||||||
if [ "$pid" -le 1 ]; then
|
if [ "$pid" -le 1 ]; then
|
||||||
timeout=$((timeout - 1))
|
timeout=$((timeout - 1))
|
||||||
if [ "$timeout" -gt 0 ]; then
|
if [ "$timeout" -gt 0 ]; then
|
||||||
continue
|
continue
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Got a bad PID: $pid, aborting ..."
|
|
||||||
ps
|
|
||||||
sleep 1
|
|
||||||
initctl status "$nm"
|
|
||||||
ps
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
break
|
|
||||||
|
if [ $pid -ne 0 ]; then
|
||||||
|
echo "Got a bad PID: $pid, aborting ..."
|
||||||
|
ps
|
||||||
|
sleep 1
|
||||||
|
initctl status "$nm"
|
||||||
|
ps
|
||||||
|
fi
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
break
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "$pid" > /tmp/oldpid
|
echo "$pid" > /tmp/oldpid
|
||||||
|
|||||||
@@ -3,3 +3,5 @@
|
|||||||
|
|
||||||
foo=bar
|
foo=bar
|
||||||
baz=qux
|
baz=qux
|
||||||
|
|
||||||
|
xyzzy=$foo
|
||||||
|
|||||||
Executable
+3
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
echo "$0 $*" >> /tmp/runparts.log
|
||||||
Symlink
+1
@@ -0,0 +1 @@
|
|||||||
|
S01abc.sh
|
||||||
Executable
+3
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
echo "$0" >> /tmp/runparts.log
|
||||||
Executable
+3
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
echo "$0" >> /tmp/runparts.log
|
||||||
Executable
+3
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
echo "$0 $*" >> /tmp/sysv.log
|
||||||
Symlink
+1
@@ -0,0 +1 @@
|
|||||||
|
S01abc.sh
|
||||||
Executable
+3
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
echo "$0" >> /tmp/sysv.log
|
||||||
Executable
+3
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
echo "$0" >> /tmp/sysv.log
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
/etc/rc.d/S01abc.sh start
|
||||||
|
/etc/rc.d/S02def.sh start
|
||||||
|
/etc/rc.d/foo.sh
|
||||||
|
/etc/rc.d/test.sh
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
/etc/rcS.d/S01abc.sh start
|
||||||
|
/etc/rcS.d/S02def.sh start
|
||||||
+13
-13
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
#define err(rc, fmt, args...) do {fprintf(stderr, "%s: " fmt ": %s\n", ident, ##args, strerror(errno)); exit(rc);} while(0)
|
#define err(rc, fmt, args...) do {fprintf(stderr, "%s: " fmt ": %s\n", ident, ##args, strerror(errno)); exit(rc);} while(0)
|
||||||
#define errx(rc, fmt, args...) do {fprintf(stderr, "%s: " fmt "\n", ident, ##args); exit(rc);} while(0)
|
#define errx(rc, fmt, args...) do {fprintf(stderr, "%s: " fmt "\n", ident, ##args); exit(rc);} while(0)
|
||||||
#define log(fmt, args...) do {fprintf(stderr, "%s: " fmt "\n", ident, ##args);} while(0)
|
#define inf(fmt, args...) do {fprintf(stderr, "%s: " fmt "\n", ident, ##args);} while(0)
|
||||||
|
|
||||||
volatile sig_atomic_t reloading = 1;
|
volatile sig_atomic_t reloading = 1;
|
||||||
volatile sig_atomic_t running = 1;
|
volatile sig_atomic_t running = 1;
|
||||||
@@ -89,7 +89,7 @@ static void cleanup(void)
|
|||||||
|
|
||||||
static void sig(int signo)
|
static void sig(int signo)
|
||||||
{
|
{
|
||||||
log("Got signal %d ...", signo);
|
inf("Got signal %d ...", signo);
|
||||||
|
|
||||||
switch (signo) {
|
switch (signo) {
|
||||||
case SIGHUP:
|
case SIGHUP:
|
||||||
@@ -120,7 +120,7 @@ static int checkfn(char *fn)
|
|||||||
|
|
||||||
static void mine(char *fn)
|
static void mine(char *fn)
|
||||||
{
|
{
|
||||||
log("Mining for spice in %s", fn);
|
inf("Mining for spice in %s", fn);
|
||||||
writefn(fn, 4711);
|
writefn(fn, 4711);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,11 +136,11 @@ static void pidfile(char *pidfn)
|
|||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
pid = getpid();
|
pid = getpid();
|
||||||
log("Creating PID file %s with %d", pidfn, pid);
|
inf("Creating PID file %s with %d", pidfn, pid);
|
||||||
writefn(pidfn, pid);
|
writefn(pidfn, pid);
|
||||||
atexit(cleanup);
|
atexit(cleanup);
|
||||||
} else {
|
} else {
|
||||||
log("Touching PID file %s", pidfn);
|
inf("Touching PID file %s", pidfn);
|
||||||
utimensat(0, fn, NULL, 0);
|
utimensat(0, fn, NULL, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -265,27 +265,27 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (do_crash) {
|
if (do_crash) {
|
||||||
log("Simulating crash, exiting with code %d", EX_SOFTWARE);
|
inf("Simulating crash, exiting with code %d", EX_SOFTWARE);
|
||||||
exit(EX_SOFTWARE);
|
exit(EX_SOFTWARE);
|
||||||
}
|
}
|
||||||
|
|
||||||
log("Entering while(1) loop");
|
inf("Entering while(1) loop");
|
||||||
while (running) {
|
while (running) {
|
||||||
if (spice) {
|
if (spice) {
|
||||||
log("Checking for spice in %s ...", spice);
|
inf("Checking for spice in %s ...", spice);
|
||||||
if (!checkfn(spice))
|
if (!checkfn(spice))
|
||||||
err(1, "Melange");
|
err(1, "Melange");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reloading) {
|
if (reloading) {
|
||||||
if (do_notify > 0) {
|
if (do_notify > 0) {
|
||||||
log("Delaying notify by 3 seconds for notify.sh ...");
|
inf("Delaying notify by 3 seconds for notify.sh ...");
|
||||||
sleep(3);
|
sleep(3);
|
||||||
log("Notifying Finit on socket %d, READY=1", do_notify);
|
inf("Notifying Finit on socket %d, READY=1", do_notify);
|
||||||
if (write(do_notify, "READY=1\n", 8) == -1)
|
if (write(do_notify, "READY=1\n", 8) == -1)
|
||||||
err(1, "Failed sending ready notification to Finit");
|
err(1, "Failed sending ready notification to Finit");
|
||||||
if (notify_s6) {
|
if (notify_s6) {
|
||||||
log("s6 notify, closing socket %d ...", do_notify);
|
inf("s6 notify, closing socket %d ...", do_notify);
|
||||||
close(do_notify);
|
close(do_notify);
|
||||||
do_notify = 0;
|
do_notify = 0;
|
||||||
}
|
}
|
||||||
@@ -305,12 +305,12 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (melange && vanish++ > 0) {
|
if (melange && vanish++ > 0) {
|
||||||
if (checkfn(melange)) {
|
if (checkfn(melange)) {
|
||||||
log("Oh no, sandworms! Harvest interrupted ...");
|
inf("Oh no, sandworms! Harvest interrupted ...");
|
||||||
remove(melange);
|
remove(melange);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log("Leaving ...");
|
inf("Leaving ...");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ TEST_DIR=$(dirname "$0")
|
|||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
|
|
||||||
say "Running test teardown."
|
say "Running test teardown."
|
||||||
run "rm -f $FINIT_CONF"
|
run "rm -f $FINIT_CONF"
|
||||||
}
|
}
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
@@ -35,9 +35,9 @@ say 'Simulate service crash (kill -9 ..)'
|
|||||||
i=0
|
i=0
|
||||||
laps=1000
|
laps=1000
|
||||||
while [ $i -lt $laps ]; do
|
while [ $i -lt $laps ]; do
|
||||||
i=$((i + 1))
|
i=$((i + 1))
|
||||||
say "Lap $i/$laps, killing service ..." # we have this, no sleep needed
|
say "Lap $i/$laps, killing service ..." # we have this, no sleep needed
|
||||||
run "slay service.sh"
|
run "slay service.sh"
|
||||||
done
|
done
|
||||||
|
|
||||||
retry 'assert_new_pid service.sh /run/service.pid'
|
retry 'assert_new_pid service.sh /run/service.pid'
|
||||||
|
|||||||
+27
-27
@@ -5,51 +5,51 @@ TEST_DIR=$(dirname "$0")
|
|||||||
|
|
||||||
test_setup()
|
test_setup()
|
||||||
{
|
{
|
||||||
say "Test start $(date)"
|
say "Test start $(date)"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
|
|
||||||
say "Running test teardown."
|
say "Running test teardown."
|
||||||
run "rm -f $FINIT_CONF"
|
run "rm -f $FINIT_CONF"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_one()
|
test_one()
|
||||||
{
|
{
|
||||||
pidfn=$1
|
pidfn=$1
|
||||||
service=$2
|
service=$2
|
||||||
|
|
||||||
say "Add service stanza '$service' to $FINIT_CONF ..."
|
say "Add service stanza '$service' to $FINIT_CONF ..."
|
||||||
run "echo '$service' > $FINIT_CONF"
|
run "echo '$service' > $FINIT_CONF"
|
||||||
|
|
||||||
say 'Reload Finit'
|
say 'Reload Finit'
|
||||||
#run "initctl debug"
|
#run "initctl debug"
|
||||||
run "initctl reload"
|
run "initctl reload"
|
||||||
#run "initctl status"
|
#run "initctl status"
|
||||||
#run "ps"
|
#run "ps"
|
||||||
|
|
||||||
#run "initctl status"
|
#run "initctl status"
|
||||||
#run "ps"
|
#run "ps"
|
||||||
#run "initctl status serv"
|
#run "initctl status serv"
|
||||||
|
|
||||||
retry 'assert_num_children 1 serv'
|
retry 'assert_num_children 1 serv'
|
||||||
retry "assert_has_pidfile $pidfn" 1
|
retry "assert_has_pidfile $pidfn" 1
|
||||||
|
|
||||||
say 'Stop the service'
|
say 'Stop the service'
|
||||||
run "initctl stop serv"
|
run "initctl stop serv"
|
||||||
|
|
||||||
retry 'assert_num_children 0 serv'
|
retry 'assert_num_children 0 serv'
|
||||||
|
|
||||||
say 'Start the service again'
|
say 'Start the service again'
|
||||||
run "initctl start serv"
|
run "initctl start serv"
|
||||||
|
|
||||||
retry 'assert_num_children 1 serv'
|
retry 'assert_num_children 1 serv'
|
||||||
|
|
||||||
say "Done, drop service from $FINIT_CONF ..."
|
say "Done, drop service from $FINIT_CONF ..."
|
||||||
run "rm $FINIT_CONF"
|
run "rm $FINIT_CONF"
|
||||||
run "initctl reload"
|
run "initctl reload"
|
||||||
}
|
}
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ TEST_DIR=$(dirname "$0")
|
|||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
|
|
||||||
say "Running test teardown."
|
say "Running test teardown."
|
||||||
run "rm -f $FINIT_RCSD/service.conf"
|
run "rm -f $FINIT_RCSD/service.conf"
|
||||||
}
|
}
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ TEST_DIR=$(dirname "$0")
|
|||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
|
|
||||||
say "Running test teardown."
|
say "Running test teardown."
|
||||||
run "rm -f $FINIT_CONF"
|
run "rm -f $FINIT_CONF"
|
||||||
}
|
}
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ TEST_DIR=$(dirname "$0")
|
|||||||
|
|
||||||
test_teardown()
|
test_teardown()
|
||||||
{
|
{
|
||||||
say "Test done $(date)"
|
say "Test done $(date)"
|
||||||
|
|
||||||
say "Running test teardown."
|
say "Running test teardown."
|
||||||
run "rm -f $FINIT_CONF"
|
run "rm -f $FINIT_CONF"
|
||||||
}
|
}
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
|
|||||||
Executable
+34
@@ -0,0 +1,34 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Ensure service environment variables are sourced and expanded properly.
|
||||||
|
set -e
|
||||||
|
|
||||||
|
TEST_DIR=$(dirname "$0")
|
||||||
|
|
||||||
|
test_setup()
|
||||||
|
{
|
||||||
|
say "Test start $(date)"
|
||||||
|
}
|
||||||
|
|
||||||
|
test_teardown()
|
||||||
|
{
|
||||||
|
say "Test done $(date)"
|
||||||
|
|
||||||
|
say "Running test teardown."
|
||||||
|
run "rm -f $FINIT_CONF"
|
||||||
|
}
|
||||||
|
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
. "$TEST_DIR/lib/setup.sh"
|
||||||
|
|
||||||
|
sep "/etc/env:"
|
||||||
|
run "cat /etc/env"
|
||||||
|
run "echo 'service env:/etc/env serv -np -e xyzzy:bar -- serv checks xyzzy=bar' > $FINIT_CONF"
|
||||||
|
|
||||||
|
say 'Reload Finit'
|
||||||
|
run "initctl reload"
|
||||||
|
|
||||||
|
retry 'assert_num_children 1 serv'
|
||||||
|
|
||||||
|
say "Done, drop service from $FINIT_CONF ..."
|
||||||
|
run "rm $FINIT_CONF"
|
||||||
|
run "initctl reload"
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user