问题
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.
回答1:
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.
回答2:
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
.
回答3:
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.
回答4:
I would use the RedHat daemon init.d function. This allows you to have the application restart when the server does. Running nohup doesn't handle server restarts, etc.
回答5:
I wouldn't rule out the external wrappers completely.
I have noticed some well respected software using the Tanuki Wrapper http://wrapper.tanukisoftware.org/.
This has the added advantage that the program can also be easily run as a windows service, with a consistent approach.
回答6:
I've used Akuma in the past, with great success. The fact that it's a Java library really makes things easier, embedding the functionality is trivial.
回答7:
You could try using screen
(Launch screen, then launch the java program, then close[not quit] the screen)
来源:https://stackoverflow.com/questions/2724725/best-way-to-daemonize-java-application-on-linux