Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Just a tiny bit of cleanup #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/inworldz/maestro/GridServices.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,11 @@ def Start(self, restart=False, delay=60):
def Terminate(self):
self.shouldBeRunning = False

""" Shutdown the region after sending an Alert and delaying for a specified interval """
""" Shutdown the service immediately but safely. """
p = provision._findServiceProcess(self.exe_name)
if (p == None):
return (True)
p.terminate()
p = provision._findServiceProcess(self.exe_name)
return (p == None)
return inworldz.util.process.TerminateAndWaitForConfirmation(p, 30)


def ConsoleCommand(self, command):
Expand Down
16 changes: 7 additions & 9 deletions src/inworldz/maestro/Region.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,14 +439,13 @@ def Start(self, restart=False, delay=60):
""" Requests a start/restart of the managed sim node with an alert and a delay.
If restart is False nothing is done if we are already running. If True and the
region is running an alert is sent and the region restarted after the delay. """
p = provision._findRegionProcess(self.slot_number)
if p != None:
if self.IsRunning():
if (restart == False):
return (True)
else:
self.Shutdown(delay)

"""" Make sure there is a region config here... """
# TODO: Make sure there is a region config here...

bindir = os.path.join(self.slot_directory, "bin")
exename = os.path.join(bindir, self.exe_name)
Expand All @@ -460,13 +459,12 @@ def Start(self, restart=False, delay=60):
return False

def Terminate(self):
""" Shutdown the region after sending an Alert and delaying for a specified interval """
""" Shutdown the region immediately but safely. """
p = provision._findRegionProcess(self.slot_number)
if (p == None):
return (True)
p.terminate()

if inworldz.util.process.WaitForProcessTermination(p, 30):
if p == None:
return True

if inworldz.util.process.TerminateAndWaitForConfirmation(p, 30):
self.ChangeState(RegionState.DeployedStopped)
return True
else:
Expand Down
4 changes: 4 additions & 0 deletions src/inworldz/util/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def WaitForProcessTermination(process, timeout):
else:
return True

def TerminateAndWaitForConfirmation(process, timeout):
process.terminate() # This sends CTRL-C, which will cause an immediate shutdown.
return WaitForProcessTermination(process, timeout)

def DumpThreadStacks(pid):
sddir = os.path.dirname(sys.argv[0])
p = psutil.Popen([os.path.join(sddir, "stackdump.exe"), str(pid)],
Expand Down