Write a pidfile for the Python services so we can manage them.

This commit is contained in:
Ryan Petrello 2014-08-13 10:06:22 -07:00
parent 765f32809d
commit dd178bb22e
2 changed files with 11 additions and 1 deletions

View File

@ -72,7 +72,7 @@ def configure_gunicorn():
worker_class ="sync"
debug = False
daemon = True
pidfile = "/tmp/gunicorn.pid"
pidfile = "/var/run/gunicorn.pid"
logfile = "/tmp/gunicorn.log"
"""
config = textwrap.dedent(config % args).lstrip()

View File

@ -16,7 +16,10 @@
import argparse
import atexit
import contextlib
import json
import functools
import logging
import os
import sys
@ -127,6 +130,13 @@ def daemonize(stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'):
os.dup2(stdout.fileno(), sys.stdout.fileno())
os.dup2(stderr.fileno(), sys.stderr.fileno())
# write a pidfile
pidfile = '/var/run/metadata.pid'
atexit.register(functools.partial(os.remove, pidfile))
pid = str(os.getpid())
with contextlib.closing(open(pidfile, 'w+')) as f:
f.write("%s\n" % pid)
def _fork():
try: