From fdf8169a2c53e824851d93908bea4cb519f8d6b6 Mon Sep 17 00:00:00 2001 From: Benoit Chesneau Date: Wed, 19 May 2010 19:29:51 +0200 Subject: [PATCH] fix issue #57 and make sure target dir of pidfile exists. --- gunicorn/arbiter.py | 6 ++++-- gunicorn/pidfile.py | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/gunicorn/arbiter.py b/gunicorn/arbiter.py index c73eb1f1..cb330d48 100644 --- a/gunicorn/arbiter.py +++ b/gunicorn/arbiter.py @@ -95,8 +95,10 @@ class Arbiter(object): self.pid = os.getpid() self.init_signals() self.LISTENER = create_socket(self.cfg) - self.pidfile = Pidfile(self.cfg.pidfile) - self.pidfile.create(self.pid) + + if self.cfg.pidfile is not None: + self.pidfile = Pidfile(self.cfg.pidfile) + self.pidfile.create(self.pid) self.log.info("Arbiter booted") self.log.info("Listening at: %s" % self.LISTENER) diff --git a/gunicorn/pidfile.py b/gunicorn/pidfile.py index 845d7427..8baa8878 100644 --- a/gunicorn/pidfile.py +++ b/gunicorn/pidfile.py @@ -32,7 +32,10 @@ class Pidfile(object): self.pid = pid # Write pidfile - fd, fname = tempfile.mkstemp(dir=os.path.dirname(self.fname)) + fdir = os.path.dirname(self.fname) + if not os.path.isdir(fdir): + raise RuntimeError("%s don't exist. Can't create pidfile" % fdir) + fd, fname = tempfile.mkstemp(dir=fdir) os.write(fd, "%s\n" % self.pid) if self.fname: os.rename(fname, self.fname)