I am trying to unmount my application using Apache Commons Daemon using the Daemon interface. A Java application by itself does nothing, it just writes in thick.
I compiled jsvc: http://people.apache.org/~mturk/daemon-1.0.10/
(even tried the new version: http://people.apache.org/~mturk/daemon-1.0.12/ )
and wrote this basic script.
do_exec() { $EXEC \ -home "$JAVA_HOME" \ -cp $CLASS_PATH \ -outfile $LOG_OUT \ -errfile $LOG_ERR \ -pidfile $PID \ $1 \ $MAIN_CLASS echo "result: $?" } case "$1" in start) do_exec ;; stop) do_exec "-stop" ;; restart) do_exec "-stop" do_exec ;; *) echo "usage: daemon {start|stop|restart}" >&2 exit 3 ;; esac
Now, when I try to stop the daemon when it does not work, I will get a 255 response code. This is fantastic.
But when I try to start the daemon when it is already running, I get a response code of 0. But in my errfile I find:
Still running according to PID file /tmp/deamon.pid, PID is 1799 Service exit with a return value of 122
Same thing when I try to throw an exception in the start () method and try to start the daemon, the response code is 0. But errfile:
Service exit with a return value of 5
What am I missing here? How can I tell user stat that deamon was not starting or that it was already running?
source share