Is it possible to start up a daemon from java. Specifically, I am trying to use MongoDB in java however I want my application to start up the mongod daemon if it not already running. I seem to be able to start it ok, exitcode is 0. However it always exits immediately. Is it possible to force it to stay running, then quit it with proc.destroy()?
ProcessBuilder pb = new ProcessBuilder("./bin/mongod","--dbpath data/db"); Process proc = pb.start();
If i set a breakpoint after i start the process the hasExisted boolean is always true, the exit code is 0 and I cannot connect to.
Also this is on OS X 10.5, I know ProcessBuilder is finicky across OS
./mongod --dbpath data/dbdoesn't start mongodb in the daemon mode. you have to use./mongod --fork --dbpath data/db --logpath /var/log/mongodb.log --logappendfor starting it as a daemon. If not started as daemon, you have to handle the stdin/stdout/stderr yourself for a process started withProcessBuilder.start