added init.d script guessing.
authorMartin Pihlak <martin.pihlak@gmail.com>
Fri, 14 Oct 2011 12:15:48 +0000 (15:15 +0300)
committerMartin Pihlak <martin.pihlak@gmail.com>
Fri, 14 Oct 2011 12:15:48 +0000 (15:15 +0300)
python/walmgr.py

index 9856aac6b4c1cb6825178d782c799b00fae2b1d6..22c90f2f32505cbc02e8357de7d5007ceea5c9d8 100755 (executable)
@@ -324,8 +324,6 @@ class WalMgr(skytools.DBScript):
 
             # slave configuration settings
             slave_opt_dict = {
-                'slave_stop_cmd':   '/etc/init.d/postgresql-%s stop' % DEFAULT_PG_VERSION,
-                'slave_start_cmd':  '/etc/init.d/postgresql-%s start' % DEFAULT_PG_VERSION,
                 'completed_wals':   '%%(walmgr_data)s/logs.complete',
                 'partial_wals':     '%%(walmgr_data)s/logs.partial',
                 'full_backup':      '%%(walmgr_data)s/data.master',
@@ -851,7 +849,6 @@ class WalMgr(skytools.DBScript):
             for path in os.environ['PATH'].split(os.pathsep):
                 path = os.path.expanduser(path)
                 exe = os.path.join(path, "postgres")
-                print "checking",exe
                 if os.path.isfile(exe):
                     self.postgres_bin = path
                     break
@@ -872,6 +869,19 @@ class WalMgr(skytools.DBScript):
                 # postgres_conf is required for master
                 die(1, "Configuration file not found: %s" % self.postgres_conf)
 
+        # Attempt to guess the init.d script name
+        script_suffixes = [ "9.1", "9.0", "8.4", "8.3", "8.2", "8.1", "8.0" ]
+        self.initd_script = "/etc/init.d/postgresql"
+        if not os.path.exists(self.initd_script):
+            for suffix in script_suffixes:
+                try_file = "%s-%s" % (self.initd_script, suffix)
+                if os.path.exists(try_file):
+                    self.initd_script = try_file
+                    break
+            else:
+                self.initd_script = "%s -m fast -D %s" % \
+                    (os.path.join(self.postgres_bin, "pg_ctl"), os.path.abspath(self.pgdata))
+
     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")
@@ -964,6 +974,11 @@ compression         = %(compression)s
         self.override_cf_option('slave_data', self.pgdata)
         self.override_cf_option('slave_config_dir', os.path.dirname(self.postgres_conf))
 
+        if self.initd_script:
+            print "overriding "
+            self.override_cf_option('slave_start_cmd', "%s start" % self.initd_script)
+            self.override_cf_option('slave_stop_cmd', "%s stop" % self.initd_script)
+
         slave_config = """[walmgr]
 job_name             = %(job_name)s
 logfile              = %(logfile)s