tor-weather crashes on start when creating database schema
starting the tor-weather service creates the database schema, but then tor-weather immediately crashes with an exception related to creating the schema. i assume each of the gunicorn workers (there's 5 right now) tries to create the database schema, and only the first one succeeds because of the lack of IF NOT EXISTS
in the sql command.
Mar 14 16:50:20 weather-01 poetry[2234087]: [2023-03-14 16:50:20 +0000] [2234087] [INFO] Worker exiting (pid: 2234087)
Mar 14 16:50:20 weather-01 poetry[2234085]: [2023-03-14 16:50:20 +0000] [2234085] [ERROR] Exception in worker process
Mar 14 16:50:20 weather-01 poetry[2234085]: Traceback (most recent call last):
Mar 14 16:50:20 weather-01 poetry[2234085]: File "/home/weather/.cache/pypoetry/virtualenvs/tor-weather-57YGnyhM-py3.9/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1964, in _exec_single_context
Mar 14 16:50:20 weather-01 poetry[2234085]: self.dialect.do_execute(
Mar 14 16:50:20 weather-01 poetry[2234085]: File "/home/weather/.cache/pypoetry/virtualenvs/tor-weather-57YGnyhM-py3.9/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 747, in do_execute
Mar 14 16:50:20 weather-01 poetry[2234085]: cursor.execute(statement, parameters)
Mar 14 16:50:20 weather-01 poetry[2234085]: psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "pg_type_typname_nsp_index"
Mar 14 16:50:20 weather-01 poetry[2234085]: DETAIL: Key (typname, typnamespace)=(admin_id_seq, 2200) already exists.
Mar 14 16:50:20 weather-01 poetry[2234085]: The above exception was the direct cause of the following exception:
Mar 14 16:50:20 weather-01 poetry[2234085]: Traceback (most recent call last):
Mar 14 16:50:20 weather-01 poetry[2234085]: File "/home/weather/.cache/pypoetry/virtualenvs/tor-weather-57YGnyhM-py3.9/lib/python3.9/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
Mar 14 16:50:20 weather-01 poetry[2234085]: worker.init_process()
Mar 14 16:50:20 weather-01 poetry[2234085]: File "/home/weather/.cache/pypoetry/virtualenvs/tor-weather-57YGnyhM-py3.9/lib/python3.9/site-packages/gunicorn/workers/base.py", line 134, in init_process
Mar 14 16:50:20 weather-01 poetry[2234085]: self.load_wsgi()
Mar 14 16:50:20 weather-01 poetry[2234085]: File "/home/weather/.cache/pypoetry/virtualenvs/tor-weather-57YGnyhM-py3.9/lib/python3.9/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
Mar 14 16:50:20 weather-01 poetry[2234085]: self.wsgi = self.app.wsgi()
Mar 14 16:50:20 weather-01 poetry[2234085]: File "/home/weather/.cache/pypoetry/virtualenvs/tor-weather-57YGnyhM-py3.9/lib/python3.9/site-packages/gunicorn/app/base.py", line 67, in wsgi
Mar 14 16:50:20 weather-01 poetry[2234085]: self.callable = self.load()
Mar 14 16:50:20 weather-01 poetry[2234085]: File "/home/weather/.cache/pypoetry/virtualenvs/tor-weather-57YGnyhM-py3.9/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
Mar 14 16:50:20 weather-01 poetry[2234085]: return self.load_wsgiapp()
Mar 14 16:50:20 weather-01 poetry[2234085]: File "/home/weather/.cache/pypoetry/virtualenvs/tor-weather-57YGnyhM-py3.9/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
Mar 14 16:50:20 weather-01 poetry[2234085]: return util.import_app(self.app_uri)
Mar 14 16:50:20 weather-01 poetry[2234085]: File "/home/weather/.cache/pypoetry/virtualenvs/tor-weather-57YGnyhM-py3.9/lib/python3.9/site-packages/gunicorn/util.py", line 359, in import_app
Mar 14 16:50:20 weather-01 poetry[2234085]: mod = importlib.import_module(module)
Mar 14 16:50:20 weather-01 poetry[2234085]: File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
Mar 14 16:50:20 weather-01 poetry[2234085]: return _bootstrap._gcd_import(name[level:], package, level)
Mar 14 16:50:20 weather-01 poetry[2234085]: File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
Mar 14 16:50:20 weather-01 poetry[2234085]: File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
Mar 14 16:50:20 weather-01 poetry[2234085]: File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
Mar 14 16:50:20 weather-01 poetry[2234085]: File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
Mar 14 16:50:20 weather-01 poetry[2234085]: File "<frozen importlib._bootstrap_external>", line 790, in exec_module
Mar 14 16:50:20 weather-01 poetry[2234085]: File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
Mar 14 16:50:20 weather-01 poetry[2234085]: File "/home/weather/tor-weather/tor_weather/app.py", line 5, in <module>
Mar 14 16:50:20 weather-01 poetry[2234085]: app: Flask = create_app()
Mar 14 16:50:20 weather-01 poetry[2234085]: File "/home/weather/tor-weather/tor_weather/__init__.py", line 32, in create_app
Mar 14 16:50:20 weather-01 poetry[2234085]: configure_database(app)
Mar 14 16:50:20 weather-01 poetry[2234085]: File "/home/weather/tor-weather/tor_weather/__init__.py", line 106, in configure_database
Mar 14 16:50:20 weather-01 poetry[2234085]: db.create_all()
Mar 14 16:50:20 weather-01 poetry[2234085]: File "/home/weather/.cache/pypoetry/virtualenvs/tor-weather-57YGnyhM-py3.9/lib/python3.9/site-packages/flask_sqlalchemy/extension.py", line 868, in create_all
Mar 14 16:50:20 weather-01 poetry[2234085]: self._call_for_binds(bind_key, "create_all")
Mar 14 16:50:20 weather-01 poetry[2234085]: File "/home/weather/.cache/pypoetry/virtualenvs/tor-weather-57YGnyhM-py3.9/lib/python3.9/site-packages/flask_sqlalchemy/extension.py", line 849, in _call_for_binds
Mar 14 16:50:20 weather-01 poetry[2234085]: getattr(metadata, op_name)(bind=engine)
Mar 14 16:50:20 weather-01 poetry[2234085]: File "/home/weather/.cache/pypoetry/virtualenvs/tor-weather-57YGnyhM-py3.9/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 5558, in create_all
Mar 14 16:50:20 weather-01 poetry[2234085]: bind._run_ddl_visitor(
Mar 14 16:50:20 weather-01 poetry[2234085]: File "/home/weather/.cache/pypoetry/virtualenvs/tor-weather-57YGnyhM-py3.9/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 3220, in _run_ddl_visitor
Mar 14 16:50:20 weather-01 poetry[2234085]: conn._run_ddl_visitor(visitorcallable, element, **kwargs)
Mar 14 16:50:20 weather-01 poetry[2234085]: File "/home/weather/.cache/pypoetry/virtualenvs/tor-weather-57YGnyhM-py3.9/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2427, in _run_ddl_visitor
Mar 14 16:50:20 weather-01 poetry[2234085]: visitorcallable(self.dialect, self, **kwargs).traverse_single(element)
Mar 14 16:50:20 weather-01 poetry[2234085]: File "/home/weather/.cache/pypoetry/virtualenvs/tor-weather-57YGnyhM-py3.9/lib/python3.9/site-packages/sqlalchemy/sql/visitors.py", line 677, in traverse_single
Mar 14 16:50:20 weather-01 poetry[2234085]: return meth(obj, **kw)
Mar 14 16:50:20 weather-01 poetry[2234085]: File "/home/weather/.cache/pypoetry/virtualenvs/tor-weather-57YGnyhM-py3.9/lib/python3.9/site-packages/sqlalchemy/sql/ddl.py", line 928, in visit_metadata
Mar 14 16:50:20 weather-01 poetry[2234085]: self.traverse_single(
Mar 14 16:50:20 weather-01 poetry[2234085]: File "/home/weather/.cache/pypoetry/virtualenvs/tor-weather-57YGnyhM-py3.9/lib/python3.9/site-packages/sqlalchemy/sql/visitors.py", line 677, in traverse_single
Mar 14 16:50:20 weather-01 poetry[2234085]: return meth(obj, **kw)
Mar 14 16:50:20 weather-01 poetry[2234085]: File "/home/weather/.cache/pypoetry/virtualenvs/tor-weather-57YGnyhM-py3.9/lib/python3.9/site-packages/sqlalchemy/sql/ddl.py", line 962, in visit_table
Mar 14 16:50:20 weather-01 poetry[2234085]: CreateTable(
Mar 14 16:50:20 weather-01 poetry[2234085]: File "/home/weather/.cache/pypoetry/virtualenvs/tor-weather-57YGnyhM-py3.9/lib/python3.9/site-packages/sqlalchemy/sql/ddl.py", line 321, in _invoke_with
Mar 14 16:50:20 weather-01 poetry[2234085]: return bind.execute(self)
Mar 14 16:50:20 weather-01 poetry[2234085]: File "/home/weather/.cache/pypoetry/virtualenvs/tor-weather-57YGnyhM-py3.9/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1414, in execute
Mar 14 16:50:20 weather-01 poetry[2234085]: return meth(
Mar 14 16:50:20 weather-01 poetry[2234085]: File "/home/weather/.cache/pypoetry/virtualenvs/tor-weather-57YGnyhM-py3.9/lib/python3.9/site-packages/sqlalchemy/sql/ddl.py", line 185, in _execute_on_connection
Mar 14 16:50:20 weather-01 poetry[2234085]: return connection._execute_ddl(
Mar 14 16:50:20 weather-01 poetry[2234085]: File "/home/weather/.cache/pypoetry/virtualenvs/tor-weather-57YGnyhM-py3.9/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1526, in _execute_ddl
Mar 14 16:50:20 weather-01 poetry[2234085]: ret = self._execute_context(
Mar 14 16:50:20 weather-01 poetry[2234085]: File "/home/weather/.cache/pypoetry/virtualenvs/tor-weather-57YGnyhM-py3.9/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1842, in _execute_context
Mar 14 16:50:20 weather-01 poetry[2234085]: return self._exec_single_context(
Mar 14 16:50:20 weather-01 poetry[2234085]: File "/home/weather/.cache/pypoetry/virtualenvs/tor-weather-57YGnyhM-py3.9/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1983, in _exec_single_context
Mar 14 16:50:20 weather-01 poetry[2234085]: self._handle_dbapi_exception(
Mar 14 16:50:20 weather-01 poetry[2234085]: File "/home/weather/.cache/pypoetry/virtualenvs/tor-weather-57YGnyhM-py3.9/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2325, in _handle_dbapi_exception
Mar 14 16:50:20 weather-01 poetry[2234085]: raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
Mar 14 16:50:20 weather-01 poetry[2234085]: File "/home/weather/.cache/pypoetry/virtualenvs/tor-weather-57YGnyhM-py3.9/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1964, in _exec_single_context
Mar 14 16:50:20 weather-01 poetry[2234085]: self.dialect.do_execute(
Mar 14 16:50:20 weather-01 poetry[2234085]: File "/home/weather/.cache/pypoetry/virtualenvs/tor-weather-57YGnyhM-py3.9/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 747, in do_execute
Mar 14 16:50:20 weather-01 poetry[2234085]: cursor.execute(statement, parameters)
Mar 14 16:50:20 weather-01 poetry[2234085]: sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "pg_type_typname_nsp_index"
Mar 14 16:50:20 weather-01 poetry[2234085]: DETAIL: Key (typname, typnamespace)=(admin_id_seq, 2200) already exists.
Mar 14 16:50:20 weather-01 poetry[2234085]: [SQL:
Mar 14 16:50:20 weather-01 poetry[2234085]: CREATE TABLE admin (
Mar 14 16:50:20 weather-01 poetry[2234085]: id SERIAL NOT NULL,
Mar 14 16:50:20 weather-01 poetry[2234085]: email VARCHAR(64) NOT NULL,
Mar 14 16:50:20 weather-01 poetry[2234085]: created_on TIMESTAMP WITHOUT TIME ZONE NOT NULL,
Mar 14 16:50:20 weather-01 poetry[2234085]: last_login TIMESTAMP WITHOUT TIME ZONE,
Mar 14 16:50:20 weather-01 poetry[2234085]: PRIMARY KEY (id)
Mar 14 16:50:20 weather-01 poetry[2234085]: )
Mar 14 16:50:20 weather-01 poetry[2234085]: ]
Mar 14 16:50:20 weather-01 poetry[2234085]: (Background on this error at: https://sqlalche.me/e/20/gkpj)
Mar 14 16:50:20 weather-01 poetry[2234085]: [2023-03-14 16:50:20 +0000] [2234085] [INFO] Worker exiting (pid: 2234085)
Mar 14 16:50:20 weather-01 poetry[2234086]: [2023-03-14 16:50:20 +0000] [2234086] [INFO] Worker exiting (pid: 2234086)
Mar 14 16:50:20 weather-01 poetry[2234088]: [2023-03-14 16:50:20 +0000] [2234088] [INFO] Worker exiting (pid: 2234088)
Mar 14 16:50:20 weather-01 poetry[2234089]: [2023-03-14 16:50:20 +0000] [2234089] [INFO] Worker exiting (pid: 2234089)
Mar 14 16:50:20 weather-01 poetry[2234082]: [2023-03-14 16:50:20 +0000] [2234082] [WARNING] Worker with pid 2234087 was terminated due to signal 15
Mar 14 16:50:20 weather-01 poetry[2234082]: [2023-03-14 16:50:20 +0000] [2234082] [INFO] Shutting down: Master
Mar 14 16:50:20 weather-01 poetry[2234082]: [2023-03-14 16:50:20 +0000] [2234082] [INFO] Reason: Worker failed to boot.
Mar 14 16:50:20 weather-01 systemd[1]: tor-weather.service: Main process exited, code=exited, status=3/NOTIMPLEMENTED
Mar 14 16:50:20 weather-01 systemd[1]: tor-weather.service: Failed with result 'exit-code'.
Mar 14 16:50:20 weather-01 systemd[1]: tor-weather.service: Consumed 2.815s CPU time.