Create log,pid,conf directories during --init
authorMartin Pihlak <martin.pihlak@skype.net>
Wed, 9 Feb 2011 13:08:33 +0000 (13:08 +0000)
committerMartin Pihlak <martin.pihlak@skype.net>
Wed, 9 Feb 2011 13:08:33 +0000 (13:08 +0000)
python/walmgr.py

index 9d7ca695d105d4e2b0099912d9008ca42f5dd352..52eab6148faa0db10dd2d982a2e71c84a23bba88 100755 (executable)
@@ -347,6 +347,13 @@ class WalMgr(skytools.DBScript):
 
             self.is_master = config.has_option('master_data')
 
+        # create the log and pid files if needed
+        for cfk in [ "logfile", "pidfile" ]:
+            if config.has_option(cfk):
+                dirname = os.path.dirname(config.getfile(cfk))
+                if not os.path.isdir(dirname):
+                    os.makedirs(dirname)
+
         return config
 
     def __init__(self, args):
@@ -784,6 +791,12 @@ class WalMgr(skytools.DBScript):
     def write_walmgr_config(self, config_data):
         cf_name = os.path.join(os.path.expanduser(self.options.config_dir),
                     self.cf.get("job_name") + ".ini")
+
+        dirname = os.path.dirname(cf_name)
+        if not os.path.isdir(dirname):
+            self.log.info('Creating config directory: %s' % dirname)
+            os.makedirs(dirname)
+
         self.log.info('Writing configuration file: %s' % cf_name)
         self.log.debug("config data:\n%s" % config_data)
         if not self.not_really:
@@ -842,6 +855,7 @@ keep_symlinks       = %(keep_symlinks)s
 
         self.write_walmgr_config(master_config)
 
+        # generate SSH key pair if requested
         if self.options.ssh_keygen:
             keyfile = os.path.expanduser("~/.ssh/id_dsa")
             if os.path.isfile(keyfile):