Tuesday, April 21, 2015

Create daemon in Java

This can be a windows service or a unix daemon. The implementation might be different depending on platform. So I'm starting to do some research.


1. Apache Commons Daemon [1]

Apache Commons Daemon is a good alternative. It has Procrun [2] for windows services, and Jsvc [3] for unix daemons. It uses less restrictive Apache license, and Apache Tomcat uses it as a part of itself to run on Windows and Linux! To get it work is a bit tricky, but there is an exhaustive article [4] with working example. With Apache Commons Daemon you can now have a custom executable name and icon! You can also get a custom Windows tray monitor with your own name and icon!

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.It can run on Win32 via the Cygwin emulation layer, however Win32 users may prefer to use procrun instead.

Procrun is a set of applications that allow Windows users to wrap (mostly) Java applications (e.g. Tomcat) as a Windows service. The service can be set to automatically start when the machine boots and will continue to run with no user logged onto the machine.


2. Java Service Wrapper (JSW) [download]

See short introduction in [5]. Also an implementation of it: YAJSW - Yet Another Java Service Wrapper [6]. Cons (?): community version cannot be run on a server.


References:

[1] http://commons.apache.org/daemon/
[2] http://commons.apache.org/daemon/procrun.html
[3] http://commons.apache.org/daemon/jsvc.html
[4] Java as Windows Service with Apache Commons Daemon
[5] Running Java Applications as a Windows Service
[6] YAJSW - Yet Another Java Service Wrapper 
[7] http://stackoverflow.com/questions/68113/how-to-create-a-windows-service-from-java-app
[8] Creating a Java Daemon (System Service) for Debian using Apache Commons Jsvc


No comments:

Blog Archive

Followers