Bug 1940078

Summary: systemd considers a starting service of Type=oneshot being cancelled as Failing
Product: Red Hat Enterprise Linux 8 Reporter: Renaud Métrich <rmetrich>
Component: systemdAssignee: David Tardon <dtardon>
Status: CLOSED ERRATA QA Contact: Frantisek Sumsal <fsumsal>
Severity: medium Docs Contact:
Priority: medium    
Version: 8.3CC: dtardon, msekleta, systemd-maint-list
Target Milestone: rcKeywords: ManPageChange, Triaged
Target Release: ---Flags: pm-rhel: mirror+
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: systemd-239-48.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-11-09 19:56:28 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Renaud Métrich 2021-03-17 14:48:17 UTC
Description of problem:

A customer uses a one-shot service to isolate to a given target.
Due to the service not being "wanted by" the given target, systemd cancels the service while it's starting, which then reports a failure, as shown in the example below:

/etc/systemd/system/foo.service:
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
[Service]
Type=oneshot
ExecStart=/usr/bin/systemctl isolate multi-user.target
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

# systemctl start foo
Job for foo.service canceled.

Journal:
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
Mar 17 15:38:56 vm-rhel8 systemd[1]: Starting foo.service...
Mar 17 15:38:56 vm-rhel8 systemd[1]: foo.service: Main process exited, code=killed, status=15/TERM
Mar 17 15:38:56 vm-rhel8 systemd[1]: foo.service: Failed with result 'signal'.
Mar 17 15:38:56 vm-rhel8 systemd[1]: Stopped foo.service.
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------


Version-Release number of selected component (if applicable):

systemd-239-41.el8_3.1.x86_64

How reproducible:

Always, see above.

Additional info:

I think that because the service startup is cancelled, the service shouldn't enter Failed state.

Comment 1 Renaud Métrich 2021-03-17 14:59:56 UTC
For some reason, adding the following stanza helps:
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
SuccessExitStatus=SIGTERM
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

This looks weird to me since SIGTERM is already a normal exit condition, unless the code handling the Starting state is different and has a bug here.

Comment 2 David Tardon 2021-03-19 08:07:52 UTC
(In reply to Renaud Métrich from comment #1)
> For some reason, adding the following stanza helps:
> -------- 8< ---------------- 8< ---------------- 8< ---------------- 8<
> --------
> SuccessExitStatus=SIGTERM
> -------- 8< ---------------- 8< ---------------- 8< ---------------- 8<
> --------
> 
> This looks weird to me since SIGTERM is already a normal exit condition,
> unless the code handling the Starting state is different and has a bug here.

SIGTERM is not a normal exit condition for oneshot services since https://github.com/systemd/systemd/commit/1f0958f640b87175cd547c1e69084cfe54a22e9d .

Comment 3 Renaud Métrich 2021-03-19 08:28:10 UTC
Sounds legit indeed, hence the manpage needs to be updated.
Current systemd.service(5) manpage on RHEL8.3:

       SuccessExitStatus=
           Takes a list of exit status definitions that, when returned by the main service process, will be
           considered successful termination, in addition to the normal successful exit code 0 and the signals
           SIGHUP, SIGINT, SIGTERM, and SIGPIPE. Exit status definitions can either be numeric exit codes or
           termination signal names, separated by spaces. For example:

Comment 5 Lukáš Nykrýn 2021-06-22 12:31:04 UTC
fix merged to github master branch -> https://github.com/redhat-plumbers/systemd-rhel8/pull/164

Comment 11 errata-xmlrpc 2021-11-09 19:56:28 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (systemd bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2021:4469