-
Notifications
You must be signed in to change notification settings - Fork 15
Implementing
Here is what you need to know to create daemon and daemon controller classes for your application.
The daemon class, which implements IDaemon, implements the methods which will start the daemon, handle commands, and shut down the daemon.
The daemon controller class, which extends DaemonController, handles command line arguments and is generally where you will put the main
method that is the entry point for your daemon.
The ExampleDaemon implementation should serve as a useful guide for your own daemon and daemon controller classes.
One useful thing you can do when you define your daemon controller class is to choose a different filename for the stdout log. To do this, override the getStdoutLogFileName()
method in the DaemonController.Options
class:
private static class Options extends DaemonController.Options {
@Override
public String getStdoutLogFileName() {
String logFileName = super.getStdoutLogFileName();
if (logFileName == null) {
logFileName = "logs/stdout.log";
}
return logFileName;
}
}
@Override
protected org.cloudcoder.daemon.DaemonController.Options createOptions() {
return new Options();
}
In the code above, the default stdout log file name is changed to logs/stdout.log
.
Some things to note:
- The pid file and the FIFO used to control the running daemon will
be created in the current directory (the directory the entry point
main
method is started from). - Each running daemon process will have an "instance name". A default instance name is used if none is provided when the daemon is started. You can run many daemon processes from the same codebase in the same directory as long as they all have different instance names.