I'm trying to create a service that will run in Ubuntu Linux written in Java. My executable Jar file is a big fat Jar file that has all the dependencies packaged inside with it. I get the following error when I try to run it using JSVC.
Java VM created successfully
Class org/apache/commons/daemon/support/DaemonLoader found
Cannot register native methods
java_init failed
Service exit with a return value of 1
What's killing me is the "cannot register native methods" line. What does this mean and how do I fix it?
I'm writing my app in Java using the Eclipse IDE, I installed the latest version of JSVC using apt-get (1.0.10-3). My commons.daemon library version is 1.0.1. My startup script is below.
#!/bin/sh
# Setup variables
EXEC=jsvc
JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-amd64
CLASS_PATH="/usr/hadoop-1.1.1/lib/commons-daemon-1.0.1.jar":"/usr/devel/Hadoop_LCS/"
CLASS=com.foo.hadoop.lcs.Program
USER=hduser
PID=/tmp/lcs_process.pid
LOG_OUT=/tmp/lcs_log.out
LOG_ERR=/tmp/lcs_log.err
do_exec()
{
$EXEC -home "$JAVA_HOME" -cp $CLASS_PATH -user $USER -debug -outfile $LOG_OUT -errfile $LOG_ERR -pidfile $PID $1 $CLASS
}
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
I got it. I just upgraded my version of the Apache commons.daemon library and that did the trick. I got 1.0.15.