How do I run a Java program as a daemon on Linux?

Nathan Meyers

A daemon usually means some service that is started up and run persistently when the system boots or enters a certain init state.

There are standard ways to start such daemons from scripts that are run at critical times in the system's lifecycle. Most Linux distributions use the SysV-style of managing system init state, meaning that products needing to run daemons can install scripts in a standard location (/etc/rc.d/init.d/ on Red Hat) that are run at the proper times.

Like any other daemon, a daemon written in Java could include a shell script installed in this directory that would launch the Java interpreter to run the daemon.

Red Hat and Red Hat-based distros include an RPM, sysvinit, that includes a short bit of documentation named sysvinitfiles. This document talks about the structure of such scripts, and you can always learn more by studying some of the scripts themselves. Note that the process of installing the scripts requires placing the script in the right directory and running the chkconfig utility to install symlinks to it from other directories that are read when the system changes init states.