def updateConfig(self): defaultcfgfile = os.path.join(self.env.SEISCOMP_ROOT, "etc", "defaults", self.name + ".cfg") cfgfile = os.path.join(self.env.SEISCOMP_ROOT, "etc", self.name + ".cfg") cfg = config.Config() cfg.readConfig(defaultcfgfile) cfg.readConfig(cfgfile) try: queues = cfg.getStrings("queues") except ValueError: queues = [] # iterate through all queues and check DB schema version if message # processor dbstore is present for queue in queues: try: msgProcs = cfg.getStrings("queues.{}.processors.messages" \ .format(queue)) if "dbstore" in msgProcs and not self.checkDBStore(cfg, queue): return 1 except ValueError: pass return 0
def updateConfig(self): cfg = config.Config() system.Environment.Instance().initConfig(cfg, self.name) try: queues = cfg.getStrings("queues") except ValueError: queues = [] # iterate through all queues and check DB schema version if message # processor dbstore is present for queue in queues: print("INFO: Checking queue '{}'".format(queue), file=sys.stderr) try: msgProcs = cfg.getStrings( "queues.{}.processors.messages".format(queue)) if "dbstore" in msgProcs and not self.checkDBStore(cfg, queue): return 1 except ValueError: print(" * ignoring - no database backend configured", file=sys.stderr) return 0
def run(self, env): desc_pattern = os.path.join(env.SEISCOMP_ROOT, "etc", "descriptions", "*.xml") xmls = glob.glob(desc_pattern) setup_groups = {} for f in xmls: try: tree = ElementTree.parse(f) except ParseError as xxx_todo_changeme: (err) = xxx_todo_changeme sys.stderr.write("%s: parsing XML failed: %s\n" % (f, err)) continue root = tree.getroot() if tagname(root) != "seiscomp": sys.stderr.write("%s: wrong root tag, expected 'seiscomp'\n" % f) continue # Read all modules mods = tree.findall("module") for mod in mods: modname = mod.get('name') if not modname: sys.stderr.write("%s: skipping module without name\n" % f) continue if modname in setup_groups: raise Exception("%s: duplicate module name: %s" % (f, modname)) setup = mod.find("setup") if setup is None: continue groups = setup.findall("group") if len(groups) == 0: continue setup_groups[modname] = groups # Read all plugin's plugins = tree.findall("plugin") for plugin in plugins: try: modname = plugin.find('extends').text.strip() except: raise Exception("%s: plugin does not define 'extends'" % f) if modname.find('\n') >= 0: raise Exception("%s: wrong module name in plugin." \ "extends: no newlines allowed" % f) if not modname: sys.stderr.write("%s: skipping module without name\n" % f) continue setup = plugin.find("setup") if setup is None: continue groups = setup.findall("group") if len(groups) == 0: continue if modname in setup_groups: setup_groups[modname] += groups else: setup_groups[modname] = groups for name, groups in sorted(setup_groups.items()): self.addGroups(self.setupTree, name, groups) # Always descend to the first child (if available) self.setupTree.activeChild = self.setupTree.child self.currentNode = self.setupTree.activeChild sys.stdout.write(''' ==================================================================== SeisComP setup ==================================================================== This initializes the configuration of your installation. If you already made adjustments to the configuration files be warned that this setup will overwrite existing parameters with default values. This is not a configurator for all options of your setup but helps to setup initial standard values. -------------------------------------------------------------------- Hint: Entered values starting with a dot (.) are handled as commands. Available commands are: quit: Quit setup without modification to your configuration. back: Go back to the previous parameter. help: Show help about the current parameter (if available). If you need to enter a value with a leading dot, escape it with backslash, e.g. "\.value". -------------------------------------------------------------------- ''') try: self.fillTree() except StopIteration: raise Exception("aborted by user") cfg = config.Config() dumpTree(cfg, self.setupTree) return cfg
def setup(self, setup_config): cfgfile = os.path.join(self.env.SEISCOMP_ROOT, "etc", self.name + ".cfg") schemapath = os.path.join(self.env.SEISCOMP_ROOT, "share", "db") cfg = config.Config() cfg.readConfig(cfgfile) try: dbenable = setup_config.getBool(self.name + ".database.enable") except ValueError: sys.stderr.write(" - database.enable not set, ignoring setup\n") return 0 dbBackend = None if not dbenable: removeEntry(cfg, "queues.production.plugins", "dbstore") removeEntry(cfg, "queues.production.processors.messages", "dbstore") cfg.remove("queues.production.processors.messages.dbstore.driver") cfg.remove("queues.production.processors.messages.dbstore.read") cfg.remove("queues.production.processors.messages.dbstore.write") else: try: dbBackend = setup_config.getString(self.name + ".database.enable.backend") except ValueError: sys.stderr.write( " - database backend not set, ignoring setup\n") return 1 if dbBackend == "mysql/mariadb": dbBackend = "mysql" try: rootpwd = setup_config.getString( self.name + ".database.enable.backend.create.rootpw") except ValueError: rootpwd = "" try: runAsSuperUser = setup_config.getBool( self.name + ".database.enable.backend.create.runAsSuperUser") except ValueError: runAsSuperUser = False params = DBParams() if not self.readDBParams(params, setup_config): return 1 cfg.setString( "queues.production.processors.messages.dbstore.read", "{}:{}@{}/{}".format(params.rouser, params.ropwd, params.rohost, params.db)) cfg.setString( "queues.production.processors.messages.dbstore.write", "{}:{}@{}/{}".format(params.rwuser, params.rwpwd, params.rwhost, params.db)) if params.create: dbScript = os.path.join(schemapath, "mysql_setup.py") options = [ params.db, params.rwuser, params.rwpwd, params.rouser, params.ropwd, params.rwhost, rootpwd, str(params.drop), schemapath ] binary = os.path.join(schemapath, "pkexec_wrapper.sh") print("+ Running MySQL database setup script {}".format( dbScript)) if runAsSuperUser: cmd = "{} seiscomp-python {} {}".format( binary, dbScript, " ".join(options)) else: cmd = "{} {}".format(dbScript, " ".join(options)) p = subprocess.Popen(cmd, shell=True) ret = p.wait() if ret != 0: print(" - Failed to setup database", file=sys.stderr) return 1 elif dbBackend == "postgresql": dbBackend = "postgresql" params = DBParams() if not self.readDBParams(params, setup_config): return 1 cfg.setString( "queues.production.processors.messages.dbstore.read", "{}:{}@{}/{}".format(params.rouser, params.ropwd, params.rohost, params.db)) cfg.setString( "queues.production.processors.messages.dbstore.write", "{}:{}@{}/{}".format(params.rwuser, params.rwpwd, params.rwhost, params.db)) if params.create: try: tmpPath = tempfile.mkdtemp() os.chmod(tmpPath, 0o755) try: copy_tree(schemapath, tmpPath) filename = os.path.join(self.env.SEISCOMP_ROOT, "bin", "seiscomp-python") shutil.copy(filename, tmpPath) except Exception as err: print(err) return 1 dbScript = os.path.join(tmpPath, "postgres_setup.py") options = [ params.db, params.rwuser, params.rwpwd, params.rouser, params.ropwd, params.rwhost, str(params.drop), tmpPath ] binary = os.path.join(schemapath, "pkexec_wrapper.sh") print("+ Running PostgreSQL database setup script {}". format(dbScript)) cmd = "{} su postgres -c \"{}/seiscomp-python {} {}\"" \ .format(binary, tmpPath, dbScript, " ".join(options)) p = subprocess.Popen(cmd, shell=True) ret = p.wait() if ret != 0: print(" - Failed to setup database", file=sys.stderr) return 1 finally: try: shutil.rmtree(tmpPath) except OSError: pass elif dbBackend == "sqlite3": dbBackend = "sqlite3" dbScript = os.path.join(schemapath, "sqlite3_setup.py") try: create = setup_config.getBool( self.name + ".database.enable.backend.create") except BaseException: create = False try: filename = setup_config.getString( self.name + ".database.enable.backend.filename") filename = system.Environment.Instance().absolutePath( filename) except BaseException: filename = os.path.join(self.env.SEISCOMP_ROOT, "var", "lib", "seiscomp.db") if not filename: sys.stderr.write(" - location not set, ignoring setup\n") return 1 try: override = setup_config.getBool( self.name + ".database.enable.backend.create.override") except BaseException: override = False options = [filename, schemapath] if create: print("+ Running SQLite3 database setup script {}".format( dbScript)) cmd = "seiscomp-python {} {} {}".format( dbScript, " ".join(options), override) p = subprocess.Popen(cmd, shell=True) ret = p.wait() if ret != 0: print(" - Failed to setup database", file=sys.stderr) return 1 cfg.setString( "queues.production.processors.messages.dbstore.read", filename) cfg.setString( "queues.production.processors.messages.dbstore.write", filename) # Configure db backend for scmaster cfg.setString("core.plugins", "db" + dbBackend) cfg.setString( "queues.production.processors.messages.dbstore.driver", dbBackend) addEntry(cfg, "queues.production.plugins", "dbstore") addEntry(cfg, "queues.production.processors.messages", "dbstore") cfg.writeConfig() # Now we need to insert the corresponding plugin to etc/global.cfg # that all connected local clients can handle the database backend if dbBackend: cfgfile = os.path.join(self.env.SEISCOMP_ROOT, "etc", "global.cfg") cfg = config.Config() cfg.readConfig(cfgfile) cfg.setString("core.plugins", "db" + dbBackend) cfg.writeConfig() return 0
def setup(self, setup_config): cfgfile = os.path.join(self.env.SEISCOMP_ROOT, "etc", self.name + ".cfg") schemapath = os.path.join(self.env.SEISCOMP_ROOT, "share", "db") cfg = config.Config() cfg.readConfig(cfgfile) try: dbenable = setup_config.getBool(self.name + ".database.enable") except ValueError: sys.stderr.write(" - database.enable not set, ignoring setup\n") return 0 dbBackend = None if not dbenable: removeEntry(cfg, "queues.production.plugins", "dbstore") removeEntry(cfg, "queues.production.processors.messages", "dbstore") cfg.remove("queues.production.processors.messages.dbstore.driver") cfg.remove("queues.production.processors.messages.dbstore.read") cfg.remove("queues.production.processors.messages.dbstore.write") else: try: dbBackend = setup_config.getString(self.name + ".database.enable.backend") except ValueError: sys.stderr.write( " - database backend not set, ignoring setup\n") return 1 # Configure db backend for scmaster cfg.setString("core.plugins", "db" + dbBackend) try: db = setup_config.getString(self.name + ".database.enable.db") except ValueError: sys.stderr.write(" - database name not set, ignoring setup\n") return 1 try: rwhost = setup_config.getString(self.name + ".database.enable.rwhost") except ValueError: sys.stderr.write( " - database host (rw) not set, ignoring setup\n") return 1 try: rwuser = setup_config.getString(self.name + ".database.enable.rwuser") except ValueError: sys.stderr.write( " - database user (rw) not set, ignoring setup\n") return 1 try: rwpwd = setup_config.getString(self.name + ".database.enable.rwpwd") except ValueError: sys.stderr.write( " - database password (rw) not set, ignoring setup\n") return 1 try: rohost = setup_config.getString(self.name + ".database.enable.rohost") except ValueError: sys.stderr.write( " - database host (ro) not set, ignoring setup\n") return 1 try: rouser = setup_config.getString(self.name + ".database.enable.rouser") except ValueError: sys.stderr.write( " - database user (ro) not set, ignoring setup\n") return 1 try: ropwd = setup_config.getString(self.name + ".database.enable.ropwd") except ValueError: sys.stderr.write( " - database password (ro) not set, ignoring setup\n") return 1 if dbBackend == "mysql": try: create = setup_config.getBool( self.name + ".database.enable.backend.create") except ValueError: create = False try: drop = setup_config.getBool( self.name + ".database.enable.backend.create.drop") except ValueError: drop = False try: rootpwd = setup_config.getString( self.name + ".database.enable.backend.create.rootpw") except ValueError: rootpwd = "" if create: if not createMYSQLDB(db, rwuser, rwpwd, rouser, ropwd, rwhost, rootpwd, drop, schemapath): sys.stdout.write(" - Failed to setup database\n") return 1 addEntry(cfg, "queues.production.plugins", "dbstore") addEntry(cfg, "queues.production.processors.messages", "dbstore") cfg.setString( "queues.production.processors.messages.dbstore.driver", dbBackend) cfg.setString("queues.production.processors.messages.dbstore.read", rouser + ":" + ropwd + "@" + rohost + "/" + db) cfg.setString( "queues.production.processors.messages.dbstore.write", rwuser + ":" + rwpwd + "@" + rwhost + "/" + db) cfg.writeConfig() # Now we need to insert the corresponding plugin to etc/global.cfg # that all connected local clients can handle the database backend if dbBackend: cfgfile = os.path.join(self.env.SEISCOMP_ROOT, "etc", "global.cfg") cfg = config.Config() cfg.readConfig(cfgfile) cfg.setString("core.plugins", "db" + dbBackend) cfg.writeConfig() return 0