api: services: improve state detection for one-shot units

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2021-07-13 18:47:05 +02:00
parent 7195dcd37a
commit 4ec19e8487

View File

@ -116,7 +116,12 @@ my $service_state = sub {
if (my $err = $@) {
return $res;
}
$res->{state} = $ss->{SubState} || 'unknown';
my $state = $ss->{SubState} || 'unknown';
if ($state eq 'dead' && $ss->{Type} && $ss->{Type} eq 'oneshot' && $ss->{Result}) {
$res->{state} = $ss->{Result};
} else {
$res->{state} = $ss->{SubState} || 'unknown';
}
$res->{'active-state'} = $ss->{ActiveState} || 'unknown';
$res->{'unit-state'} = $ss->{UnitFileState} || 'unknown';