add umask option

This commit is contained in:
benoitc 2010-02-15 11:30:15 +01:00
parent 2d760e492d
commit 07d252eb4d
2 changed files with 25 additions and 11 deletions

View File

@ -34,6 +34,8 @@ def options():
help='set the background PID FILE'),
op.make_option('-D', '--daemon', dest='daemon', action="store_true",
help='Run daemonized in the background.'),
op.make_option('-m', '--umask', dest="umask", type='int',
help="Define umask of daemon process"),
op.make_option('--log-level', dest='loglevel', default='info',
help='Log level below which to silence messages. [%default]'),
op.make_option('--log-file', dest='logfile', default='-',
@ -57,12 +59,12 @@ def configure_logging(opts):
h.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s %(message)s"))
logger.addHandler(h)
def daemonize():
def daemonize(umask):
if not 'GUNICORN_FD' in os.environ:
if os.fork() == 0:
os.setsid()
if os.fork() == 0:
os.umask(UMASK)
os.umask(umask)
else:
os._exit(0)
else:
@ -107,6 +109,8 @@ def main(usage, get_app):
port = 8000
addr = (host, port)
umask = int(opts.umask or UMASK)
kwargs = dict(
debug=opts.debug,
pidfile=opts.pidfile
@ -114,7 +118,7 @@ def main(usage, get_app):
arbiter = Arbiter(addr, workers, app, **kwargs)
if opts.daemon:
daemonize()
daemonize(umask)
else:
os.setpgrp()
configure_logging(opts)
@ -146,6 +150,10 @@ def paste_server(app, global_conf=None, host="127.0.0.1", port=None,
if global_conf:
daemon = global_conf.get('daemon', daemonize)
umask = kwgars.get('umask', UMASK)
if global_conf:
umask = global_conf.get('umask', umask)
kwargs = dict(
debug=debug,
pidfile=pid
@ -153,7 +161,7 @@ def paste_server(app, global_conf=None, host="127.0.0.1", port=None,
arbiter = Arbiter(bind_addr, workers, app, **kwargs)
if daemon == "true":
daemonize()
daemonize(umask)
else:
os.setpgrp()
arbiter.run()
@ -247,6 +255,9 @@ def run_paster():
else:
workers = int(ctx.local_conf.get('workers', 1))
if not opts.umask:
opts.umask = int(ctx.local_conf.get('umask', UMASK))
if not opts.bind:
host = ctx.local_conf.get('host')
port = ctx.local_conf.get('port')

View File

@ -16,7 +16,7 @@ from django.core.servers.basehttp import AdminMediaHandler, WSGIServerException
from django.core.handlers.wsgi import WSGIHandler
from gunicorn.arbiter import Arbiter
from gunicorn.main import daemonize
from gunicorn.main import daemonize, UMASK
class Command(BaseCommand):
option_list = BaseCommand.option_list + (
@ -28,6 +28,8 @@ class Command(BaseCommand):
help='set the background PID file'),
make_option( '--daemon', dest='daemon', action="store_true",
help='Run daemonized in the background.'),
make_option('--umask', dest='umask', type='int',
help="Define umask of daemon process"),
)
help = "Starts a fully-functional Web server using gunicorn."
args = '[optional port number, or ipaddr:port or unix:/path/to/sockfile]'
@ -57,7 +59,8 @@ class Command(BaseCommand):
workers = int(options.get('workers', '1'))
daemon = options.get('daemon')
quit_command = (sys.platform == 'win32') and 'CTRL-BREAK' or 'CONTROL-C'
pidfile = options.get('pidfile') or None
pidfile = options.get('pidfile', None)
umask = options.get('umask', UMASK)
print "Validating models..."
self.validate(display_num_errors=True)
@ -77,7 +80,7 @@ class Command(BaseCommand):
arbiter = Arbiter(addr, workers, handler,
pidfile=pidfile)
if daemon:
daemonize()
daemonize(umask)
arbiter.run()
except WSGIServerException, e:
# Use helpful error messages instead of ugly tracebacks.