python 3.x – Fabric: running "systemctl state" in process stopped


I experience unexpected behavior with fabric 2.5 in Red Hat:

When executing & # 39; systemctl status & # 39; While the respective process is running, Fabric returns as expected:

>>> from fabric import Connection
>>> hostname = 'foo.bar'
>>> c = Connection(host=hostname, user=foo, connect_kwargs={"password":"bar",})
>>> result = c.sudo('systemctl status postgresql-9.6.service)
postgresql-9.6.service - PostgreSQL 9.6 database server
 Loaded: loaded(/usr    /lib ...)  ...
Active: active (running) since ...  ...

However, when executing the same thing in a process that stops, Fabric returns with exit code 3:

>>> result = c.sudo('systemctl stop postgresql-9.6.service)
>>> result = c.sudo('systemctl status postgresql-9.6.service)
postgresql-9.6.service - PostgreSQL 9.6 database server
 Loaded: loaded(/usr    /lib ...)  ...
Active: inactive (dead) since ...  ...
...
Traceback (most recent call list):
...
raise UnexpectedExit(result)
invoke.exceptions.UnexpectedExit: Encountered a bad command exit code!

Command: "sudo -S -p '(sudo) password: ' systemctl status postgresql-9.6.service"

Exit code: 3

Stdout: already printed

Stderr: n/a (PTYs have no stderr)