[EDIT] I changed SIGINT to SIGTERM in whole question.
I have a script which runs subproccess script which starts jboss.
#!/bin/sh
....
start_jboss.sh &
trap 'kill -SIGTERM 0' EXIT HUP TERM INT
....
I want to send SIGTERM signal to jboss when my script was killed, terminated or interrupted. But above code does not terminate JBoss. KILL
signal kills JBoss (following code) but JBoss does not release H2 database lock. It is important in my case to release H2 lock so I have to use SIGTERM signal.
#!/bin/sh
....
start_jboss.sh &
trap 'kill -9 0' EXIT HUP TERM INT
....
My JBoss uses port 8080 so following command gives me a JBoss pid:
sudo netstat -lnpt | grep 8080
If I execute following command:
kill -SIGTERM jboss_pid_from_netstat_command
then JBoss is interrupted and releases H2 database lock.
How to modify my trap action to send SIGTERM
singal to JBoss? I don't know why SIGKILL works and SIGTERM does not work.
[EDIT] I changed SIGINT to SIGTERM in whole question.
EDIT
JBoss start script (standalone.sh
) starts JBoss in foreground process if LAUNCH_JBOSS_IN_BACKGROUND
is not set and starts JBoss in background process if this variable is set. So I set this variable in my script. Following scripts works properly then:
#!/bin/sh
....
export LAUNCH_JBOSS_IN_BACKGORUND=a
standalone.sh &
trap 'kill -SIGTERM 0' EXIT HUP TERM INT
....
#!/bin/sh
....
export LAUNCH_JBOSS_IN_BACKGORUND=a
standalone.sh &
trap 'kill -SIGTERM $(jobs -pr)' EXIT HUP TERM INT
....
#!/bin/sh
....
export LAUNCH_JBOSS_IN_BACKGORUND=a
standalone.sh &
jboss_script_id=$!
trap 'kill -SIGTERM $jboss_script_id' EXIT HUP TERM INT
....
I still have no idea why following code does not work. I work on Centos with bash. I tested it on Ubuntu with dash and following codes work but core dump
warning is thrown.
(not work)
#!/bin/sh
....
standalone.sh &
trap 'kill -SIGTERM 0' EXIT HUP TERM INT
....
or (not work)
#!/bin/sh
....
standalone.sh &
trap 'kill -SIGTERM $(jobs -pr)' EXIT HUP TERM INT
....
or (not work)
#!/bin/sh
....
standalone.sh &
jboss_script_id=$!
trap 'kill -SIGTERM $jboss_script_id' EXIT HUP TERM INT
....