Discussion:
[systemd-devel] Cannot make java exit 0 on SIGTERM
Chris Paulson-Ellis
2011-11-28 15:12:13 UTC
Permalink
Hi,

I'm running a Java JVM service using:

ExecStart=/usr/bin/java -jar foo.jar

When I stop the service with systemctl, it goes into the failed state
because the JVM exits with status 143 instead of 0.

There doesn't seem to be any way to get a JVM to exit(0) on SIGTERM. You
can run code on the signal with Runtime.addShutdownHook(), but you
cannot call Runtime.exit(0) from within a shutdown hook, so you cannot
influence the exit status.

Is there any way to get systemd to treat the 143 exit status as normal
termination if it sent a SIGTERM? I'd rather not write a signal catching
C or shell-script wrapper around the JVM as I'll probably introduce a
race condition or other error.

Chris.
Peter Sztan
2011-11-29 09:26:17 UTC
Permalink
Post by Chris Paulson-Ellis
Is there any way to get systemd to treat the 143 exit status as normal
termination if it sent a SIGTERM? I'd rather not write a signal catching
C or shell-script wrapper around the JVM as I'll probably introduce a
race condition or other error.
Chris.
Yes there is, see:
http://0pointer.de/public/systemd-man/systemd.service.html
the part about ExecStart.
Lennart Poettering
2011-12-15 15:56:32 UTC
Permalink
Post by Chris Paulson-Ellis
Hi,
ExecStart=/usr/bin/java -jar foo.jar
When I stop the service with systemctl, it goes into the failed
state because the JVM exits with status 143 instead of 0.
There doesn't seem to be any way to get a JVM to exit(0) on SIGTERM.
You can run code on the signal with Runtime.addShutdownHook(), but
you cannot call Runtime.exit(0) from within a shutdown hook, so you
cannot influence the exit status.
Is there any way to get systemd to treat the 143 exit status as
normal termination if it sent a SIGTERM? I'd rather not write a
signal catching C or shell-script wrapper around the JVM as I'll
probably introduce a race condition or other error.
Use ExecStart=-/usr/bin/java... (i.e. add the - in there, to ignore
failure exit codes)

Lennart
--
Lennart Poettering - Red Hat, Inc.
mokasin
2012-02-16 21:53:56 UTC
Permalink
Post by Lennart Poettering
Post by Chris Paulson-Ellis
Hi,
ExecStart=/usr/bin/java -jar foo.jar
When I stop the service with systemctl, it goes into the failed
state because the JVM exits with status 143 instead of 0.
There doesn't seem to be any way to get a JVM to exit(0) on SIGTERM.
You can run code on the signal with Runtime.addShutdownHook(), but
you cannot call Runtime.exit(0) from within a shutdown hook, so you
cannot influence the exit status.
Is there any way to get systemd to treat the 143 exit status as
normal termination if it sent a SIGTERM? I'd rather not write a
signal catching C or shell-script wrapper around the JVM as I'll
probably introduce a race condition or other error.
Use ExecStart=-/usr/bin/java... (i.e. add the - in there, to ignore
failure exit codes)
Lennart
It seems also to ignore an exit code due to an error.

If the service failed to start for an actual reason, wouldn't systemd
fail to recognize it?
Lennart Poettering
2012-02-20 15:57:56 UTC
Permalink
Post by mokasin
Post by Lennart Poettering
failure exit codes)
Lennart
It seems also to ignore an exit code due to an error.
If the service failed to start for an actual reason, wouldn't systemd
fail to recognize it?
Yes, we prefixing with "-" ensures that all unclean exit results of a
process are considered OK, which precise signal codes and retvals those
are you cannot specify.

I don't think it makes too much sense to make this
configurable.

Lennart
--
Lennart Poettering - Red Hat, Inc.
Loading...