fix issue #57 and make sure target dir of pidfile exists.

This commit is contained in:
Benoit Chesneau 2010-05-19 19:29:51 +02:00
parent ed17054137
commit fdf8169a2c
2 changed files with 8 additions and 3 deletions

View File

@ -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)

View File

@ -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)