def gunicorn(ec):
cmd = [
"%s/env/bin/gunicorn" % PROJECT_PATH,
"--chdir",
APP_PATH,
"api:application",
"--worker-class",
ec.gunicorn_worker_type,
"-b",
ec.gunicorn_bind,
"--log-level",
ec.logging_level.lower(),
"-w",
"%s" % ec.gunicorn_workers,
"-c",
gunicorn_conf.__file__
]
if not os.getenv('prometheus_multiproc_dir', None):
os.environ["prometheus_multiproc_dir"] = ec.prometheus_multiproc_dir
fs_gunicorn_cleaning()
p = multiprocessing.Process(target=lambda: os.execve(cmd[0], cmd, os.environ))
def stop(signum, frame):
print("terminating %d" % p.pid)
p.terminate()
print("starting gunicorn: %s" % " ".join(cmd))
p.start()
with open(ec.gunicorn_pid_file, "w") as f:
f.write("%d" % p.pid)
for sig in [signal.SIGINT, signal.SIGTERM]:
signal.signal(sig, stop)
p.join()
fs_gunicorn_cleaning()
评论列表
文章目录