1

I'm trying to deamonize my Java app using jsvc. This is my initscript

#!/bin/sh

# CONFIG
JSVC=/opt/jsvc/jsvc
JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk.x86_64
USER=gserv
ARGS=none
# END CONFIG

PIDFILE=/var/run/silvercar-gameserver.pid
LOGDIR=/var/log/silvercar-gameserver

case "$1" in
        start)
                export JAVA_HOME
                cd `dirname $0`
                $JSVC -jvm server -pidfile $PIDFILE -user $USER -outfile $LOGDIR/stdout -errfile $LOGDIR/stderr \
                         -cp `cat classpath` tr.silvercar.gameserver.runner.DeamonGameServer $ARGS
                ;;
        stop)
                $JSVC -stop -pidfile $PIDFILE
                ;;
esac

exit 0

When I run ./thisscript.sh start as root two things go wrong, and I suspect they're related:

  • The app starts, but its output is shown instead of saved to the specified outfile
  • The script doesn't exit, but blocks until I hit Ctrl+C.

What am I doing wrong?

Bart van Heukelom
  • 43,244
  • 59
  • 186
  • 301

1 Answers1

0

I don't see anything wrong in your launch script; perhaps there is an issue in your service implementation DeamonGameServer. Try replacing your class with a simple Daemon skeleton implementation and see what happens.

Also, note there is an open defect in jsrv : Jsvc does not exit when all non-daemon threads are dead.

David J. Liszewski
  • 10,959
  • 6
  • 44
  • 57
  • I don't think there's anything wrong with my app. `DaemonGameServer.start()` returns (I have a log statement at the end of it), but I'll check. – Bart van Heukelom Dec 21 '10 at 16:16
  • Hmm, I created the directory for the log files (it didn't exist yet) and suddenly now it works. Very strange, because it shouldn't have started the app if there was an error. Maybe I changed something else too. – Bart van Heukelom Dec 21 '10 at 16:25
  • Well, even though your answer wasn't the solution, here is an accept for the effort :) – Bart van Heukelom Dec 22 '10 at 10:08