1

I'm tying to use runit to daemonize JBoss.

I use the /opt/jboss-6.1.0.Final/bin/run.sh script to start the server. When I do so from the comandline, JBoss does not detach (which is what we want), and will also shut down when CTRL+C is pressed. In theory a perfect candidate to use runit on.

Everything works fine except when I try to get runit to shut down JBoss. When I issue the command sv stop jboss nothing happens. Runit thinks the process is stopped but jboss continues to run normally.

I'm not doing anything special with the run script. This is my runit run script:

#!/bin/sh
exec 2>&1
exec /opt/jboss-6.1.0.Final/bin/run.sh -c standard -b 0.0.0.0

Looking at the jboss_init_redhat.sh script, the start section does mention ./bin/run.sh but the stop section has the following text:

JBOSS_CMD_STOP=${JBOSS_CMD_STOP:-"java -classpath $JBOSSCP org.jboss.Shutdown --shutdown"}

Any ideas of what I could try?

2 Answers 2

1

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.

1
  • 1
    Nice reply. Thanks for the follow up, can you mark this as the correct answer as it will make your answer easier to find for others with similar problems
    – iain
    Feb 25, 2013 at 11:04
0

When i replaced eval with exec command, I'm getting below exception though java dir is correct and eval is working good. The issue is see when i use eval 2 processes are running when jboss is started. please advice. ./standalone.sh: 289: exec: "/app/dms/java/jdk1.7.0_60/bin/java": not found

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .