import daemon import daemon.pidfile context = daemon.DaemonContext() context.stdin = sys.stdin context.stderr = open(args.logfile, 'a') context.stdout = open(args.logfile, 'a') context.files_preserve = [fh.stream] context.uid = pwd.getpwnam(args.username).pw_uid context.gid = pwd.getpwnam(args.groupname).pw_gid app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 app.config['CORS_HEADERS'] = 'Content-Type' Log.loadGwtSymbolMap() # There is a race condition here but it will do for us. if os.path.exists(args.pidfile): pid = open(args.pidfile).read() try: os.kill(int(pid), 0) print "svc is running -- not starting" sys.exit(-1) os._exit(-1) except: print "removing pidfile and starting" os.remove(args.pidfile) context.pidfile = daemon.pidfile.TimeoutPIDLockFile(args.pidfile) with context: print "Starting streaming server" startStreamingServer(port) else: with util.pidfile(args.pidfile): startStreamingServer(port)
print "svc is running -- not starting" sys.exit(-1) os._exit(-1) except: print "removing pidfile and starting" os.remove(args.pidfile) context.pidfile = daemon.pidfile.TimeoutPIDLockFile(args.pidfile) with context: proc = Process(target=PeerConnectionManager.start) proc.start() jobs.append(proc.pid) app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 app.config['CORS_HEADERS'] = 'Content-Type' Log.loadGwtSymbolMap() app.debug = True server = pywsgi.WSGIServer(('localhost', 8002), app) server.serve_forever() else: print "Starting federation service" with util.pidfile(pidfile): Log.configureLogging("federation") proc = Process(target=PeerConnectionManager.start) proc.start() jobs.append(proc.pid) app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 app.config['CORS_HEADERS'] = 'Content-Type' Log.loadGwtSymbolMap() app.debug = True server = pywsgi.WSGIServer(('localhost', 8002), app) server.serve_forever()