Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to daemonize Java application on Linux [closed]

Tags:

java

linux

daemon

While I found this question being answered here on SW several times, I didn't find a concluding answer what is the best approach.

I'm not looking to use any external wrapper, as I found them launching the java process under a nice level lower then themselves which potentially lowers the performance, so it seems only the shell methods are left.

I so far found 3 different shell methods:

  • start-stop-daemon
  • RedHat daemon init.d function
  • nohup on start / disown after start

What you people are using, and can recommend as the most reliable method?

Thanks.

like image 753
SyBer Avatar asked Apr 27 '10 20:04

SyBer


3 Answers

While the standard answer to this seems to be jsvc, I have been using djb's daemon tools to be a great way to make anything into a daemon.

I have java, python and a few shell scripts all running as daemons, with a simple way to start/stop them and great logging.

I've used to run daemontools itself as root on initctl as originally designed, but after a few months I decided to run it manually, under a normal user, and using svscan-start for nicer logging.

like image 180
itsadok Avatar answered Nov 10 '22 02:11

itsadok


If I want to run an application in the background as a daemon, I do it like this:

nohup java -jar MyJar &

There's nothing particularly unreliable about it - nohup keeps it from receiving a SIGHUP when you disconnect, and & runs a process in the background.

Optionally, you can redirect the output to something other than nohup.out.

like image 37
danben Avatar answered Nov 10 '22 03:11

danben


Take a look at http://yajsw.sourceforge.net/. It's free and somewhat compatible reimplementation of TanukiSoftware Java Service Wrapper featuring free 64-bit support.

There is also a comparison table for YAJSW, JSW, ACD and L4J.

like image 24
Vadzim Avatar answered Nov 10 '22 02:11

Vadzim