I'm running an application written in scala (running on the jvm) as a systemd service configured with ExecStart=java -jar Darts-Backend-assembly-0.1.0.jar
.
On systemctl stop darts
the application is terminated by sending it a SIGTERM signal. journalctl interprets the non-zero exit code of the application terminated by SIGTERM as a failure:
Feb 25 13:10:00 DartberryPi systemd[1]: darts.service: Main process exited, code=exited, status=143/n/a
Feb 25 13:10:00 DartberryPi systemd[1]: darts.service: Failed with result 'exit-code'.
As far as I understand there is no way of configuring the exit code of a Scala (of Java for that matter) application when receiving a e.g. SIGTERM signal. There also seems to be no way to configure systemd to accept 143 as a succefful termination of a process and still interpret all other non-zero exit codes as failures.
The goal is to have termination by SIGTERM interpreted as a successful termination and other terminations (e.g. from an actual failure such as an unhandled exception) still logged as a failure.
Does anyone know a way around this? Or do you just accept that journalctl logs failure? Or do you just ignore all non-zero exit codes with ExecStart=-java -jar Darts-Backend-assembly-0.1.0.jar
?
CodePudding user response:
systemd services do actually have an option to handle a non-zero exit status as successful.
[Service]
SuccessExitStatus=143
Consider that, as expected, this doesn't change the fact that 0
is still a successful exit status.
More info in the systemd manual.