def reexec(self): """ Relaunch the master and workers. """ if self.pidfile is not None: self.pidfile.rename("%s.oldbin" % self.pidfile.fname) self.reexec_pid = os.fork() if self.reexec_pid != 0: self.master_name = "Old %s" % self.master_name _setproctitle(self.master_name) return os.chdir(self.START_CTX['cwd']) os.execvpe(self.START_CTX[0], self.START_CTX['args'], os.environ)
def start(self): # Initialize the arbiter, create pidfile if needed. self.set_process_owner(self.uid, self.gid) # setup logging self.file_logger = setup_file_logging("prefork", self.log_file) self.file_logger.info("Startting arbiter") self.file_logger.info('Use Config File %s', self.config_file) if self.daemonize: daemonize() _setproctitle(self.master_name) self.pid = os.getpid() self.file_logger.info("Master Pid --> %s" % self.pid) try: if self.pidfile: self.pidfile.create(self.pid) # chown(self.pidfile.fname, self.uid, self.gid) except Exception, e: self.file_logger.info(str(e))
def reload(self): self.file_logger.info("Reload config file:%s", self.cfg.ACTUAL_CONFIG_FILE) old_pidfile = self.pidfile self.cfg.load_config() self.setup() if old_pidfile and self.pidfile and old_pidfile.fname != self.pidfile.fname: #old_pidfile.unlink() self.file_logger.info("pidfile:%s", self.pidfile.fname) self.pidfile.rename(self.pid) self.set_process_owner(self.uid, self.gid) self.file_logger = setup_file_logging("prefork", self.log_file) _setproctitle(self.master_name) # start new workers for i in range(self.number_workers): self.spawn_worker() self.manage_workers()
def start(self): # Initialize the arbiter, create pidfile if needed. self.set_process_owner(self.uid, self.gid) # setup logging self.file_logger = setup_file_logging("prefork", self.log_file) self.file_logger.info("Startting arbiter") self.file_logger.info('Use Config File %s', self.config_file) if self.daemonize: daemonize() _setproctitle(self.master_name) self.pid = os.getpid() self.file_logger.info("Master Pid --> %s"%self.pid) try: if self.pidfile: self.pidfile.create(self.pid) # chown(self.pidfile.fname, self.uid, self.gid) except Exception,e: self.file_logger.info(str(e))
def init_process(self): self.setup() #set proc name _setproctitle(self.worker_name) self.init_signals() # bind ip and port if needed if not self.LISTENERS and (self.bind or self.unix_socket): self.file_logger.info("Listern on %s, unixdomian:%s", self.cfg.bind or "", self.cfg.unix_socket or "") self.LISTENERS = create_sockets(self.bind, self.unix_socket, self.SOCK_BACKLOG) if self.LISTENERS: for s in self.LISTENERS: close_on_exec(s) s.setblocking(0) self.rd_fds = list(self.LISTENERS) else: self.rd_fds = None # enter main loop self.booted = True