Stop Daemon not terminating child java process

1k views Asked by At

following setup

Start-Stop-Daemon:

do_start
start-stop-daemon -S -m -p $PIDFILE --name myapp --exec /opt/myapp

do_stop
start-stop-daemon -K -R TERM/30/KILL/5 -p $PIDFILE --name myapp

the script I start looks like that:

 java -jar ./myapp.jar

so when I start my daemon everything is working fine, PIDFILE is generated. ps aux | grep myapp gives me 2 outputs, one for the daemon and one for the java, as child. If I do want to stop it, only the daemon is stopped the java process keeps running detached from console.

How do I need to change my daemon/script to also term the java application when I stop the daemon?

1

There are 1 answers

0
Simon Fischer On BEST ANSWER

The reason why this does not work is that you are really just stopping /opt/myapp which when being killed does not automatically kill its children (the java process). Either do that in your script manually (which is tricky) or have the start-stop-daemon start java directly. It should then loook like this

start-stop-daemon -S -m -p $PIDFILE --name myapp --exec java -- -jar ./myapp.jar