Bug 1256858 - systemctl does not distinguish between stopped and non-existing service using exit code
systemctl does not distinguish between stopped and non-existing service using...
Status: ASSIGNED
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: systemd (Show other bugs)
7.2
Unspecified Unspecified
low Severity low
: rc
: ---
Assigned To: systemd-maint
Branislav Blaškovič
:
Depends On:
Blocks: 1289485 1313485 1400961 1472751
  Show dependency treegraph
 
Reported: 2015-08-25 11:32 EDT by Dalibor Pospíšil
Modified: 2017-08-21 04:33 EDT (History)
9 users (show)

See Also:
Fixed In Version: systemd-219-27.el7
Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed:
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Dalibor Pospíšil 2015-08-25 11:32:03 EDT
Description of problem:
Systemctl status returns the same exit code (0) for stopped and non-existing service. This is also propagated to service wrapper. The behavior is different from RHEL6. It would be good to distinguish this also by exit code as it gives scripts more flexibility.

Version-Release number of selected component (if applicable):
systemd-219-11.el7

How reproducible:
100%

Actual results:
# service atd stop
# service XYZ status; echo $?
Redirecting to /bin/systemctl status  XYZ.service
● XYZ.service
   Loaded: not-found (Reason: No such file or directory)
   Active: inactive (dead)
3
# service atd status; echo $?
Redirecting to /bin/systemctl status  atd.service
● atd.service - Job spooling tools
   Loaded: loaded (/usr/lib/systemd/system/atd.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Út 2015-08-25 11:23:50 EDT; 1s ago
 Main PID: 1382 (code=exited, status=0/SUCCESS)

srp 24 10:03:49 ibm-p8-kvm-10-guest-04.lab4.eng.bos.redhat.com systemd[1]: Started Job spooling tools.
srp 24 10:03:49 ibm-p8-kvm-10-guest-04.lab4.eng.bos.redhat.com systemd[1]: Starting Job spooling too...
srp 25 11:23:50 ibm-p8-kvm-10-guest-04.lab4.eng.bos.redhat.com systemd[1]: Stopping Job spooling too...
srp 25 11:23:50 ibm-p8-kvm-10-guest-04.lab4.eng.bos.redhat.com systemd[1]: Stopped Job spooling tools.
Hint: Some lines were ellipsized, use -l to show in full.
3


Expected results:
# service atd stop
# service XYZ status; echo $?
Redirecting to /bin/systemctl status  XYZ.service
● XYZ.service
   Loaded: not-found (Reason: No such file or directory)
   Active: inactive (dead)
7   <<<<<<<<<<<<< this should not be 3


Additional info:
Comment 1 Michal Sekletar 2015-08-31 03:47:45 EDT
I don't think changing the return code is a good idea. "It was like that on RHEL6" is not a solid argument to me, sorry. Now return code of status action complies to LSB. On RHEL6 service XYZ status returns 1, which to me seems completely bogus.

I can pretty much guarantee you that once we change return code, someone comes along waving with LSB in their hands.

Anyway, systemd is now cross-distro effort, so maybe I am wrong and we can change return code after all. This must be decided upstream, to make sure it is consistent everywhere.

http://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic.html#TOCSYSINIT
Comment 2 Dalibor Pospíšil 2015-08-31 04:35:27 EDT
According to the document you have linked, exit code 4 would make sense.
program or service status is unknown - we do not know anything about the service so we do not know the status.
Comment 3 Michal Sekletar 2015-08-31 04:46:04 EDT
Sure, exit code 4 might make sense. I'll ask redhat-lsb maintainer about his opinion. At any rate, this must be discussed and agreed on upstream before we make any changes. Do you care to file an issue on GitHub about this? Or I can do it on you behalf, let me know.
Comment 4 Dalibor Pospíšil 2015-08-31 05:20:51 EDT
Currently I am not able to file it there, so please file it by yourself, thanks.
Comment 5 Lukáš Nykrýn 2015-09-08 04:19:38 EDT
https://github.com/systemd/systemd/issues/1092
Comment 8 Branislav Blaškovič 2016-06-06 07:29:21 EDT
qa acking.
Comment 15 Jan Synacek 2016-08-10 10:42:35 EDT
https://github.com/lnykryn/systemd-rhel/pull/44
Comment 20 dearfriend 2016-11-23 05:30:32 EST
RHEL is OK now
But the same in Fedora.

Note You need to log in before you can comment on or make changes to this bug.