Bug 1367406 - systemctl restart returns 0 for a failed service
Summary: systemctl restart returns 0 for a failed service
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: systemd
Version: 7.3
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: systemd-maint
QA Contact: Frantisek Sumsal
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-08-16 11:10 UTC by Frantisek Sumsal
Modified: 2016-08-16 11:41 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2016-08-16 11:41:42 UTC
Target Upstream Version:


Attachments (Terms of Use)

Description Frantisek Sumsal 2016-08-16 11:10:37 UTC
Description of problem:
systemctl restart returns 0 even if given service fails during its restart. As an example I used openssh service (sshd). Both used versions of openssh have identical unit files.

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

How reproducible:
always

Steps to Reproduce:
1. echo 'AuthenticationMethods garbage' >>/etc/ssh/sshd_config
2. systemctl restart sshd
3. echo $?
4. systemctl status sshd

Actual results:
# echo 'AuthenticationMethods garbage' >>/etc/ssh/sshd_config
# systemctl restart sshd
# echo $?
0
# systemctl status sshd
● sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
   Active: activating (auto-restart) (Result: exit-code) since Tue 2016-08-16 06:55:52 EDT; 8s ago
     Docs: man:sshd(8)
           man:sshd_config(5)
  Process: 1537 ExecStart=/usr/sbin/sshd -D $OPTIONS (code=exited, status=255)
 Main PID: 1537 (code=exited, status=255)

Aug 16 06:55:52 qeos-157 systemd[1]: sshd.service: main process exited, code=exited, status=255/n/a
Aug 16 06:55:52 qeos-157 systemd[1]: Unit sshd.service entered failed state.
Aug 16 06:55:52 qeos-157 systemd[1]: sshd.service failed.

Expected results:
systemctl restart should return non-zero exit code. This actually worked in systemd-219-22.el7:

# echo 'AuthenticationMethods garbage' >>/etc/ssh/sshd_config
# systemctl restart sshd
Job for sshd.service failed because the control process exited with error code. See "systemctl status sshd.service" and "journalctl -xe" for details.
# echo $?
1

Additional info:
I guess this behavior is caused by fix for BZ#1362461 (sshd has Restart=on-failure and quite big RestartSec delay: 42s).

Comment 3 Lukáš Nykrýn 2016-08-16 11:41:42 UTC
Seems to be working with latest systemd. This is reproducible only in the case that the service is Type=Simple, but for those systemctl does not wait.


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