i'm using JSVC to start my java program as a daemon which should run 24/7.
However, i used to enable JMX to monitor my application until i decided to convert it to a daemon.
My init.d Script is like this
#!/bin/sh
# Setup variables
EXEC=/usr/bin/jsvc
JAVA_HOME=/usr/lib/jvm/java-6-openjdk
CLASS_PATH="/usr/share/java/commons-daemon.jar":"/fullpath/Myserver.jar"
CLASS=myserver.Main
USER=myserver
PID=/var/run/myserver.pid
LOG_OUT=/var/log/myserver/client.out
LOG_ERR=/var/log/myserver/client.err
do_exec()
{
$EXEC -home "$JAVA_HOME" -cp $CLASS_PATH -user $USER -outfile $LOG_OUT -errfile $LOG_ERR -pidfile $PID $1 $CLASS -Xmx30M -Djava.rmi.server.hostname=123.234.12.34 -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.password.file=/fullpath/jmxremote.password -Dcom.sun.management.jmxremote.access.file=/fullpath/jmxremote.access -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=1234
}
case "$1" in
start)
do_exec
;;
stop)
do_exec "-stop"
;;
restart)
if [ -f "$PID" ]; then
do_exec "-stop"
do_exec
else
echo "service not running, will do nothing"
exit 1
fi
;;
*)
echo "usage: daemon {start|stop|restart}" >&2
exit 3
;;
esac
The -D options don't seem to take effect, because port 1234 (or any other port i specify) is not used by JMX.
The application runs just fine, but not JMX. I don't know where to start searching, do you have an idea?
I need to replace:
$EXEC -home "$JAVA_HOME" -cp $CLASS_PATH -user $USER -outfile $LOG_OUT -errfile $LOG_ERR -pidfile $PID $1 $CLASS -Xmx30M -Djava.rmi.server.hostname=123.234.12.34 -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.password.file=/fullpath/jmxremote.password -Dcom.sun.management.jmxremote.access.file=/fullpath/jmxremote.access -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=1234
with:
$EXEC -home "$JAVA_HOME" -cp $CLASS_PATH -user $USER -outfile $LOG_OUT -errfile $LOG_ERR -pidfile $PID -Xmx30M -Djava.rmi.server.hostname=123.234.12.34 -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.password.file=/fullpath/jmxremote.password -Dcom.sun.management.jmxremote.access.file=/fullpath/jmxremote.access -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=1234 $1 $CLASS
so, don't put the additional arguments after $CLASS