mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Added basic process monitoring and re-spawning for services.
git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@451 19e92222-5c0b-0410-8929-a290d50e31e9
This commit is contained in:
parent
0bd56fb47c
commit
125626f140
4 changed files with 63 additions and 2 deletions
|
@ -2,4 +2,4 @@
|
|||
* Single Service (SingleMongrel) object type implemented.
|
||||
* Updated Rakefile to reflect the new building steps.
|
||||
* Removed SendSignal, too hackish for my taste, replaced with complete FB solution.
|
||||
|
||||
* Added basic Process monitoring and re-spawning.
|
|
@ -93,7 +93,24 @@ namespace mongrel_service
|
|||
debug("single_onStart()")
|
||||
|
||||
do while (self.state = Running) or (self.state = Paused)
|
||||
sleep 100
|
||||
'# instead of sitting idle here, we must monitor the pid
|
||||
'# and re-spawn a new process if needed
|
||||
if not (Status(single_mongrel_ref->__child_pid) = ProcessStillActive) then
|
||||
'# check if we aren't terminating
|
||||
if (self.state = Running) or (self.state = Paused) then
|
||||
debug("child process terminated!, re-spawning a new one")
|
||||
|
||||
single_mongrel_ref->__child_pid = 0
|
||||
single_mongrel_ref->__child_pid = Spawn(self.commandline)
|
||||
|
||||
if (single_mongrel_ref->__child_pid > 0) then
|
||||
debug("new child process pid: " + str(single_mongrel_ref->__child_pid))
|
||||
end if
|
||||
end if
|
||||
end if
|
||||
|
||||
'# wait for 5 seconds
|
||||
sleep 5000
|
||||
loop
|
||||
|
||||
debug("single_onStart() done")
|
||||
|
|
|
@ -265,6 +265,39 @@ namespace process
|
|||
end function
|
||||
|
||||
|
||||
'# StillActive(PID) will return FALSE (0) in case the process no longer
|
||||
'# exist of get terminated with error.
|
||||
function Status(byval pid as uinteger) as ProcessStateEnum
|
||||
dim result as ProcessStateEnum
|
||||
dim exit_code as DWORD
|
||||
|
||||
'# process reference
|
||||
dim child as HANDLE
|
||||
|
||||
'# presume error?
|
||||
result = ProcessQueryError
|
||||
|
||||
'# is pid valid?
|
||||
if (pid > 0) then
|
||||
'# try getting a handler to the process
|
||||
child = OpenProcess(PROCESS_QUERY_INFORMATION or SYNCHRONIZE, FALSE, pid)
|
||||
if not (child = NULL) then
|
||||
'# the process reference is valid, get the exit_code
|
||||
if not (GetExitCodeProcess(child, @exit_code) = 0) then
|
||||
'# no error in the query, get result
|
||||
if (exit_code = STILL_ACTIVE) then
|
||||
result = ProcessStillActive
|
||||
end if '# (exit_code = STILL_ACTIVE)
|
||||
end if '# not (GetExitCodeProcess())
|
||||
|
||||
'# closes the process handle
|
||||
CloseHandle(child)
|
||||
end if '# not (child = NULL)
|
||||
end if '# (pid > 0)
|
||||
|
||||
return result
|
||||
end function
|
||||
|
||||
'# Special hook used to avoid the process calling Terminate()
|
||||
'# respond to CTRL_*_EVENTS when terminating child process
|
||||
private function _child_console_handler(byval dwCtrlType as DWORD) as BOOL
|
||||
|
|
|
@ -28,6 +28,13 @@ namespace process
|
|||
'# fb.process functions that allow creation/graceful termination
|
||||
'# of child process.
|
||||
|
||||
'# Process Status Enum
|
||||
enum ProcessStateEnum
|
||||
ProcessQueryError = 0
|
||||
ProcessStillActive = STILL_ACTIVE
|
||||
end enum
|
||||
|
||||
|
||||
'# Spawn(cmdline) will try to create a new process, monitor
|
||||
'# if it launched successfuly (5 seconds) and then return the
|
||||
'# new children PID (Process IDentification) or 0 in case of problems
|
||||
|
@ -38,6 +45,10 @@ namespace process
|
|||
'# in case of the first two fails.
|
||||
declare function Terminate(byval as uinteger) as BOOL
|
||||
|
||||
'# StillActive(PID) will return FALSE (0) in case the process no longer
|
||||
'# exist of get terminated with error.
|
||||
declare function Status(byval as uinteger) as ProcessStateEnum
|
||||
|
||||
'# Special hook used to avoid the process calling Terminate()
|
||||
'# respond to CTRL_*_EVENTS when terminating child process
|
||||
declare function _child_console_handler(byval as DWORD) as BOOL
|
||||
|
|
Loading…
Add table
Reference in a new issue