当前位置: 首页>>代码示例>>Python>>正文


Python DaemonContext.stderr方法代码示例

本文整理汇总了Python中daemon.DaemonContext.stderr方法的典型用法代码示例。如果您正苦于以下问题:Python DaemonContext.stderr方法的具体用法?Python DaemonContext.stderr怎么用?Python DaemonContext.stderr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在daemon.DaemonContext的用法示例。


在下文中一共展示了DaemonContext.stderr方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: from daemon import DaemonContext [as 别名]
# 或者: from daemon.DaemonContext import stderr [as 别名]
 def run(self):
     logger.info("-- starting mandelbrot agent --")
     # execute any privileged subsystem code
     self.privilegedStartService()
     # set the process title
     setproctitle("mandelbrot-agent")
     # construct the daemon context
     daemon = DaemonContext()
     daemon.prevent_core = True
     daemon.chroot_directory = None
     daemon.working_directory = "/"
     if self.pidfile is not None:
         daemon.pidfile = TimeoutPIDLockFile(self.pidfile)
     if os.getuid() == 0:
         daemon.uid = self.uid
         daemon.gid = self.gid
     elif self.uid is not None or self.gid is not None:
         logger.warning("not dropping privileges, process uid is not 0")
     # FIXME: hack to ensure that fds stay open when passed to daemon context
     daemon.files_preserve = [x for x in xrange(64)]
     if self.foreground:
         daemon.detach_process = False
         daemon.stdin = sys.stdin
         daemon.stdout = sys.stdout
         daemon.stderr = sys.stderr
     else:
         daemon.detach_process = True
     with daemon:
         from twisted.internet import reactor
         self.startService()
         reactor.run()
         logger.info("-- stopping mandelbrot agent --")
         self.stopService()
     logger.info("-- stopped mandelbrot agent --")
     return 0
开发者ID:mikefort,项目名称:mandelbrot,代码行数:37,代码来源:agent.py

示例2: actionStartFCGI

# 需要导入模块: from daemon import DaemonContext [as 别名]
# 或者: from daemon.DaemonContext import stderr [as 别名]
    def actionStartFCGI(self):
        from flup.server.fcgi import WSGIServer
        from daemon import DaemonContext
        from lockfile import FileLock
        from os import getpid

        ctx = DaemonContext(working_directory=".", pidfile=FileLock("/tmp/wl-fcgi"))
        ctx.stderr = open("error.log", "w+")
        with ctx:
            open("wl-fcgi.pid", "w").write(str(getpid()))
            WSGIServer(app, bindAddress="fcgi.sock", umask=0000).run()
开发者ID:SpicyHorse,项目名称:delivery,代码行数:13,代码来源:manage.py

示例3: start_server

# 需要导入模块: from daemon import DaemonContext [as 别名]
# 或者: from daemon.DaemonContext import stderr [as 别名]
def start_server(config):
    weblogger = logging.getLogger('plight_httpd')
    weblogger.setLevel(config['web_log_level'])
    if weblogger.handlers == []:
        weblogging_handler = RotatingFileHandler(config['web_log_file'],
                                              mode='a',
                                              maxBytes=config['web_log_filesize'],
                                              backupCount=config['web_log_rotation_count'])
        weblogger.addHandler(weblogging_handler)

    applogger = logging.getLogger('plight')
    applogger.setLevel(config['log_level'])
    if applogger.handlers == []:
        applogging_handler = RotatingFileHandler(config['log_file'],
                                              mode='a',
                                              maxBytes=config['log_filesize'],
                                              backupCount=config['log_rotation_count'])
        applogger.addHandler(applogging_handler)

    pidfile = PIDLockFile(PID_FILE)
    context = DaemonContext(pidfile=pidfile,
                            uid=pwd.getpwnam(config['user']).pw_uid,
                            gid=grp.getgrnam(config['group']).gr_gid,
                            files_preserve = [
                                weblogging_handler.stream,
                                applogging_handler.stream,
                            ],)
    context.stdout = applogging_handler.stream
    context.stderr = applogging_handler.stream
    context.open()
    os.umask(0022)

    try:
        try:
            log_message('Plight is starting...')
            node_status = plight.NodeStatus(config['state_file'])
            server_class = BaseHTTPServer.HTTPServer
            http = server_class((config['host'],
                                 config['port']),
                                 plight.StatusHTTPRequestHandler)
            http.serve_forever()
        except SystemExit, sysexit:
            log_message("Stopping... " + str(sysexit))
        except Exception, ex:
            log_message("ERROR: " + str(ex))
开发者ID:nickbales,项目名称:plight,代码行数:47,代码来源:util.py

示例4: handle_daemon

# 需要导入模块: from daemon import DaemonContext [as 别名]
# 或者: from daemon.DaemonContext import stderr [as 别名]
    def handle_daemon(self, name, daemon):
        """
        Executes the daemon command.

        :param str name: The name of the daemon.
        :param * daemon: The daemon, i.e. object with main method.
        """
        self.output = EnarkshStyle(self.input, self.output)

        log = logging.getLogger('enarksh')
        log.setLevel(logging.INFO)
        log_formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')

        if self.option('daemonize'):
            config = Config.get()

            log_file_name = os.path.join(C.HOME, config.get_enarksh_log_dir(), name + '.log')
            pid_file_name = os.path.join(C.HOME, config.get_enarksh_lock_dir(), name + '.pid')

            log_handler = logging.handlers.RotatingFileHandler(log_file_name,
                                                               maxBytes=config.get_enarksh_max_log_size(),
                                                               backupCount=config.get_enarksh_log_back())
            log_handler.setLevel(logging.DEBUG)
            log_handler.setFormatter(log_formatter)
            log.addHandler(log_handler)

            output = open(log_file_name, 'ab', 0)

            context = DaemonContext()
            context.working_directory = C.HOME
            context.umask = 0o002
            context.pidfile = PIDLockFile(pid_file_name, False)
            context.stdout = output
            context.stderr = output
            context.files_preserve = [log_handler.stream]

            with context:
                daemon.main()
        else:
            log_handler = logging.StreamHandler(sys.stdout)
            log_handler.setLevel(logging.DEBUG)
            log_handler.setFormatter(log_formatter)
            log.addHandler(log_handler)

            daemon.main()
开发者ID:SetBased,项目名称:py-enarksh,代码行数:47,代码来源:DaemonCommand.py

示例5: start

# 需要导入模块: from daemon import DaemonContext [as 别名]
# 或者: from daemon.DaemonContext import stderr [as 别名]
def start(**keywords):
    args = {}
    args.update(
        dev_install = False,
        mark_read = None,
        debug_level = None,
        )
    args.update(keywords)
    try:
        config = democraticd.config.Config(
            dev_install = args['dev_install'],
            debug_level = args['debug_level'],
            mark_read = args['mark_read'],
            )
    except:
        args['dev_install'] = not args['dev_install']
        config = democraticd.config.Config(
            dev_install = args['dev_install'],
            debug_level = args['debug_level'],
            mark_read = args['mark_read'],
            )            
    del args['dev_install']
    del args['debug_level']
    del args['mark_read']
    
    log_file = open(config.log_filename, 'wt+')
    
    context = DaemonContext()
    context.uid = config.uid
    context.gid = config.gid
    context.stdout = log_file
    context.stderr = log_file

    print('Starting daemon, logging to ' + config.log_filename)
    with context:
        DemocraticDaemon(config, **args).start()
开发者ID:democraticd,项目名称:democraticd,代码行数:38,代码来源:server.py


注:本文中的daemon.DaemonContext.stderr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。