Miel Donkers created KARAF-6963:
-----------------------------------
Summary: Stopping Karaf daemon invokes kill -9, resulting in
failed systemd service
Key: KARAF-6963
URL: https://issues.apache.org/jira/browse/KARAF-6963
Project: Karaf
Issue Type: Bug
Components: karaf
Affects Versions: 4.2.4
Environment: Linux + systemd
Reporter: Miel Donkers
Karaf supplies an example systemd file:
[https://github.com/apache/karaf/blob/master/assemblies/features/base/src/main/resources/resources/bin/contrib/karaf-service-template.systemd]
For our solution we use a similar systemd service file. However we noticed that
when stopping the service, it's always left in a "failed" state:
{code:java}
root@vagrant:/opt/instana/agent# systemctl stop instana-agent
root@vagrant:/opt/instana/agent# systemctl status instana-agent
● instana-agent.service - "Instana(tm) agent."
Loaded: loaded (/lib/systemd/system/instana-agent.service; enabled; vendor
preset: enabled)
Active: failed (Result: signal) since Tue 2020-12-15 20:29:44 UTC; 2s ago
Process: 5461 ExecStop=/opt/instana/agent/bin/karaf stop (code=exited,
status=0/SUCCESS)
Process: 5371 ExecStart=/opt/instana/agent/bin/karaf daemon (code=killed,
signal=KILL)
Main PID: 5371 (code=killed, signal=KILL)
{code}
This is not due to the way the systemd service is being stopped, but rather due
to how the "stop" command is handled internally. Following the execution path
from the "karaf" script, this eventually leads to
[https://github.com/apache/karaf/blob/bb175f9c613921a20e017c343e6b978a3e80c80e/util/src/main/java/org/apache/karaf/jpm/impl/ProcessImpl.java#L84]
{code:java}
ret = ScriptUtils.executeProcess(new java.lang.ProcessBuilder("kill", "-9",
Integer.toString(pid)));
{code}
Instead of doing a hard `kill -9`, it would be much nicer to first execute a
'kill', followed by checking if the process nicely shuts down and if not
executing the 'kill -9'.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)