Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

service is_running does not work with exit code 4 #748

Open
martinhoyer opened this issue Dec 1, 2023 · 6 comments
Open

service is_running does not work with exit code 4 #748

martinhoyer opened this issue Dec 1, 2023 · 6 comments

Comments

@martinhoyer
Copy link
Contributor

Error code 4:
LSB: "program or service status is unknown"
systemd: "no such unit"

I would expect service.is_running() to return False, when service is not available, while like this is causes a crash, as there is run_expect([0, 1, 3]

Would it be possible to add rc 4, at least to SystemdService?

@arossert
Copy link

arossert commented Jul 2, 2024

I have the same issue, is there a workaround for this one?

@philpep
Copy link
Contributor

philpep commented Sep 17, 2024

Crash is expected no ? I mean a service which doesn't exists should not be reported as just "not running".

@permanentdaylight
Copy link

Crash is expected no ? I mean a service which doesn't exists should not be reported as just "not running".

That makes sense, but the main problem here is the inconsistency in behavior (example of Ubuntu 22 and Ubuntu 24)

$ u22.service('fake').is_running
False

$ u24.service('fake').is_running
AssertionError!

So the painpoint is running the same test against the two distros now requires us to hack the test a bit to account for the same scenario returning separate results.

@pfuntner
Copy link

That makes sense, but the main problem here is the inconsistency in behavior (example of Ubuntu 22 and Ubuntu 24)
...
So the painpoint is running the same test against the two distros now requires us to hack the test a bit to account for the same scenario returning separate results.

I agree. We have some tooling that deals with a variety of distros (Debian, Alma, etc) and Ubuntu 24 is the only one giving trouble. For the time being, I'm slipping in a class with a few methods such as is_enabled() that calls host.service(server_name).is_enabled but inside a try block which returns False when an exception is raised.

@martinhoyer
Copy link
Contributor Author

Ubuntu 24 is the only one giving trouble.

I don't think it's just Ubuntu 24 tbh.

https://refspecs.linuxbase.org/LSB_3.0.0/LSB-PDA/LSB-PDA/iniscrptact.html

manpage of my systemd-255.12-1.fc40:

EXIT STATUS
       On success, 0 is returned, a non-zero failure code otherwise.

       systemctl uses the return codes defined by LSB, as defined in LSB
       3.0.0[3].

       Table 3. LSB return codes
       ┌───────┬─────────────────────┬─────────────────────┐
       │ Value │ Description in LSB  │ Use in systemd      │
       ├───────┼─────────────────────┼─────────────────────┤
       │ 0     │ "program is running │ unit is active      │
       │       │ or service is OK"   │                     │
       ├───────┼─────────────────────┼─────────────────────┤
       │ 1     │ "program is dead    │ unit not failed     │
       │       │ and /var/run pid    │ (used by is-failed) │
       │       │ file exists"        │                     │
       ├───────┼─────────────────────┼─────────────────────┤
       │ 2     │ "program is dead    │ unused              │
       │       │ and /var/lock lock  │                     │
       │       │ file exists"        │                     │
       ├───────┼─────────────────────┼─────────────────────┤
       │ 3     │ "program is not     │ unit is not active  │
       │       │ running"            │                     │
       ├───────┼─────────────────────┼─────────────────────┤
       │ 4     │ "program or service │ no such unit        │
       │       │ status is unknown"  │                     │
       └───────┴─────────────────────┴─────────────────────┘

@philpep
Copy link
Contributor

philpep commented Sep 25, 2024

Crash is expected no ? I mean a service which doesn't exists should not be reported as just "not running".

That makes sense, but the main problem here is the inconsistency in behavior (example of Ubuntu 22 and Ubuntu 24)

$ u22.service('fake').is_running
False

$ u24.service('fake').is_running
AssertionError!

So the painpoint is running the same test against the two distros now requires us to hack the test a bit to account for the same scenario returning separate results.

What about:

if host.service('fake').exists:
    assert host.service('fake').is_running

?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants