[Bug 1828883] Re: systemd sysv-compatibility eats exit codes
Dan Streetman
dan.streetman at canonical.com
Wed May 15 10:58:56 UTC 2019
All sysv service scripts (i.e. /etc/init.d/ scripts) are converted at
runtime into systemd service scripts by the systemd-sysv-generator
script; you can find them in /run/systemd/generator*/ directories.
The systemd-sysv-generator script normally does handle sysv script non-
zero exit codes as an error, but it handles two of them as a non-error
exit:
/* Consider two special LSB exit codes a clean exit */
if (s->has_lsb)
fprintf(f,
"SuccessExitStatus=%i %i\n",
EXIT_NOTINSTALLED,
EXIT_NOTCONFIGURED);
So, this behavior is as-designed in systemd. Any sysv service script returning either "not installed" (5) or "not configured" (6) error codes will be treated as successful/non-error status.
I suggest seeing if openNMS's sysv service script can be changed to
return an error value other than 5 or 6 - are they aware of this
problem?
Alternately, you can locally override the default systemd-sysv-generator
handling of return values, by creating a directory
"/etc/systemd/system/exitcode.service.d" and then creating a file in
that directory, for example
"/etc/systemd/system/exitcode.service.d/error_on_6.conf", with the
contents:
[Service]
SuccessExitStatus=
that will override the generated value (of "5 6") and will cause the 'exitcode' service to return error when the sysv init script returns any non-zero value.
I'm marking this bug as 'invalid' for systemd, as this behavior is as
designed. If you really believe systemd behavior should be different, I
suggest opening a bug with upstream systemd.
** Changed in: systemd (Ubuntu)
Status: New => Invalid
--
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to systemd in Ubuntu.
https://bugs.launchpad.net/bugs/1828883
Title:
systemd sysv-compatibility eats exit codes
Status in systemd package in Ubuntu:
Invalid
Bug description:
Systemd properly honors an exit code of 6 when creating a native
service, like so:
---8<---
ranger at carolina:/lib/systemd/system$ cat exitcode.service
[Unit]
Description=Test Exit Code (Systemd)
[Service]
Type=oneshot
ExecStart=/bin/bash -c 'exit 6'
[Install]
WantedBy=default.target
ranger at carolina:/lib/systemd/system$ sudo systemctl start exitcode
Job for exitcode.service failed because the control process exited with error code.
See "systemctl status exitcode.service" and "journalctl -xe" for details.
ranger at carolina:/lib/systemd/system$ echo $?
1
---8<---
However, the equivalent SysV init file improperly returns an exit code
of 0 when starting under the compatibility layer:
---8<---
ranger at carolina:/etc/init.d$ cat exitcode
#! /bin/sh
### BEGIN INIT INFO
# Provides: exitcode
# Required-Start: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Test Exit Code (SysV)
# Description: Test case for Systemd SysV compatibility layer
### END INIT INFO
exit 6
ranger at carolina:/etc/init.d$ sudo systemctl enable exitcode
exitcode.service is not a native service, redirecting to systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable exitcode
ranger at carolina:/etc/init.d$ sudo systemctl start exitcode
ranger at carolina:/etc/init.d$ echo $?
0
---8<---
Even if I change the script to do `exit 1` it still returns exit code
0.
These are tiny examples but we are hitting it in the real world with
the startup scripts for the OpenNMS Debian/Ubuntu packages, which
return exit code 6 (LSB "not configured") when there are leftover
upgrade files in `/etc/opennms`. The OpenNMS startup is not properly
failing on attempted startup in this case.
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1828883/+subscriptions
More information about the foundations-bugs
mailing list