def run_server(dbpath=os.path.expanduser(config.dbserver.file), dbhostport=None, loglevel='WARN'): """ Run the DbServer on the given database file and port. If not given, use the settings in openquake.cfg. """ if dbhostport: # assume a string of the form "dbhost:port" dbhost, port = dbhostport.split(':') addr = (dbhost, int(port)) else: addr = (config.dbserver.listen, DBSERVER_PORT) # create the db directory if needed dirname = os.path.dirname(dbpath) if not os.path.exists(dirname): os.makedirs(dirname) # create and upgrade the db if needed db('PRAGMA foreign_keys = ON') # honor ON DELETE CASCADE actions.upgrade_db(db) # the line below is needed to work around a very subtle bug of sqlite; # we need new connections, see https://github.com/gem/oq-engine/pull/3002 db.close() # reset any computation left in the 'executing' state actions.reset_is_running(db) # configure logging and start the server logging.basicConfig(level=getattr(logging, loglevel)) DbServer(db, addr).start() # expects to be killed with CTRL-C
def run_server(dbpathport=None, logfile=DATABASE['LOG'], loglevel='WARN'): """ Run the DbServer on the given database file and port. If not given, use the settings in openquake.cfg. """ if dbpathport: # assume a string of the form "dbpath:port" dbpath, port = dbpathport.split(':') addr = (DATABASE['HOST'], int(port)) DATABASE['NAME'] = dbpath DATABASE['PORT'] = int(port) else: addr = config.DBS_ADDRESS # create the db directory if needed dirname = os.path.dirname(DATABASE['NAME']) if not os.path.exists(dirname): os.makedirs(dirname) # create and upgrade the db if needed curs = connection.cursor() # bind the db curs.execute('PRAGMA foreign_keys = ON') # honor ON DELETE CASCADE actions.upgrade_db() # configure logging and start the server logging.basicConfig(level=getattr(logging, loglevel), filename=logfile) DbServer(addr, config.DBS_AUTHKEY).loop()
def run_server(dbhostport=None, dbpath=None, logfile=DATABASE['LOG'], loglevel='WARN'): """ Run the DbServer on the given database file and port. If not given, use the settings in openquake.cfg. """ if dbhostport: # assume a string of the form "dbhost:port" dbhost, port = dbhostport.split(':') addr = (dbhost, int(port)) DATABASE['PORT'] = int(port) else: addr = config.DBS_ADDRESS if dbpath: DATABASE['NAME'] = dbpath # create the db directory if needed dirname = os.path.dirname(DATABASE['NAME']) if not os.path.exists(dirname): os.makedirs(dirname) # create and upgrade the db if needed db = dbapi.Db(sqlite3.connect, DATABASE['NAME'], isolation_level=None, detect_types=sqlite3.PARSE_DECLTYPES) db('PRAGMA foreign_keys = ON') # honor ON DELETE CASCADE actions.upgrade_db(db) db.conn.close() # configure logging and start the server logging.basicConfig(level=getattr(logging, loglevel), filename=logfile) DbServer(db, addr, config.DBS_AUTHKEY).loop()
def run_server(dbpath=os.path.expanduser(config.dbserver.file), dbhostport=None, loglevel='WARN'): """ Run the DbServer on the given database file and port. If not given, use the settings in openquake.cfg. """ if dbhostport: # assume a string of the form "dbhost:port" dbhost, port = dbhostport.split(':') addr = (dbhost, int(port)) else: addr = (config.dbserver.listen, DBSERVER_PORT) # create the db directory if needed dirname = os.path.dirname(dbpath) if not os.path.exists(dirname): os.makedirs(dirname) # create and upgrade the db if needed db('PRAGMA foreign_keys = ON') # honor ON DELETE CASCADE actions.upgrade_db(db) # the line below is needed to work around a very subtle bug of sqlite; # we need new connections, see https://github.com/gem/oq-engine/pull/3002 db.close() # reset any computation left in the 'executing' state actions.reset_is_running(db) # configure logging and start the server logging.basicConfig(level=getattr(logging, loglevel)) DbServer(db, addr).start() # expects to be killed with CTRL-C
def run_server(dbhostport=None, loglevel='WARN', foreground=False): """ Run the DbServer on the given database file and port. If not given, use the settings in openquake.cfg. """ # configure the logging first of all logging.basicConfig(level=getattr(logging, loglevel.upper())) if dbhostport: # assume a string of the form "dbhost:port" dbhost, port = dbhostport.split(':') addr = (dbhost, int(port)) else: addr = (config.dbserver.listen, DBSERVER_PORT) # create the db directory if needed dirname = os.path.dirname(os.path.expanduser(config.dbserver.file)) if not os.path.exists(dirname): os.makedirs(dirname) # create and upgrade the db if needed db('PRAGMA foreign_keys = ON') # honor ON DELETE CASCADE actions.upgrade_db(db) # the line below is needed to work around a very subtle bug of sqlite; # we need new connections, see https://github.com/gem/oq-engine/pull/3002 db.close() # start the dbserver if hasattr(os, 'fork') and not (config.multi_user or foreground): # needed for https://github.com/gem/oq-engine/issues/3211 # but only if multi_user = False, otherwise init/supervisor # will loose control of the process detach_process() DbServer(db, addr).start() # expects to be killed with CTRL-C
def runserver(dbpathport=None, logfile=DATABASE['LOG'], loglevel='WARN'): logging.basicConfig(level=getattr(logging, loglevel), filename=logfile) if dbpathport: # assume a string of the form "dbpath:port" dbpath, port = dbpathport.split(':') addr = (DATABASE['HOST'], int(port)) DATABASE['NAME'] = dbpath DATABASE['PORT'] = int(port) else: addr = config.DBS_ADDRESS # create and upgrade the db if needed connection.cursor() # bind the db actions.upgrade_db() # start the server DbServer(addr, config.DBS_AUTHKEY).loop()