Make WorkerTmp accept a configurable tmp dir

This commit is contained in:
Raphaël Slinckx 2013-12-18 15:05:01 +01:00 committed by benoitc
parent f7d9979d5b
commit f1e2073047
2 changed files with 16 additions and 1 deletions

View File

@ -801,6 +801,18 @@ class Pidfile(Setting):
If not set, no PID file will be written.
"""
class WorkerTmpDir(Setting):
name = "worker_tmp_dir"
section = "Server Mechanics"
cli = ["--worker-tmp-dir"]
meta = "DIR"
validator = validate_string
default = None
desc = """\
A directory to use for the worker heartbeat temporary file.
If not set, the default temporary directory will be used.
"""
class User(Setting):
name = "user"

View File

@ -19,7 +19,10 @@ class WorkerTmp(object):
def __init__(self, cfg):
old_umask = os.umask(cfg.umask)
fd, name = tempfile.mkstemp(prefix="wgunicorn-")
fdir = cfg.worker_tmp_dir
if fdir and not os.path.isdir(fdir):
raise RuntimeError("%s doesn't exist. Can't create workertmp." % fdir)
fd, name = tempfile.mkstemp(prefix="wgunicorn-", dir=fdir)
# allows the process to write to the file
util.chown(name, cfg.uid, cfg.gid)