def cleanup(self, signum=0, frame=None, reloading=False): log.debug("SrvServer.cleanup()") self.cleaningUp = True for server in self.servers: try: server.shutdown() except: pass # clean up domains for those that have on_xend_stop if not reloading: xenddomain().cleanup_domains() self.running = False
def cleanup(self, signum = 0, frame = None, reloading = False): log.debug("SrvServer.cleanup()") self.cleaningUp = True for server in self.servers: try: server.shutdown() except: pass # clean up domains for those that have on_xend_stop if not reloading: xenddomain().cleanup_domains() self.running = False
def start(self, status): # Running the network script will spawn another process, which takes # the status fd with it unless we set FD_CLOEXEC. Failing to do this # causes the read in SrvDaemon to hang even when we have written here. if status: fcntl.fcntl(status, fcntl.F_SETFD, fcntl.FD_CLOEXEC) # Prepare to catch SIGTERM (received when 'xend stop' is executed) # and call each server's cleanup if possible signal.signal(signal.SIGTERM, self.cleanup) signal.signal(signal.SIGHUP, self.reloadConfig) while True: threads = [] for server in self.servers: if server.ready: continue thread = Thread(target=server.run, name=server.__class__.__name__) thread.setDaemon(True) thread.start() threads.append(thread) # check for when all threads have initialized themselves and then # close the status pipe retryCount = 0 threads_left = True while threads_left: threads_left = False for server in self.servers: if not server.ready: threads_left = True break if threads_left: time.sleep(.5) retryCount += 1 if retryCount > 60: for server in self.servers: if not server.ready: log.error("Server " + server.__class__.__name__ + " did not initialise!") break if status: status.write('0') status.close() status = None # auto start pools before domains are started try: XendCPUPool.autostart_pools() except Exception, e: log.exception("Failed while autostarting pools") # Reaching this point means we can auto start domains try: xenddomain().autostart_domains() except Exception, e: log.exception("Failed while autostarting domains")
def start(self, status): # Running the network script will spawn another process, which takes # the status fd with it unless we set FD_CLOEXEC. Failing to do this # causes the read in SrvDaemon to hang even when we have written here. if status: fcntl.fcntl(status, fcntl.F_SETFD, fcntl.FD_CLOEXEC) # Prepare to catch SIGTERM (received when 'xend stop' is executed) # and call each server's cleanup if possible signal.signal(signal.SIGTERM, self.cleanup) signal.signal(signal.SIGHUP, self.reloadConfig) while True: threads = [] for server in self.servers: if server.ready: continue thread = Thread(target=server.run, name=server.__class__.__name__) thread.setDaemon(True) thread.start() threads.append(thread) # check for when all threads have initialized themselves and then # close the status pipe retryCount = 0 threads_left = True while threads_left: threads_left = False for server in self.servers: if not server.ready: threads_left = True break if threads_left: time.sleep(.5) retryCount += 1 if retryCount > 60: for server in self.servers: if not server.ready: log.error("Server " + server.__class__.__name__ + " did not initialise!") break if status: status.write('0') status.close() status = None # Reaching this point means we can auto start domains try: xenddomain().autostart_domains() except Exception, e: log.exception("Failed while autostarting domains") # loop to keep main thread alive until it receives a SIGTERM self.running = True while self.running: time.sleep(100000000) if self.reloadingConfig: log.info("Restarting all XML-RPC and Xen-API servers...") self.cleaningUp = False self.reloadingConfig = False xoptions.set_config() self.servers = [] _loadConfig(self, self.root, True) else: break