Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SuccessExitStatus= confusingly does not affect the symbolic name mapping of exit statuses in "systemctl status" output #15757

Closed
joshuamiller01 opened this issue May 8, 2020 · 3 comments · Fixed by #15776

Comments

@joshuamiller01
Copy link

joshuamiller01 commented May 8, 2020

systemd version the issue has been seen with

244

Used distribution

CentOS7

Expected behaviour you didn't see

Main PID (as reported by systemctl status <service> exit shows SUCCESS when exit code of ExecStart matches SuccessExitStatus

Unexpected behaviour you saw

Main PID shows status=1/FAILURE, even though unit isn't marked as failed (per 'Active: inactive' from systemctl status <service>

Steps to reproduce the problem
If I create a timer, which runs a oneshot service, and ExecStart returns 1, I expect it to fail, which it does:

[root@somehost ~]# cat /etc/systemd/timers/test.timer
[Unit]
Description=test timer
Requires=test.service

[Install]
WantedBy=timers.target

[Timer]
OnCalendar=*:0/10:0
Unit=test.service

[root@somehost ~]# cat /etc/systemd/timers/test.service
[Unit]
Description=test service
After=network.target

[Service]
Type=oneshot
ExecStart=/bin/false
#SuccessExitStatus=1

[root@somehost ~]# systemctl link /etc/systemd/timers/test.timer
Created symlink /etc/systemd/system/test.timer → /etc/systemd/timers/test.timer.
[root@somehost ~]# systemctl link /etc/systemd/timers/test.service
Created symlink /etc/systemd/system/test.service → /etc/systemd/timers/test.service.
[root@somehost ~]#
[root@somehost ~]# systemctl start test.timer
[root@somehost ~]# systemctl status test.service
● test.service - test service
     Loaded: loaded (/etc/systemd/timers/test.service; linked; vendor preset: enabled)
     Active: failed (Result: exit-code) since Fri 2020-05-08 10:12:47 PDT; 11s ago
TriggeredBy: ● test.timer
    Process: 3377705 ExecStart=/bin/false (code=exited, status=1/FAILURE)
   Main PID: 3377705 (code=exited, status=1/FAILURE)
        CPU: 1ms

May 08 10:12:47 somehost systemd[1]: Starting test service...
May 08 10:12:47 somehost systemd[1]: test.service: Main process exited, code=exited, status=1/FAILURE
May 08 10:12:47 somehost systemd[1]: test.service: Failed with result 'exit-code'.
May 08 10:12:47 somehost systemd[1]: Failed to start test service.

The problem is that, if I fix the service unit to have SuccessExitStatus=1, and reload, subsequent runs of the service show it as partially failing; the unit is correctly marked as 'inactive (dead)', but MainPID reports '(code=exited, status=1/FAILURE)'.

[root@somehost ~]# vi /etc/systemd/timers/test.service  # Uncomment SuccessExitStatus
[root@somehost ~]# systemctl daemon-reload
[root@somehost ~]# systemctl start test.service
[root@somehost ~]# systemctl status test.service
● test.service - test service
     Loaded: loaded (/etc/systemd/timers/test.service; linked; vendor preset: enabled)
     Active: inactive (dead) since Fri 2020-05-08 10:13:30 PDT; 3s ago
TriggeredBy: ● test.timer
    Process: 3380053 ExecStart=/bin/false (code=exited, status=1/FAILURE)
   Main PID: 3380053 (code=exited, status=1/FAILURE)
        CPU: 1ms

May 08 10:13:30 somehost systemd[1]: Starting test service...
May 08 10:13:30 somehost systemd[1]: test.service: Succeeded.
May 08 10:13:30 somehost systemd[1]: Started test service.
[root@somehost ~]#
@joshuamiller01
Copy link
Author

Hmm, actually, even if you start with the service having SuccessExitStatus properly set, you still get the partial failure reported: "(code=exited, status=1/FAILURE)" even though the unit isn't marked as failed.

@poettering
Copy link
Member

Ah, this is a misunderstanding. The "1/FAILURE" display just shows the numeric code and the textual name of it, i.e. using the table "systemd-analyze exit-status" shows you. SuccessExitStatus= does not affect that textual mapping, it only controls what happens as result of a such an exit status.

I'll prep a PR that tries to clear this up a bit.

poettering added a commit to poettering/systemd that referenced this issue May 11, 2020
poettering added a commit to poettering/systemd that referenced this issue May 11, 2020
…ExitStatus=

Fixes: systemd#15757

(Note there's quite some confusion regarding "exit status" vs. "exit
code" in the docs here. We should clean this up fully one day. This
change tries to fix some occasions of the wrong use, but not all.)
@poettering
Copy link
Member

documentation fix waiting in #15776

@poettering poettering changed the title timer partially marked as failed with nonzero exit despite SuccessExitStatus SuccessExitStatus= confusingly does not affect the symbolic name mapping of exit statuses in "systemctl status" output May 11, 2020
keszybz pushed a commit that referenced this issue May 11, 2020
…ExitStatus=

Fixes: #15757

(Note there's quite some confusion regarding "exit status" vs. "exit
code" in the docs here. We should clean this up fully one day. This
change tries to fix some occasions of the wrong use, but not all.)
eworm-de pushed a commit to eworm-de/systemd that referenced this issue Jun 23, 2020
…ExitStatus=

Fixes: systemd#15757

(Note there's quite some confusion regarding "exit status" vs. "exit
code" in the docs here. We should clean this up fully one day. This
change tries to fix some occasions of the wrong use, but not all.)

(cherry picked from commit 1e0d5ee)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants