4

How to get the exit-code of a failed systemd service ?

service some_service status prints the following :

 Active: failed (Result: exit-code)

But what is that exit-code ?

And are those exit-codes standard or do they have different meanings for different services?

1 Answer 1

5

systemctl status does have what you're looking for:

$ systemctl status openproject-web-1.service
● openproject-web-1.service
   Loaded: loaded (/etc/systemd/system/openproject-web-1.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2020-05-25 08:17:17 CEST; 1 day 4h ago
  Process: 969 ExecStart=/usr/bin/openproject run web (code=exited, status=203/EXEC)
 Main PID: 969 (code=exited, status=203/EXEC)

You see here under Main PID: you have (code=exited, status=203/EXEC). That 203 is the exit code.

The exit codes are up to the specific application, but there are conventions. 0 is successful exit, 1-255 is abnormal exit, 256+ is out of range. The posix standard has a few special cases. But you'll want to look at the documentation of the application for anything more than that.

For example, grep(1) says:

...the exit status is 0 if a line is selected, 1 if no lines were selected, and 2 if an error occurred

As JdePB describes below, systemd may set some exit codes itself in the range of 200 to 242. In the example above we have exit code 203 which means the actual execution failed (maybe the file was not found or was not marked as executable).

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.