原地址:http://www.9miao.com/question-15-53966.html
最近看源码,查了半天,没找到已守护进程方式启动firefly的方法,自己改了改写了一个,废话不多说直接上代码。
startmaster.py 修改后的代码
#coding:utf8
import os
import sys
from twisted.python import log
class Launcher:
def __init__(self):
self.serverInit()
self.daemonize()
self.startServer()
def daemonize(self):
try:
pid = os.fork()
if pid > 0:
sys.exit(0)
except OSError,e:
log.msg("Fork 1 has failed --> %d--[%s]\n" % (e.errno,e.strerror))
sys.exit(1)
os.setsid()
try:
pid = os.fork()
if pid > 0:
log.msg("Daemon process pid %d" % pid)
sys.exit(0)
except OSError, e:
log.msg("Fork 2 has failed --> %d--[%s]" % (e.errno, e.strerror))
sys.exit(1)
def serverInit(self):
if os.name!='nt' and os.name!='posix':
from twisted.internet import epollreactor
epollreactor.install()
def startServer(self):
from firefly.master.master import Master
master = Master()
master.config('config.json','appmain.py')
master.start()
if __name__=="__main__":
Launcher()
~
复制代码