mirror of
https://github.com/troglobit/finit.git
synced 2026-10-21 11:29:42 +00:00
Add remain:yes option for run/task oneshot commands
Similar to systemd's RemainAfterExit=yes. Prevents the task from
re-running on runlevel re-entry and ensures the post: script runs
when explicitly stopped or when leaving valid runlevels.
Useful for tasks that set up persistent state like firewall rules:
task [2345] remain:yes \
post:/usr/sbin/teardown-firewall \
/usr/sbin/setup-firewall -- Firewall setup
Not supported for bootstrap-only tasks (runlevel S only) since these
are deleted immediately after completion.
This commit is contained in:
1 parent
a215747355
commit
5f7e8457af
7 files changed
+121
-4
No files matched your search
@@ -69,6 +69,11 @@ confines of that the following options are available:
|
||||
* `respawn` -- bypasses the `restart` mechanism completely, allows
|
||||
endless restarts. Useful in many use-cases, but not what `service`
|
||||
was originally designed for so not the default behavior
|
||||
* `remain:yes` -- for `run` and `task` only. Prevents the task from
|
||||
re-running on runlevel re-entry and ensures the `post:` script runs
|
||||
when the task is explicitly stopped or leaves its valid runlevels.
|
||||
Similar to systemd's `RemainAfterExit=yes`. See [Task and Run](task-and-run.md)
|
||||
for more details
|
||||
* `oncrash:reboot` -- when all retries have failed, and the service
|
||||
has *crashed*, if this option is set the system is rebooted
|
||||
* `oncrash:script` -- similarly, but instead of rebooting, call the
|
||||
|
||||
@@ -44,3 +44,44 @@ redirects can be used:
|
||||
|
||||
Please note, `;`, `&&`, `||`, and similar are *not supported*. Any
|
||||
non-trivial constructs are better placed in a separate shell script.
|
||||
|
||||
|
||||
remain:yes
|
||||
----------
|
||||
|
||||
By default, a `run` or `task` will re-run each time its runlevel is
|
||||
entered, and its `post:` script does not run on completion.
|
||||
|
||||
With `remain:yes`, the task runs once and does not re-run on runlevel
|
||||
re-entry:
|
||||
|
||||
task [2345] remain:yes /usr/sbin/setup-firewall -- Firewall setup
|
||||
|
||||
This has the following effects:
|
||||
|
||||
* The task does not re-run on runlevel re-entry
|
||||
* The `post:` script runs when:
|
||||
- The task is explicitly stopped (`initctl stop NAME`)
|
||||
- The task leaves its valid runlevels (e.g., runlevel change)
|
||||
|
||||
This is useful for tasks that set up persistent state where:
|
||||
|
||||
* Cleanup should only happen on explicit stop or when leaving valid runlevels
|
||||
* The setup should not be re-run on every runlevel entry
|
||||
|
||||
**Example:** Setting up firewall rules with cleanup on shutdown:
|
||||
|
||||
```
|
||||
task [2345] remain:yes \
|
||||
post:/usr/sbin/teardown-firewall \
|
||||
/usr/sbin/setup-firewall -- Firewall setup
|
||||
```
|
||||
|
||||
The firewall rules are created once. The `post:` script runs when
|
||||
entering runlevel 0 (halt) or 6 (reboot), or on explicit stop.
|
||||
|
||||
> [!NOTE]
|
||||
> The `remain:yes` option is not supported for bootstrap-only tasks
|
||||
> (tasks with only runlevel S). Bootstrap tasks are deleted immediately
|
||||
> after completion, and their `post:` scripts never run. A warning is
|
||||
> logged if `remain:yes` is used on such tasks.
|
||||
Reference in new issue
Block a user