SRJRCFrames
v0.1.296

de.schwarzrot.startup
Class ServiceManager

java.lang.Object
  extended by de.schwarzrot.app.support.AbstractService<ServiceConfig>
      extended by de.schwarzrot.startup.ServiceManager
All Implemented Interfaces:
MainEntry<ServiceConfig>, Service<ServiceConfig>, UserNameProvider, Runnable

public class ServiceManager
extends AbstractService<ServiceConfig>

a manager class used to start and stop other services remotely. Services that should be managed must have a valid database entry, so this manager class works together with a database.

The ServiceDefinition includes 2 script filenames and a trigger filename. The preStart-script will be executed before starting the service. That script can be used to vomit a wakeonlan package or something like that. The waitPreStart-time is the time, the ServiceManager waits after executing the pre-start-script, before really starting the service. That time can be set to reflect the boot-time of the dynamically started machine.

The triggerfile can be used to give a feedback from the pre-start-script to the ServiceManager. If a triggerfile is defined, the service will only be startet, if that file exists. Both, the pre-start-script and the post-end-script get the absolute path of the triggerfile as second parameter, so there's no need to hardcode it in the scripts.

The first parameter of the scripts will be "start" or "stop", depending on whether the script is defined as pre-start-script or as post-end-script. This way it is possible to use the same script for both actions.

The post-end-script is the counterpart of the pre-start-script and may be used to trigger a shutdown of the dynamically started machine. The waitPostEnd-time is the time, the ServiceManager waits after stopping the service, before it executes the post-end-script. The script gets the absolute path of the triggerfile, so it can remove it for cleanup.

Lifecycle of a service:
Initial status of a service is STOPPED and pid is 0. At user-request status is set to START_REQUESTED.

The starter setup ensures the cyclic performing of the workloop, as well as the relaxed sleeping in between.

The ServiceManager will be started by a shellscript wrapper usually in root-mode, so it is able to start the other services with the userid defined at the services database entry.

Author:
Reinhard Mantey

Field Summary
protected static String PIDFILE_PROPERTY
           
 
Constructor Summary
ServiceManager()
           
 
Method Summary
protected  void checkRunningService(ServiceDefinition sd)
           
protected  void doAutoStart(ServiceDefinition sd)
           
protected  void doServiceStarted(ServiceDefinition sd)
           
protected  void doServiceStarting(ServiceDefinition sd)
           
protected  void doServiceStopping(ServiceDefinition sd)
           
protected  void doStartRequested(ServiceDefinition sd)
           
protected  void doStopRequested(ServiceDefinition sd)
           
protected  void executeScript(ServiceDefinition sd, boolean startScript)
           
 String getApplicationName()
          print the application name - may be localized.
protected  Integer getMyProcessID()
           
 boolean isIdle()
          will be used by the ServiceLauncher to determine, whether it should sleep between the calls to Service.run().
static void main(String[] args)
           
protected  void readMyProcessID()
           
 void run()
           
 void setupLate()
          second stage of initialization.
protected  void startService(ServiceDefinition sd)
           
protected  void stopService(ServiceDefinition sd, boolean beSmart)
           
 void usage()
          tell the user about the right usage
protected  int validatePid(ServiceDefinition sd)
           
 
Methods inherited from class de.schwarzrot.app.support.AbstractService
getAppArgs, getAppInfo, getAppInfo, getApplicationDefaults, getConfig, getLogger, getUserName, isShutdownRequested, setAppArgs, setConfig, setShutdownRequested, setupEarly
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PIDFILE_PROPERTY

protected static final String PIDFILE_PROPERTY
See Also:
Constant Field Values
Constructor Detail

ServiceManager

public ServiceManager()
Method Detail

getApplicationName

public String getApplicationName()
Description copied from interface: MainEntry
print the application name - may be localized. For identifying purpose consider using SystemDefault.applicationID

Specified by:
getApplicationName in interface MainEntry<ServiceConfig>
Overrides:
getApplicationName in class AbstractService<ServiceConfig>
Returns:
- the applications name

isIdle

public boolean isIdle()
Description copied from interface: Service
will be used by the ServiceLauncher to determine, whether it should sleep between the calls to Service.run().

Returns:
true if the Service was idle, otherwise false

run

public void run()

setupLate

public void setupLate()
Description copied from interface: Service
second stage of initialization. Will be called after loading all referenced external jars, right before starting the service loop.


usage

public void usage()
Description copied from interface: MainEntry
tell the user about the right usage


checkRunningService

protected void checkRunningService(ServiceDefinition sd)

doAutoStart

protected void doAutoStart(ServiceDefinition sd)

doServiceStarted

protected void doServiceStarted(ServiceDefinition sd)

doServiceStarting

protected void doServiceStarting(ServiceDefinition sd)

doServiceStopping

protected void doServiceStopping(ServiceDefinition sd)

doStartRequested

protected void doStartRequested(ServiceDefinition sd)

doStopRequested

protected void doStopRequested(ServiceDefinition sd)

executeScript

protected void executeScript(ServiceDefinition sd,
                             boolean startScript)

getMyProcessID

protected Integer getMyProcessID()

readMyProcessID

protected void readMyProcessID()

startService

protected void startService(ServiceDefinition sd)

stopService

protected void stopService(ServiceDefinition sd,
                           boolean beSmart)

validatePid

protected int validatePid(ServiceDefinition sd)

main

public static void main(String[] args)

SRJRCFrames
v0.1.296

hosted at
Find SRJRCFrames at SourceForge.net. Fast, secure and free:
           Open Source Software download
Submit a bug or request a feature

SRJRCFrames is published according to the GNU General Public License
Copyright 2005-2012 Reinhard Mantey - some rights reserved.