mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-30 13:37:55 +00:00
Better error messages on execution failure.
Environment cleanup. git-svn-id: svn://bind10.isc.org/svn/bind10/branches/f2f200910@259 e5f2f494-b856-4b98-b285-d166d9295462
This commit is contained in:
@@ -19,6 +19,8 @@ signal handling outside of that class, in the code running for
|
|||||||
__main__.
|
__main__.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# TODO: start up statistics thingy
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import signal
|
import signal
|
||||||
import os
|
import os
|
||||||
@@ -44,12 +46,14 @@ class ProcessInfo:
|
|||||||
dev_null = open("/dev/null", "w")
|
dev_null = open("/dev/null", "w")
|
||||||
|
|
||||||
def _spawn(self):
|
def _spawn(self):
|
||||||
|
spawn_env = self.env
|
||||||
|
spawn_env['PATH'] = os.environ['PATH']
|
||||||
self.process = subprocess.Popen(self.args,
|
self.process = subprocess.Popen(self.args,
|
||||||
stdin=subprocess.PIPE,
|
stdin=subprocess.PIPE,
|
||||||
stdout=self.dev_null,
|
stdout=self.dev_null,
|
||||||
stderr=self.dev_null,
|
stderr=self.dev_null,
|
||||||
close_fds=True,
|
close_fds=True,
|
||||||
env=self.env,)
|
env=spawn_env,)
|
||||||
self.pid = self.process.pid
|
self.pid = self.process.pid
|
||||||
|
|
||||||
def __init__(self, name, args, env={}):
|
def __init__(self, name, args, env={}):
|
||||||
@@ -86,12 +90,13 @@ class BoB:
|
|||||||
"""
|
"""
|
||||||
# start the c-channel daemon
|
# start the c-channel daemon
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
sys.stdout.write("Starting msgq using port %d\n" % self.c_channel_port)
|
sys.stdout.write("Starting msgq using port %d\n" %
|
||||||
|
self.c_channel_port)
|
||||||
c_channel_env = { "ISC_MSGQ_PORT": str(self.c_channel_port), }
|
c_channel_env = { "ISC_MSGQ_PORT": str(self.c_channel_port), }
|
||||||
try:
|
try:
|
||||||
c_channel = ProcessInfo("msgq", "msgq", c_channel_env)
|
c_channel = ProcessInfo("msgq", "msgq", c_channel_env)
|
||||||
except:
|
except Exception as e:
|
||||||
return "Unable to start msgq"
|
return "Unable to start msgq; " + str(e)
|
||||||
self.processes[c_channel.pid] = c_channel
|
self.processes[c_channel.pid] = c_channel
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
sys.stdout.write("Started msgq (PID %d)\n" % c_channel.pid)
|
sys.stdout.write("Started msgq (PID %d)\n" % c_channel.pid)
|
||||||
@@ -115,9 +120,9 @@ class BoB:
|
|||||||
sys.stdout.write("Starting bind-cfgd\n")
|
sys.stdout.write("Starting bind-cfgd\n")
|
||||||
try:
|
try:
|
||||||
bind_cfgd = ProcessInfo("bind-cfgd", "bind-cfgd")
|
bind_cfgd = ProcessInfo("bind-cfgd", "bind-cfgd")
|
||||||
except:
|
except Exception as e:
|
||||||
c_channel.process.kill()
|
c_channel.process.kill()
|
||||||
return "Unable to start bind-cfgd"
|
return "Unable to start bind-cfgd; " + str(e)
|
||||||
self.processes[bind_cfgd.pid] = bind_cfgd
|
self.processes[bind_cfgd.pid] = bind_cfgd
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
sys.stdout.write("Started bind-cfgd (PID %d)\n" % bind_cfgd.pid)
|
sys.stdout.write("Started bind-cfgd (PID %d)\n" % bind_cfgd.pid)
|
||||||
@@ -129,10 +134,10 @@ class BoB:
|
|||||||
sys.stdout.write("Starting parkinglot on port 5300\n")
|
sys.stdout.write("Starting parkinglot on port 5300\n")
|
||||||
try:
|
try:
|
||||||
parkinglot = ProcessInfo("parkinglot", ["parkinglot", "-p", "5300"])
|
parkinglot = ProcessInfo("parkinglot", ["parkinglot", "-p", "5300"])
|
||||||
except:
|
except Exception as e:
|
||||||
c_channel.kill()
|
c_channel.kill()
|
||||||
bind_cfgd.kill()
|
bind_cfgd.kill()
|
||||||
return "Unable to start parkinglot"
|
return "Unable to start parkinglot; " + str(e)
|
||||||
self.processes[parkinglot.pid] = parkinglot
|
self.processes[parkinglot.pid] = parkinglot
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
sys.stdout.write("Started parkinglot (PID %d)\n" % parkinglot.pid)
|
sys.stdout.write("Started parkinglot (PID %d)\n" % parkinglot.pid)
|
||||||
@@ -159,7 +164,8 @@ class BoB:
|
|||||||
self.stop_all_processes()
|
self.stop_all_processes()
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
time.sleep(0.1) # XXX: some delay probably useful... how much is uncertain
|
# XXX: some delay probably useful... how much is uncertain
|
||||||
|
time.sleep(0.1)
|
||||||
# next try sending a SIGTERM
|
# next try sending a SIGTERM
|
||||||
processes_to_stop = list(self.processes.values())
|
processes_to_stop = list(self.processes.values())
|
||||||
unstopped_processes = []
|
unstopped_processes = []
|
||||||
@@ -173,7 +179,8 @@ class BoB:
|
|||||||
# ignore these (usually ESRCH because the child
|
# ignore these (usually ESRCH because the child
|
||||||
# finally exited)
|
# finally exited)
|
||||||
pass
|
pass
|
||||||
time.sleep(0.1) # XXX: some delay probably useful... how much is uncertain
|
# XXX: some delay probably useful... how much is uncertain
|
||||||
|
time.sleep(0.1)
|
||||||
for proc_info in processes_to_stop:
|
for proc_info in processes_to_stop:
|
||||||
(pid, exit_status) = os.waitpid(proc_info.pid, os.WNOHANG)
|
(pid, exit_status) = os.waitpid(proc_info.pid, os.WNOHANG)
|
||||||
if pid == 0:
|
if pid == 0:
|
||||||
@@ -201,6 +208,9 @@ class BoB:
|
|||||||
Returns True if everything is okay, or False if a fatal error
|
Returns True if everything is okay, or False if a fatal error
|
||||||
has been detected and the program should exit.
|
has been detected and the program should exit.
|
||||||
"""
|
"""
|
||||||
|
if not pid in self.processes:
|
||||||
|
sys.stdout.write("Unknown child pid %d exited.\n" % pid)
|
||||||
|
return
|
||||||
proc_info = self.processes.pop(pid)
|
proc_info = self.processes.pop(pid)
|
||||||
self.dead_processes[proc_info.pid] = proc_info
|
self.dead_processes[proc_info.pid] = proc_info
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
@@ -219,8 +229,6 @@ class BoB:
|
|||||||
msg, data = self.cc_session.group_recvmsg(False)
|
msg, data = self.cc_session.group_recvmsg(False)
|
||||||
if msg is None:
|
if msg is None:
|
||||||
return
|
return
|
||||||
pprint.pprint(msg)
|
|
||||||
pprint.pprint(data)
|
|
||||||
msg_from = data.get('from', '')
|
msg_from = data.get('from', '')
|
||||||
if (type(msg) is dict) and (type(data) is dict):
|
if (type(msg) is dict) and (type(data) is dict):
|
||||||
if "command" in msg:
|
if "command" in msg:
|
||||||
|
Reference in New Issue
Block a user