Esempio n. 1
0
def start_proc_manager(config, logfile):
    from pycopia import asyncio
    pm = proctools.get_procmanager()
    libexec = config.get("LIBEXEC", "/usr/libexec/pycopia")

    for name, serverlist in list(config.VHOSTS.items()):
        for servername in serverlist:
            logging.info("Starting {} for vhost {}.".format(servername, name))
            cmd = "{}/scgi_server -n {}".format(libexec, servername)
            p = pm.spawnprocess(
                ServerProcess, cmd, persistent=True, logfile=logfile)
            asyncio.poller.register(p)
    if config.USEFRONTEND:
        if asyncio.poller:
            pm.spawnpipe("{} -D -f {}".format(LIGHTTPD, LTCONFIG),
                         persistent=True, logfile=logfile)
        else:  # no servers, just run frontend alone
            pm.spawnpipe("{} -f {}".format(LIGHTTPD, LTCONFIG))
    try:
        asyncio.poller.loop()
        logging.info("No servers, exited loop.")
    except KeyboardInterrupt:
        pass
    if asyncio.poller:
        asyncio.poller.unregister_all()
        for proc in pm.getprocs():
            proc.killwait()
    if os.path.exists(config.PIDFILE):
        os.unlink(config.PIDFILE)
Esempio n. 2
0
 def respawn_callback(self, deadproc):
     """Callback that performs a respawn, for persistent services."""
     if deadproc.exitstatus.status == 127:
         logging.error("process {!r} didn't start (NOT restarting).\n".format(  # noqa
             deadproc.cmdline))
         raise ProcessError("Process never started. Check command line.")
     elif not deadproc.exitstatus:
         logging.error("process {!r} died: %s (restarting in 1 sec.).\n".format(  # noqa
                      deadproc.cmdline, deadproc.exitstatus))
         scheduler.add(self._respawn, 1.0, args=(deadproc,))
     else:
         logging.info("process {!r} normal exit (NOT restarting).\n".format(
                 deadproc.cmdline))
     return None
Esempio n. 3
0
 def respawn_callback(self, deadproc):
     """Callback that performs a respawn, for persistent services."""
     if deadproc.exitstatus.status == 127:
         logging.error(
             "process {!r} didn't start (NOT restarting).\n".format(  # noqa
                 deadproc.cmdline))
         raise ProcessError("Process never started. Check command line.")
     elif not deadproc.exitstatus:
         logging.error("process {!r} died: %s (restarting in 1 sec.).\n".
                       format(  # noqa
                           deadproc.cmdline, deadproc.exitstatus))
         scheduler.add(self._respawn, 1.0, args=(deadproc, ))
     else:
         logging.info("process {!r} normal exit (NOT restarting).\n".format(
             deadproc.cmdline))
     return None
Esempio n. 4
0
 def get_logfile(self):
     from pycopia import logfile
     if self._cache._logfile is None:
         logfilename = self.get_logfilename()
         try:
             lf = logfile.ManagedLog(logfilename, self.get("logfilesize", 1000000))
             if self.flags.VERBOSE:
                 logging.info("Logging to: {}".format(logfilename))
         except:
             logging.exception_warning("get_logfile: Could not open log file")
             self._cache._logfile = None
             return None
         else:
             self._cache._logfile = lf
             return lf
     else:
         return self._cache._logfile
Esempio n. 5
0
 def get_logfile(self):
     from pycopia import logfile
     if self._cache._logfile is None:
         logfilename = self.get_logfilename()
         try:
             lf = logfile.ManagedLog(logfilename,
                                     self.get("logfilesize", 1000000))
             if self.flags.VERBOSE:
                 logging.info("Logging to: {}".format(logfilename))
         except:
             logging.exception_warning(
                 "get_logfile: Could not open log file")
             self._cache._logfile = None
             return None
         else:
             self._cache._logfile = lf
             return lf
     else:
         return self._cache._logfile
Esempio n. 6
0
 def hangup_handler(self):
     logging.info("Hangup: {}.\n".format(self.cmdline))
Esempio n. 7
0
 def hangup_handler(self):
     logging.info("Hangup: {}.\n".format(self.cmdline))