For anybody that is in a similar bind, I figured out what the problem was. I'm explaining how I got to the answer as I think it can help solve other problems.
After starting up JBoss with runit, if you execute ps aux | grep jboss
this is the result:
# ps aux | grep jboss
root 1855 0.0 0.0 120 24 ? Ss 11:23 0:00 runsv jboss
root 1856 0.0 0.0 144 44 ? S 11:23 0:00 svlogd -tt /var/log/jboss
root 1857 0.0 0.0 10820 1168 ? S 11:23 0:00 /bin/sh /opt/jboss-6.1.0.Final/bin/run.sh -c standard -b 0.0.0.0
root 1926 178 1.9 1501080 78560 ? Sl 11:23 0:05 java -server -Xms128m -Xmx1024m -XX:MaxPermSize=256m -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n -Djava.net.preferIPv4Stack=true -Dprogram.name=run.sh -Dlogging.configuration=file:/opt/jboss-6.1.0.Final/bin/logging.properties -Djava.library.path=/opt/jboss-6.1.0.Final/bin/native/lib64 -Djava.endorsed.dirs=/opt/jboss-6.1.0.Final/lib/endorsed -classpath /opt/jboss-6.1.0.Final/bin/run.jar org.jboss.Main -c standard -b 0.0.0.0
root 1950 0.0 0.0 61224 764 pts/0 S+ 11:23 0:00 grep jboss
Now execute sv status jboss
and note the pid that sv
reports:
# sv status jboss
run: jboss: (pid 1857) 17s; run: log: (pid 1856) 17s
sv
thinks that jboss' pid is 1857, but checking the output from ps
, jboss actual pid is 1926, the shell that started jboss is pid is 1857. That is the problem, the run.sh script is doing something funny.
If you dig into the run.sh script, after wading through the horrible java classpath concatenation, you can find the following extract:
# Execute the JVM in the foreground
eval \"$JAVA\" $JAVA_OPTS \
-Djava.endorsed.dirs=\"$JBOSS_ENDORSED_DIRS\" \
-classpath \"$JBOSS_CLASSPATH\" \
org.jboss.Main "$@"
JBOSS_STATUS=$?
It's using eval
instead of exec
to execute the jvm! That is why it spawns a separate process, and runit cannot control it correctly.
Just change that part of the script to:
# Execute the JVM in the foreground
exec ${JAVA} $JAVA_OPTS \
-Djava.endorsed.dirs=${JBOSS_ENDORSED_DIRS} \
-classpath ${JBOSS_CLASSPATH} \
org.jboss.Main "$@"
JBOSS_STATUS=$?
And presto! The call to exec
will replace itself with the process executed and runit will be able to control the process correctly.