ensure runtime dir exists
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 06 Aug 2009 09:04:26 +0200
changeset 2711 7aee3bd7a704
parent 2710 40789c3044f3
child 2715 acdaf780d4a6
ensure runtime dir exists
etwist/server.py
server/serverctl.py
--- a/etwist/server.py	Wed Aug 05 19:14:39 2009 +0200
+++ b/etwist/server.py	Thu Aug 06 09:04:26 2009 +0200
@@ -370,6 +370,11 @@
     if not debug:
         daemonize()
         if config['pid-file']:
+            # ensure the directory where the pid-file should be set exists (for
+            # instance /var/run/cubicweb may be deleted on computer restart)
+            piddir = os.path.dirname(config['pid-file'])
+            if not os.path.exists(piddir):
+                os.makedirs(piddir)
             file(config['pid-file'], 'w').write(str(os.getpid()))
     if config['profile']:
         prof = hotshot.Profile(config['profile'])
--- a/server/serverctl.py	Wed Aug 05 19:14:39 2009 +0200
+++ b/server/serverctl.py	Thu Aug 06 09:04:26 2009 +0200
@@ -458,7 +458,13 @@
         # create the server
         server = RepositoryServer(config, debug)
         # go ! (don't daemonize in debug mode)
-        if not debug and server.daemonize(config['pid-file']) == -1:
+        pidfile = config['pid-file']
+        # ensure the directory where the pid-file should be set exists (for
+        # instance /var/run/cubicweb may be deleted on computer restart)
+        piddir = os.path.dirname(pidfile)
+        if not os.path.exists(piddir):
+            os.makedirs(piddir)
+        if not debug and server.daemonize(pidfile) == -1:
             return
         uid = config['uid']
         if uid is not None: