org.onebusaway.cli
Class Daemonizer

java.lang.Object
  extended by org.onebusaway.cli.Daemonizer

public class Daemonizer
extends Object

Supports portable daemonization of a Java process. Uses the Sakuma wrapper of LIBC to perform daemonization, so will only work on systems that have LIBC. Works with the commons-cli command-line-interface argument parsing to define and process command line arguments defining daemonization parameters like a pid file, jvm args, and process output log files. See buildOptions(Options) and handleDaemonization(CommandLine) for convenience methods to perform daemonization.

Author:
bdferris

Constructor Summary
Daemonizer()
           
 
Method Summary
static org.apache.commons.cli.Options buildOptions(org.apache.commons.cli.Options options)
          Add common daemonization command line arguments to a commons-cli Options collection.
 void daemonize()
           
static boolean handleDaemonization(org.apache.commons.cli.CommandLine cli)
          Convenience method to handle daemonization of a command line Java program
 void setErrorFile(File errorFile)
           
 void setJvmArgs(Collection<String> jvmArgs)
           
 void setOutputFile(File outputFile)
           
 void setPidFile(File pidFile)
           
 void setWorkingDirectory(File workingDirectory)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Daemonizer

public Daemonizer()
Method Detail

buildOptions

public static org.apache.commons.cli.Options buildOptions(org.apache.commons.cli.Options options)
Add common daemonization command line arguments to a commons-cli Options collection.

Parameters:
options - we add command line options to this target options collection
Returns:
the same target options collection

handleDaemonization

public static boolean handleDaemonization(org.apache.commons.cli.CommandLine cli)
                                   throws Exception
Convenience method to handle daemonization of a command line Java program

Parameters:
cli - parsed command line option values
Returns:
true if daemonization was performed
Throws:
Exception

setOutputFile

public void setOutputFile(File outputFile)

setErrorFile

public void setErrorFile(File errorFile)

setPidFile

public void setPidFile(File pidFile)

setWorkingDirectory

public void setWorkingDirectory(File workingDirectory)

setJvmArgs

public void setJvmArgs(Collection<String> jvmArgs)

daemonize

public void daemonize()
               throws Exception
Throws:
Exception


Copyright © 2011 OneBusAway. All Rights Reserved.