mirror of
https://github.com/troglobit/finit.git
synced 2026-11-20 19:41:51 +00:00
initctl: add what was missing from the JSON status
initctl -j status is for other programs and should have all there is,
the plain view is the one kept short. It was the other way around:
the restart counter and restart-max were only in the plain view, and
the restart delay of restart-max-sec was not in the JSON either.
Add a restart object:
"restarts": 7,
"restart": {
"count": 4,
"max": -1,
"delay": 160,
"limit": 300
},
Also add manual and started, and give starts for all services, not
only those with manual-start. The restarts total stays where it is.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
4 files changed
+74
-5
No files matched your search
@@ -14,6 +14,11 @@ All relevant changes are documented in this file.
|
||||
- The `restart_sec:` option of the line-based format is now spelled
|
||||
`restart-sec:`, kebab-case like every other setting. The old spelling
|
||||
is still accepted
|
||||
- `initctl -j status` now has all `initctl` gets from Finit about a
|
||||
service. New is a `restart` object with the restart counter,
|
||||
`restart-max`, the current restart delay and its limit, and `manual`
|
||||
and `started`. `starts` is now there for all services, not only those
|
||||
with `manual-start`
|
||||
- Add `restart-max-sec`, a limit for the delay between restarts of a
|
||||
crashing service. When set, the delay doubles for each restart, from
|
||||
`restart-sec` up to the limit, and comes down again as the service keeps
|
||||
|
||||
@@ -146,6 +146,53 @@ Apr 8 15:02:11 alpine authpriv.info dropbear[2634]: Child connection from 192.1
|
||||
Apr 8 15:02:12 alpine authpriv.notice dropbear[2634]: Password auth succeeded for 'root' from 192.168.121.1:48576
|
||||
```
|
||||
|
||||
With `-j` the same command gives JSON, for scripts and other programs.
|
||||
The view above is kept short for reading, the JSON has everything
|
||||
`initctl` gets from Finit about the service:
|
||||
|
||||
```
|
||||
alpine:~# initctl -j status dialer
|
||||
{
|
||||
"identity": "dialer",
|
||||
"description": "Modem dialer",
|
||||
"type": "service",
|
||||
"forking": false,
|
||||
"status": "restart",
|
||||
"exit": { "code": 1 },
|
||||
"origin": "/etc/finit.d/enabled/dialer.conf",
|
||||
"command": "dialer",
|
||||
"manual": false,
|
||||
"started": false,
|
||||
"starts": 0,
|
||||
"restarts": 7,
|
||||
"restart": {
|
||||
"count": 4,
|
||||
"max": -1,
|
||||
"delay": 160,
|
||||
"limit": 300
|
||||
},
|
||||
"pidfile": "none",
|
||||
"pid": 0,
|
||||
"user": "root",
|
||||
"group": "root",
|
||||
"uptime": 0,
|
||||
"runlevels": [ 2, 3, 4, 5 ]
|
||||
}
|
||||
```
|
||||
|
||||
In `restart`, `count` is the restart counter that `restart-max`, here
|
||||
`max`, is compared to, -1 for `restart = "always"`. The total since
|
||||
boot is in `restarts`. `delay` is the number of seconds before the
|
||||
next restart, should the service crash, and `limit` is its
|
||||
`restart-max-sec`, 0 when not set. `environment`, `condition`, `exit`,
|
||||
and the cgroup members `cgroup`, `memory`, `cpu`, and `limits` are left
|
||||
out when they do not apply.
|
||||
|
||||
```
|
||||
alpine:~# initctl -j status dialer | jq .restart.delay
|
||||
160
|
||||
```
|
||||
|
||||
|
||||
Switch Root
|
||||
-----------
|
||||
|
||||
+20
-5
@@ -1755,12 +1755,27 @@ static int json_status_one(FILE *fp, struct svc_row *r, char *indent, int prev)
|
||||
fprintf(fp,
|
||||
"%s \"condition\": %s,\n", indent, buf);
|
||||
|
||||
if (r->manual)
|
||||
fprintf(fp,
|
||||
"%s \"starts\": %u,\n", indent, r->starts);
|
||||
|
||||
fprintf(fp,
|
||||
"%s \"restarts\": %d,\n", indent, r->restart_tot); /* XXX: add restart_cnt and restart_max */
|
||||
"%s \"manual\": %s,\n"
|
||||
"%s \"started\": %s,\n"
|
||||
"%s \"starts\": %u,\n"
|
||||
"%s \"restarts\": %d,\n"
|
||||
"%s \"restart\": {\n"
|
||||
"%s \"count\": %d,\n"
|
||||
"%s \"max\": %d,\n"
|
||||
"%s \"delay\": %u,\n"
|
||||
"%s \"limit\": %u\n"
|
||||
"%s },\n",
|
||||
indent, r->manual ? "true" : "false",
|
||||
indent, r->started ? "true" : "false",
|
||||
indent, r->starts,
|
||||
indent, r->restart_tot,
|
||||
indent,
|
||||
indent, r->restart_cnt,
|
||||
indent, r->restart_max,
|
||||
indent, r->restart_delay,
|
||||
indent, r->restart_delay_max,
|
||||
indent);
|
||||
|
||||
/* Add memory and CPU information if cgroup support is available */
|
||||
if (cgrp && r->pid > 1) {
|
||||
|
||||
@@ -77,6 +77,8 @@ assert_delay 4 5 4 5
|
||||
|
||||
say 'The restart counter stops where the delay peaks'
|
||||
assert "Delay and limit in status" "$(texec initctl status crash | sed -n 's/.*Restart in : //p')" = "4 sec (max 4)"
|
||||
run "initctl -j status crash"
|
||||
assert "Same in JSON" "$(texec initctl -j status crash | jq -c .restart)" = '{"count":2,"max":-1,"delay":4,"limit":4}'
|
||||
assert "Restart counter is 2" "$(texec initctl status crash | awk '/Restarts/{ print $4 }')" = "(2/-1)"
|
||||
|
||||
sep
|
||||
|
||||
Reference in new issue
Block a user