# daemon-framework **Repository Path**: mirrors_gspandy/daemon-framework ## Basic Information - **Project Name**: daemon-framework - **Description**: Little framework to create Java programs that behave like Linux daemons - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-09-24 - **Last Updated**: 2025-12-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Taimos daemon-framework Little framework to create Java programs that behave like Linux daemons/Windows services. [![Build Status](https://travis-ci.org/taimos/daemon-framework.png)](https://travis-ci.org/taimos/daemon-framework) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/de.taimos/daemon-framework/badge.svg)](https://maven-badges.herokuapp.com/maven-central/de.taimos/daemon-framework) # Getting started There are some small steps to follow to create a Linux daemon with Java: 1. Implement your subclass of de.taimos.daemon.DaemonLifecycleAdapter 2. Call the DaemonStarter from your main method 3. Customize your init-script There are three different startup modes which can be specified with ``-DstartupMode=``: - start: intended for background daemons - run: intended for foreground daemons - dev: start in development mode The default mode is ``dev``. If you want to run the program in _production mode_ make sure you start it with ``-DstartupMode=start`` or ``-DstartupMode=run``. In start mode the console logging is disabled. In development mode the program's behavior will differ in some small points: - Logging uses console instead of syslog and logfile ## DaemonLifecycleAdapter ### void doStart() throws Exception This method is called to start your program. It must be non blocking. If this method throws any Exception the DaemonFramework stops execution of the daemon. ### void doStop() throws Exception This method is called on OS signal to stop your program. It must be non blocking. If this method throws any Exception the DaemonFramework stops execution of the daemon. ### started() This method is called when the daemon completed startup successfully. ### stopped() This method is called when the daemon completed shutdown successfully. Immediatly after this method _System.exit(0)_ is called. ### stopping() This method is called when the daemon received shutdown signal. ### aborting() This method is called when the daemon aborts execution. Immediatly after this method _System.exit(1)_ is called. ### signalUSR2() This method is called when the daemon received the OS signal __USR2__. You can do what you want within this method. ### exception(LifecyclePhase phase, Throwable exception) This method is called when an exception occurs in DaemonStarter. It provides the current phase and the thrown exception. ### Map loadProperties() This method is called to obtain the daemon properties. All properties provided in this map will be available via _System.getProperty_ later on. The properties found in _de.taimos.daemon.DaemonProperties_ are used by the daemon framework itself and should be filled. ## Call DaemonStarter In your _main_ method just call startDaemon to run the daemon framework. You have to provide a service name and an instance of your subclass of DaemonLifecycleAdapter; ``` DaemonStarter.startDaemon("my-service-name", new MyLifecycleAdapter()); ``` ## Customize init-script (Linux) You just have to create a copy of _initscript_ from the projects _linux_ folder and customize it. For basic usage it is enough to change the variables on top of the script ### progname The name of the daemon ### pidfile The name and location of the PID file. It defaults to /var/run/ ### RUNDIR The location of the daemon program. It defaults to /opt/ ### RUNUSER The user under which the daemon is run. The init script then calls java with ``su -c RUNUSER`` ### JAR_FILE The name of the jarfile as it is found in $RUNDIR. The script calls java -jar . ### JAVA_OPTS Some Java options like memory size etc. ## Customize service setup (Windows) You just have to create a copy of the contents of the _windows_ folder and customize it. For basic usage it is enough to change the variables on top of the script _install.bat_ and to rename the _service.exe_ file. set svcName=CloudConductor set svcFullName="CloudConductor Server" set svcDesc="Cinovo CloudConductor" set svcJAR=de.cinovo.cloudconductor.cloudconductor-server.jar set svcStarter=de.cinovo.cloudconductor.server.ServerStarter ### svcName The short name of the service (no spaces) ### svcFullName The full name of the service ### svcDesc The description of the service ### svcJAR The name of the jarfile as it is found in the installation folder. ### svcStarter The java main class to start the service