Пример #1
0
    def cmd_run(self, options, *args):
        """Run the server daemon"""
        setup_logging()

        while True:
            # If the server was initialized before a stoq database exists,
            # don't let the process die. Instead, wait until the configuration
            # is valid so we can really start.
            try:
                setup_stoq()
            # FIXME: We should not be excepting BaseException, but there are
            # some issues (e.g. postgresql not installed) that will raise an
            # exception that inherit from BaseException directly. We need this
            # to make sure we will wait until the database is
            # installed, configured and ready.
            except BaseException as e:
                logging.warning(
                    "Unable to initialize Stoq: %s\n"
                    "Trying again in 1 minute...", str(e))
                time.sleep(60)
            else:
                break

        with api.new_store() as store:
            query = ("SELECT client_addr FROM pg_stat_activity "
                     "WHERE application_name LIKE ? AND "
                     "      application_name NOT LIKE ? AND "
                     "      datname = ? "
                     "LIMIT 1")
            params = [
                u'stoqserver%',
                u'%%%d' % (os.getpid()),
                unicode(db_settings.dbname)
            ]
            res = store.execute(query, params=params).get_one()
            if res is not None:
                print(
                    "There's already a Stoq Server running in this "
                    "database on address %s" % (res[0], ))
                return 1

        if not api.sysparam.get_string('USER_HASH'):
            print "No USER_HASH found for this installation"
            return 1

        worker = Worker()
        atexit.register(lambda: worker.stop())

        def _exit(*args):
            worker.stop()
            sys.exit(0)

        signal.signal(signal.SIGTERM, _exit)
        signal.signal(signal.SIGINT, _exit)
        if platform.system() != 'Windows':
            signal.signal(signal.SIGQUIT, _exit)

        worker.run()
Пример #2
0
    def cmd_run(self, options, *args):
        """Run the server daemon"""
        setup_logging()

        while True:
            # If the server was initialized before a stoq database exists,
            # don't let the process die. Instead, wait until the configuration
            # is valid so we can really start.
            try:
                setup_stoq()
            # FIXME: We should not be excepting BaseException, but there are
            # some issues (e.g. postgresql not installed) that will raise an
            # exception that inherit from BaseException directly. We need this
            # to make sure we will wait until the database is
            # installed, configured and ready.
            except BaseException as e:
                logging.warning("Unable to initialize Stoq: %s\n"
                                "Trying again in 1 minute...", str(e))
                time.sleep(60)
            else:
                break

        with api.new_store() as store:
            query = ("SELECT client_addr FROM pg_stat_activity "
                     "WHERE application_name LIKE ? AND "
                     "      application_name NOT LIKE ? AND "
                     "      datname = ? "
                     "LIMIT 1")
            params = ['stoqserver%', '%%%d' % (os.getpid()),
                      str(db_settings.dbname)]
            res = store.execute(query, params=params).get_one()
            if res is not None:
                print(("There's already a Stoq Server running in this "
                       "database on address %s" % (res[0], )))
                return 1

        if not api.sysparam.get_string('USER_HASH'):
            print("No USER_HASH found for this installation")
            return 1

        worker = Worker()
        atexit.register(lambda: worker.stop())

        def _exit(*args):
            worker.stop()
            sys.exit(0)

        signal.signal(signal.SIGTERM, _exit)
        signal.signal(signal.SIGINT, _exit)
        if platform.system() != 'Windows':
            signal.signal(signal.SIGQUIT, _exit)

        worker.run()
Пример #3
0
    def cmd_run(self, options, *args):
        """Run the server daemon"""
        self._setup_logging()

        while True:
            # If the server was initialized before a stoq database exists,
            # don't let the process die. Instead, wait until the configuration
            # is valid so we can really start.
            try:
                self._setup_stoq()
            except Exception as e:
                logging.warning("Unable to initialize Stoq: %s\n"
                                "Trying again in 1 minute...", str(e))
                time.sleep(60)
            else:
                break

        with api.new_store() as store:
            query = ("SELECT client_addr FROM pg_stat_activity "
                     "WHERE application_name LIKE ? AND "
                     "      application_name NOT LIKE ? AND "
                     "      datname = ? "
                     "LIMIT 1")
            params = [u'stoqserver%', u'%%%d' % (os.getpid()),
                      unicode(db_settings.dbname)]
            res = store.execute(query, params=params).get_one()
            if res is not None:
                print ("There's already a Stoq Server running in this "
                       "database on address %s" % (res[0], ))
                return 1

        if not api.sysparam.get_string('USER_HASH'):
            print "No USER_HASH found for this installation"
            return 1

        worker = Worker()
        atexit.register(lambda: worker.stop())

        def _exit(*args):
            worker.stop()
            sys.exit(0)

        signal.signal(signal.SIGTERM, _exit)
        signal.signal(signal.SIGINT, _exit)
        signal.signal(signal.SIGQUIT, _exit)

        worker.run()
Пример #4
0
def worker():
    return Worker()