Commit 17dfed49 authored by segfault's avatar segfault

Add debug output to error message

parent 78e7267a
......@@ -49,7 +49,8 @@ class SystemdManager(object):
return
time.sleep(0.2)
raise SystemdError("Failed to start %s (timeout: %s)", self.id, START_TIMEOUT)
raise SystemdError("Failed to start %s (timeout: %s). systemctl status: %s" %
(self.id, START_TIMEOUT, self._get_service_status_output()))
def is_running(self) -> bool:
try:
......@@ -142,16 +143,7 @@ class SystemdManager(object):
active_state, sub_state = self._get_state()
if active_state in ("inactive", "failed") or sub_state == "exited":
# Get systemctl status output for debugging
output = None
try:
output = sh.systemctl("--no-pager", "-M", self.container, "status", self.service, _ok_code=[0, 3])
except sh.ErrorReturnCode:
# `systemctl status` currently returns exit code 3 if the unit is stopped,
# but we shouldn't rely on that, so we ignore other error exit codes too
pass
logger.error("Service '%s' stopped. systemctl status: %s", self.service, output)
logger.error("Service '%s' stopped. systemctl status: %s", self.service, self._get_service_status_output())
self.status_callback(Status.ERROR)
def _get_state(self) -> (str, str):
......@@ -163,3 +155,19 @@ class SystemdManager(object):
sub_state = lines[1].split('=')[-1]
logger.debug("Service %r state: ActiveState: %r, SubState: %r", self.service, active_state, sub_state)
return active_state, sub_state
def _get_service_status_output(self) -> str:
# Get systemctl status output for debugging
output = str()
try:
output = sh.systemctl("--no-pager", "--lines=0", "-M", self.container,
"status", self.service, _ok_code=[0, 3]).stdout.decode()
# In the current version (238) systemctl status does not include
# log lines when using the -M option, so we add those to the output ourselves
output += '\n' + sh.journalctl("--no-pager", "--lines=10", "-M", self.container,
"_SYSTEMD_UNIT=" + self.service).stdout.decode()
except sh.ErrorReturnCode:
# `systemctl status` currently returns exit code 3 if the unit is stopped,
# but we shouldn't rely on that, so we ignore other error exit codes too
pass
return output
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment