From a752a3d41973dfae6c03d927f030e5975e836e6b Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Tue, 18 Mar 2008 15:53:46 +0000 Subject: [PATCH] Fixed #6687: added outlog/errlog options to runfcgi. Thanks, tamas. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7297 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/core/servers/fastcgi.py | 14 ++++++++++++-- django/utils/daemonize.py | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/django/core/servers/fastcgi.py b/django/core/servers/fastcgi.py index de04a5af62..d7145e15ec 100644 --- a/django/core/servers/fastcgi.py +++ b/django/core/servers/fastcgi.py @@ -37,7 +37,9 @@ Optional Fcgi settings: (setting=value) maxchildren=NUMBER hard limit number of processes / threads daemonize=BOOL whether to detach from terminal. pidfile=FILE write the spawned process-id to this file. - workdir=DIRECTORY change to this directory when daemonizing + workdir=DIRECTORY change to this directory when daemonizing. + outlog=FILE write stdout to this file. + errlog=FILE write stderr to this file. Examples: Run a "standard" fastcgi process on a file-descriptor @@ -69,6 +71,8 @@ FASTCGI_OPTIONS = { 'minspare': 2, 'maxchildren': 50, 'maxrequests': 0, + 'outlog': None, + 'errlog': None, } def fastcgi_help(message=None): @@ -150,9 +154,15 @@ def runfastcgi(argset=[], **kwargs): else: return fastcgi_help("ERROR: Invalid option for daemonize parameter.") + daemon_kwargs = {} + if options['outlog']: + daemon_kwargs['out_log'] = options['outlog'] + if options['errlog']: + daemon_kwargs['err_log'] = options['errlog'] + if daemonize: from django.utils.daemonize import become_daemon - become_daemon(our_home_dir=options["workdir"]) + become_daemon(our_home_dir=options["workdir"], **daemon_kwargs) if options["pidfile"]: fp = open(options["pidfile"], "w") diff --git a/django/utils/daemonize.py b/django/utils/daemonize.py index 437c288292..f0c2f684bd 100644 --- a/django/utils/daemonize.py +++ b/django/utils/daemonize.py @@ -29,6 +29,8 @@ if os.name == 'posix': os.dup2(si.fileno(), sys.stdin.fileno()) os.dup2(so.fileno(), sys.stdout.fileno()) os.dup2(se.fileno(), sys.stderr.fileno()) + # Set custom file descriptors so that they get proper buffering. + sys.stdout, sys.stderr = so, se else: def become_daemon(our_home_dir='.', out_log=None, err_log=None): """