本文整理汇总了Python中daemon.DaemonContext.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python DaemonContext.__init__方法的具体用法?Python DaemonContext.__init__怎么用?Python DaemonContext.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类daemon.DaemonContext
的用法示例。
在下文中一共展示了DaemonContext.__init__方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from daemon import DaemonContext [as 别名]
# 或者: from daemon.DaemonContext import __init__ [as 别名]
def __init__(self, redirect_output = '/tmp/ocsp_responder.log',
chroot = None,
detach = True,
pidfile = '/tmp/ocsp_responder.pid'):
self.redirect_output = file(redirect_output, 'a')
self.chroot = chroot
self.detach = detach
self.pidfile = pidfile
if self.pidfile:
self.pidfile = LockFile(pidfile)
if not self.detach:
self.redirect_output = sys.stdout
DaemonContext.__init__(self,
stdout = self.redirect_output,
stderr = self.redirect_output,
detach_process = self.detach,
pidfile = self.pidfile)
示例2: __init__
# 需要导入模块: from daemon import DaemonContext [as 别名]
# 或者: from daemon.DaemonContext import __init__ [as 别名]
def __init__(self, args=None):
# Parse args
if args is None:
args = {}
options, _ = getopt.getopt(sys.argv[1:], 'c:d')
options = dict(options)
config_file = options.get('-c', '/usr/local/etc/rpcdaemon.conf')
daemonize = '-d' not in options
# Parse config
self.config = Config(config_file, 'Daemon')
# Initialize logger
self.logger = Logger(
name='rpcdaemon',
level = self.config['loglevel'],
path = self.config['logfile'] if daemonize else None,
handler = None if daemonize else logging.StreamHandler()
)
self.pidfile = PIDFile(self.config['pidfile']) if daemonize else None;
# TOOD: plugin.check thread pool?
self.timeout = int(self.config.get('check_interval', 1))
# Clamp in case we exit before worker exists
self.worker = None
# Initialize daemon
DaemonContext.__init__(
self,
detach_process=daemonize,
files_preserve=[self.logger.handler.stream.fileno()],
pidfile=self.pidfile,
stdout=self.logger.handler.stream,
stderr=self.logger.handler.stream
)
示例3: __init__
# 需要导入模块: from daemon import DaemonContext [as 别名]
# 或者: from daemon.DaemonContext import __init__ [as 别名]
def __init__( self, pidfile, **kwargs ):
argv = list(sys.argv)
filename = self.filename = os.path.abspath( argv.pop(0) )
path = os.path.dirname(filename)
kwargs.setdefault( 'working_directory', path )
if isinstance( pidfile, basestring ):
if pidfile[0] != '/':
pidfile = '%s/%s' % (path, pidfile )
pidfile = PIDLockFile( pidfile )
if argv:
cmd = argv.pop(0)
if cmd=='stop':
self._stop( pidfile )
sys.exit(0)
elif cmd=='restart':
self._stop( pidfile )
c = 10
while pidfile.is_locked():
c-=1
gevent.sleep(1)
if not c:
raise Exception('Cannot stop daemon (Timed out)')
# should just work without this - but it does not :/
cmd = [sys.executable, filename]+argv
cmd.append('&')
os.system( ' '.join(cmd) )
exit(0)
"""
elif cmd!='start':
sys.stderr.write('try %s %s start|stop|restart\r\n' % (sys.executable, sys.argv[0]))
exit(0)
"""
if pidfile.is_locked():
sys.stderr.write( 'Daemon seems to be already running\r\n' )
sys.exit(-1)
self.exit_hooks = kwargs.pop('exit_hooks',[])
files_preserve = kwargs.pop('files_preserve',[])
stderr = kwargs.get('stderr')
if stderr:
files_preserve.append( stderr )
for logger in kwargs.pop('loggers',()):
for handler in logger.handlers:
if hasattr( handler, 'stream' ):
files_preserve.append( handler.stream )
self.loggers = []
filename = os.path.basename( self.filename)
try:
from setproctitle import setproctitle
setproctitle( filename )
except ImportError:
import ctypes
try:
libc = ctypes.CDLL("libc.so.6")
libc.prctl(15, filename, 0, 0, 0)
except:
pass
_DaemonContext.__init__( self, pidfile=pidfile, files_preserve=files_preserve, **kwargs )