Java daemon under Linux: Choices?

2019-04-08 10:58发布

问题:

I have a console application (written in Java), which should run on a Linux machine until it is stopped.

Logging is done by the application itself.

The application needs to be stopped whenever a new version is available (i. e. I login, stop the application, copy the new JAR file, and then launch it again).

What are the options for implementing this, apart from those specified below?

Known ways to do it:

1) Tanuki service wrapper

2) nohup java -jar myapp-1.32.jar &

回答1:

Some modern Linux distributions have switched to upstart. That's a daeomon starting and stopping all the other services. I'd definitely look into that. Since it solves some tricky problems with production ready start scripts. The downside is that it has no java specific functionality.



回答2:

I use Java Service Wrapper, but you already mentioned it. I think it should suit your needs.

Apache Commons Daemon is also popular: http://commons.apache.org/daemon/, but I never used it.



回答3:

I'm using this startup script: http://shrubbery.homeip.net/c/display/W/Java+Daemon+Startup+Script

[Changed domain name - by wiki owner]



回答4:

There also the apache commons deamons http://commons.apache.org/proper/commons-daemon/jsvc.html

Jsvc is a set of libraries and applications for making Java applications run on UNIX more easily.

Jsvc allows the application (e.g. Tomcat) to perform some privileged operations as root (e.g. bind to a port < 1024), and then switch identity to a non-privileged user.