|
SRJRCFrames v0.1.296 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object de.schwarzrot.app.support.AbstractService<ServiceConfig> de.schwarzrot.startup.ServiceManager
public class ServiceManager
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
.
ServiceDefinition
contains a valid
scriptPreStart
. If so, set the status to STARTING
, set
dtStarted
to current time and execute the scriptPreStart
. If
scriptPreStart
is empty or invalid, set status to STARTED
and
start the service.STARTING
, check whether dtStarted
plus
waitPreStart
is gone. If so, check whether a triggerfile is defined.
If so, check the existance of that file. If the file does not exists, means
the pre-start-script has failed. Set status to STOP_REQUESTED
. If the
triggerfile exists, set the status to STARTED
and start the serviceSTARTED
or RUNNING
, determine the pid for
the service. If pid is not 0, check whether the pid equals the stored pid. If
not, update the stored pid.dtStopped
to current time and
status to STOPPING
.STOPPING
, check whether dtStopped
plus
waitPostEnd
is gone. If so, set the status to STOPPED
and
check whether a scriptPostEnd
is defined and valid. If so, execute
it.
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.
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 |
---|
protected static final String PIDFILE_PROPERTY
Constructor Detail |
---|
public ServiceManager()
Method Detail |
---|
public String getApplicationName()
MainEntry
SystemDefault.applicationID
getApplicationName
in interface MainEntry<ServiceConfig>
getApplicationName
in class AbstractService<ServiceConfig>
public boolean isIdle()
Service
ServiceLauncher
to determine, whether it
should sleep between the calls to Service.run()
.
public void run()
public void setupLate()
Service
public void usage()
MainEntry
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)
protected Integer getMyProcessID()
protected void readMyProcessID()
protected void startService(ServiceDefinition sd)
protected void stopService(ServiceDefinition sd, boolean beSmart)
protected int validatePid(ServiceDefinition sd)
public static void main(String[] args)
|
SRJRCFrames v0.1.296 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |