Shell – How to execute in background / return early

background-processjavanohupprocessshell

For reference, I'm using phpseclib to control a remote SSH server using the 'root' account.

I have to start/stop a java process which is ran in the background. Stopping works fine with killall java and this is all I need for now, although when I run the server, I'm using:

(cd ./serv/; nohup java -classpath bin:deps/poi.jar:deps/netty.jar:deps/mysql.jar:deps/slf4j.jar:deps/slf4j-nop.jar:deps/jython.jar:log4j-1.2.15.jar: server.Server &)

As you can see, I am using the & operator for the second command inside the brackets. The command would execute correctly though the page would keep loading waiting for a return value/exit code? And it would eventually use up all the memory on my webhost.

The answer was that you need to manually direct the output of nohup:

Edit: Answer!!

(cd ./serv/; java -classpath bin:deps/poi.jar:deps/netty.jar:deps/mysql.jar:deps/slf4j.jar:deps/slf4j-nop.jar:deps/jython.jar:log4j-1.2.15.jar: server.Server >/tmp/test.out 2>&1 &)

Thanks to Mikeserv for the help.

Best Answer

cd ./serv/; java -classpath bin:deps/poi.jar:deps/netty.jar:deps/mysql.jar:deps/slf4j.jar:deps/slf4j-nop.jar‌​:deps/jython.jar:log4j-1.2.15.jar: server.Server >/tmp/test.out 2>&1 &

Answer courtesy of @mikeserv, I'm posting it at the request of @Sebastian so that this gets removed from the unanswered queue (a year and a half later).