project BLF > class TDaemon > method StartRun
Description
Start the right daemon processor.
Parameters
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
BLF
program code (program1/tdaemon.p)
assign vcCurrentDaemon = session:parameter
vcAction = "start":U /* Default */.
if num-entries(vcCurrentDaemon,"|":U) > 1
then do :
assign vcCurrentDaemon = entry(1,vcCurrentDaemon,"|":U)
vcAction = (if entry(2,vcCurrentDaemon,"|":U) = "stop":U
then "stop":U else "start":U).
end.
/* ================================================================= */
/* First, get the login information for this daemon */
/* ================================================================= */
<Q-21 run DaemonLoginInfo (all) (Read) (NoCache)
(input vcCurrentDaemon, (DaemonName)
output dataset tqDaemonLoginInfo) in BBaseDaemon >
find first tqDaemonLoginInfo no-error.
if NOT available tqDaemonLoginInfo
then do :
<M-20 run SetMessageInLog (input trim(#T-25'Cannot start: the daemon name is not supplied':120(75)T-25#) (icMessage),
output viFcReturnSuper (oiReturnStatus)) in TDaemon>
return.
end.
assign vcDaemonLogFile = (if available tqDaemonLoginInfo then tqDaemonLoginInfo.tcDaemonLogFile
else vcDaemonLogFile).
/* ================================================================= */
/* We need to start the session for this daemon */
/* ================================================================= */
<I-35 {tFcStartAndOpenInstance
&CLASS = "Session"
&SESSIONID = "viSession1ID"}>
if viSession1ID = ? or viSession1ID = 0
then do :
<M-15 run SetMessageInLog
(input substitute(trim(#T-26'Unable to start a session for the &1 daemon.':120(76)T-26#),vcCurrentDaemon ) (icMessage),
output viFcReturnSuper (oiReturnStatus)) in TDaemon>
return.
end.
/* Activate CTLOG - indicated in config file - WouAnt 15.07.2005 */
/* The config file is placed in same folder as server.xml */
/* the ctlog is placed in folder specified in config */
ASSIGN vcdaemonConfig = SEARCH (caps (vcCurrentDaemon) + ".config":U ).
IF vcDaemonConfig <> ?
THEN DO :
input stream sConfig from value(vcDaemonConfig).
repeat:
import stream sConfig unformatted vcLine.
if vcLine begins "DebugLevel=":U
then assign viDebugLevel = integer(substring(vcLine,LENGTH ("DebugLevel=":U,"CHARACTER":U) + 1,-1,"CHARACTER":U)) no-error.
/* backward compatibility */
else if vcLine begins "BLDebugLevel=":U
then assign viDebugLevel = integer(substring(vcLine,LENGTH ("BLDebugLevel=":U,"CHARACTER":U) + 1,-1,"CHARACTER":U)) no-error.
end.
input stream sConfig close.
<M-34 run SetDebugLevel (input viDebugLevel (iiDebugLevel)) in Session>
END.
ELSE DO :
/* Make the config file on the same place as the server.xml */
ASSIGN vcdaemonConfig = SEARCH ("server.xml":U).
IF vcdaemonConfig <> ?
THEN DO :
ASSIGN vcdaemonConfig = REPLACE (vcdaemonConfig,"server.xml":U,caps(vcCurrentDaemon) + ".config":U).
<M-55 run Main (input 0 (iiSessionId)) in TDaemonUtility>
<M-80 run CreateDaemonConfig
(input vcDaemonConfig (icFilename),
input 0 (iiDebugLevel),
input vcCurrentDaemon (icDaemonName)) in TDaemonUtility>
run gipr_DeleteProcedure in vhFcComponent.
delete procedure vhFcComponent.
END.
END.
/* XE ******************************************** Wouter */
/*Decode the password before using it*/
assign vhFcComponent = ?.
<M-32 run MainBlock
() in TCrypt>
assign vhCrypthandle = vhFcComponent.
<M-33 run DecryptString
(input tqDaemonLoginInfo.tcDaemonPassword (icInputString),
output vcDaemonPassword (ocOutputString),
output viFcReturnSuper (oiReturnStatus)) in TCrypt>
run gipr_DeleteProcedure in vhCrypthandle.
delete procedure vhCrypthandle.
/* Login with Daemon-User: called method contains a call towards Session.Login */
<M-22 run DaemonLogin
(input tqDaemonLoginInfo.tcDaemonLogin (icLogin),
input vcDaemonPassword (icPassword),
input '' (icExtra),
output viLocalReturnStatus (oiReturnStatus)) in TDaemon>
<I-7 {tFcCloseInstance
&CLASS = "Session"}>
if viLocalReturnStatus <> 0
then do:
assign oiReturnStatus = viLocalReturnStatus.
if oiReturnStatus < 0
then return.
end. /* if viLocalReturnStatus <> 0 */
/* ================================================================= */
/* Start the specific daemon processor component */
/* ================================================================= */
<M-8 run StartDaemonProcessor (input vcCurrentDaemon (icDaemonName),
output vhDaemonProcessor (ohDaemonProcessor),
output viFcReturnSuper (oiReturnStatus)) in TDaemon>
if viFcReturnSuper <> 0
then do:
<M-9 run SetMessageInLog
(input substitute(trim(#T-27'Cannot start the daemon processor for daemon &1 (return status: &2).':120(77)T-27#),vcCurrentDaemon,string(vifcreturnsuper) ) (icMessage),
output viFcReturnSuper (oiReturnStatus)) in TDaemon>
return.
end.
if vhDaemonProcessor = ?
then do:
<M-16 run SetMessageInLog
(input substitute(trim(#T-28'Cannot start the daemon processor for daemon &1 (unsupported type).':120(78)t-28#),vcCurrentDaemon) (icMessage),
output viFcReturnSuper (oiReturnStatus)) in TDaemon>
return.
end.
assign vhBBaseDaemonProcessorInst = vhDaemonProcessor.
/* ================================================================= */
/* Depending on the value of vcAction, start an instance of the */
/* daemon, or send a stop request. */
/* ================================================================= */
if vcAction = "start":U
then do :
/* ================================================================= */
/* Start a run of the daemon processor */
/* ================================================================= */
<M-10 run StartDaemonProcessorInstance
(output vcErrorMessage (ocErrorMessage),
input false (ilStop),
output viFcReturnSuper (oiReturnStatus)) in BBaseDaemonProcessor>
if viFcReturnSuper <> 0
then do:
<M-11 run SetMessageInLog
(input substitute(trim(#T-29'Cannot start the daemon processor for daemon &1 (return status: &2).':120(77)T-29#),vcCurrentDaemon,string(vifcreturnsuper) ) + chr(10) + vcErrorMessage (icMessage),
output viFcReturnSuper (oiReturnStatus)) in TDaemon>
return.
end.
end.
else do:
/* ================================================================= */
/* Send a stop request to the daemon */
/* ================================================================= */
<M-30 run SetDaemonStopping (output viFcReturnSuper (oiReturnStatus)) in BBaseDaemonProcessor>
if viFcReturnSuper <> 0
then do:
<M-31 run SetMessageInLog
(input substitute(trim(#T-30'Unable to set the &1 daemon to status Stopping (return status: &2).':120(4380)T-30#),vcCurrentDaemon,string(vifcreturnsuper) ) (icMessage),
output viFcReturnSuper (oiReturnStatus)) in TDaemon>
return.
end.
end.
<I-36 {tFcCloseAndStopInstance
&CLASS = "BBaseDaemonProcessor"}>
<I-13 {tFcStopInstance
&CLASS = "Session"
&SESSIONID = "viSession1ID"}>