Uptime-Kuma-Web-API icon indicating copy to clipboard operation
Uptime-Kuma-Web-API copied to clipboard

Error on Docker Boot

Open reisdiegoss opened this issue 1 year ago • 3 comments

Error from log container:

return await func(self, query, *args)

File "/app/venv/lib/python3.9/site-packages/tortoise/backends/sqlite/client.py", line 153, in execute_script async with self.acquire_connection() as connection: File "/app/venv/lib/python3.9/site-packages/tortoise/backends/base/client.py", line 220, in aenter await self.ensure_connection() File "/app/venv/lib/python3.9/site-packages/tortoise/backends/base/client.py", line 216, in ensure_connection await self.client.create_connection(with_db=True) File "/app/venv/lib/python3.9/site-packages/tortoise/backends/sqlite/client.py", line 69, in create_connection await self._connection._connect() File "/app/venv/lib/python3.9/site-packages/aiosqlite/core.py", line 137, in _connect self.connection = await future File "/app/venv/lib/python3.9/site-packages/aiosqlite/core.py", line 102, in run result = function() File "/app/venv/lib/python3.9/site-packages/aiosqlite/core.py", line 397, in connector return sqlite3.connect(loc, **kwargs) sqlite3.OperationalError: unable to open database file During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/app/venv/lib/python3.9/site-packages/starlette/routing.py", line 645, in lifespan async with self.lifespan_context(app): File "/app/venv/lib/python3.9/site-packages/starlette/routing.py", line 540, in aenter await self.router.startup() File "/app/venv/lib/python3.9/site-packages/starlette/routing.py", line 622, in startup await handler() File "/app/main.py", line 41, in startup_event await initialize_app(app) File "/app/app_setup.py", line 10, in initialize_app await setup_database() File "/app/app_setup.py", line 29, in setup_database await Tortoise.generate_schemas() File "/app/venv/lib/python3.9/site-packages/tortoise/init.py", line 636, in generate_schemas await generate_schema_for_client(connection, safe) File "/app/venv/lib/python3.9/site-packages/tortoise/utils.py", line 31, in generate_schema_for_client await generator.generate_from_string(schema) File "/app/venv/lib/python3.9/site-packages/tortoise/backends/base/schema_generator.py", line 448, in generate_from_string await self.client.execute_script(creation_string) File "/app/venv/lib/python3.9/site-packages/tortoise/backends/sqlite/client.py", line 36, in translate_exceptions raise OperationalError(exc) tortoise.exceptions.OperationalError: unable to open database file [2023-05-17 18:21:24 +0000] [7] [ERROR] Application startup failed. Exiting. [2023-05-17 18:21:24 +0000] [7] [INFO] Worker exiting (pid: 7) [2023-05-17 18:21:24 +0000] [1] [INFO] Shutting down: Master [2023-05-17 18:21:24 +0000] [1] [INFO] Reason: Worker failed to boot. [2023-05-17 18:21:31 +0000] [1] [INFO] Starting gunicorn 20.1.0 [2023-05-17 18:21:31 +0000] [1] [INFO] Listening at: http://0.0.0.0:8000 (1) [2023-05-17 18:21:31 +0000] [1] [INFO] Using worker: uvicorn.workers.UvicornWorker [2023-05-17 18:21:31 +0000] [7] [INFO] Booting worker with pid: 7 [2023-05-17 18:21:31 +0000] [7] [INFO] Started server process [7] [2023-05-17 18:21:31 +0000] [7] [INFO] Waiting for application startup. [2023-05-17 18:21:32 +0000] [7] [ERROR] Traceback (most recent call last): File "/app/venv/lib/python3.9/site-packages/tortoise/backends/sqlite/client.py", line 34, in translate_exceptions return await func(self, query, *args) File "/app/venv/lib/python3.9/site-packages/tortoise/backends/sqlite/client.py", line 153, in execute_script async with self.acquire_connection() as connection: File "/app/venv/lib/python3.9/site-packages/tortoise/backends/base/client.py", line 220, in aenter await self.ensure_connection() File "/app/venv/lib/python3.9/site-packages/tortoise/backends/base/client.py", line 216, in ensure_connection await self.client.create_connection(with_db=True) File "/app/venv/lib/python3.9/site-packages/tortoise/backends/sqlite/client.py", line 69, in create_connection await self._connection._connect() File "/app/venv/lib/python3.9/site-packages/aiosqlite/core.py", line 137, in _connect self._connection = await future File "/app/venv/lib/python3.9/site-packages/aiosqlite/core.py", line 102, in run result = function() File "/app/venv/lib/python3.9/site-packages/aiosqlite/core.py", line 397, in connector return sqlite3.connect(loc, **kwargs) sqlite3.OperationalError: unable to open database file During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/app/venv/lib/python3.9/site-packages/starlette/routing.py", line 645, in lifespan async with self.lifespan_context(app): File "/app/venv/lib/python3.9/site-packages/starlette/routing.py", line 540, in aenter await self.router.startup() File "/app/venv/lib/python3.9/site-packages/starlette/routing.py", line 622, in startup await handler() File "/app/main.py", line 41, in startup_event await initialize_app(app) File "/app/app_setup.py", line 10, in initialize_app await setup_database() File "/app/app_setup.py", line 29, in setup_database await Tortoise.generate_schemas() File "/app/venv/lib/python3.9/site-packages/tortoise/init.py", line 636, in generate_schemas await generate_schema_for_client(connection, safe) File "/app/venv/lib/python3.9/site-packages/tortoise/utils.py", line 31, in generate_schema_for_client await generator.generate_from_string(schema) File "/app/venv/lib/python3.9/site-packages/tortoise/backends/base/schema_generator.py", line 448, in generate_from_string await self.client.execute_script(creation_string) File "/app/venv/lib/python3.9/site-packages/tortoise/backends/sqlite/client.py", line 36, in translate_exceptions raise OperationalError(exc) tortoise.exceptions.OperationalError: unable to open database file [2023-05-17 18:21:32 +0000] [7] [ERROR] Application startup failed. Exiting. [2023-05-17 18:21:32 +0000] [7] [INFO] Worker exiting (pid: 7) [2023-05-17 18:21:32 +0000] [1] [INFO] Shutting down: Master [2023-05-17 18:21:32 +0000] [1] [INFO] Reason: Worker failed to boot.

My Docker Compose is:

version: "3.9"
services:
  api:
    build: .
    #image: medaziz11/uptimekuma_restapi
    volumes:
      - ./db:/db:rwx
    container_name: kuma_restapi
    restart: always
    networks:
      - network_public
    environment:
      - KUMA_SERVER=${KUMA_SERVER:-http://kuma:3001}
      - KUMA_USERNAME=${KUMA_USERNAME:-USER}
      - KUMA_PASSWORD=${KUMA_PASSWORD:-PASSWORD}
      - ADMIN_PASSWORD=${ADMIN_PASSWORD:-PASSWORD}
      # - ACCESS_TOKEN_EXPIRATION=${ACCESS_TOKEN_EXPIRATION:-1}
      - SECRET_KEY=${SECRET_KEY:-uk2_FYWegoBdM9aAUJAJ5c6AVz3rtCwT2yglQGMxWyT1} #random 32bit string that's url safe.

reisdiegoss avatar May 17 '23 18:05 reisdiegoss

Long story short, it boils down to incorrect permissions on the volume where the sqlite database file is stored. The author tried to set the volume to rwx with the line on the docker-compose.yml that says:

  volumes:
    - ./db:/db:rwx

but that is likely throwing errors because ro is valid and rw is valid, but I don't think rwx is valid

A way to work around this is to set the db folder to have the correct permissions. There are many ways to accomplish this, but the following command should work best and be least amount of changed permissions.

  1. Stop the backend container
  2. mount up another container, like busybox or similar, with the api volume attached so you can modify permissions. Something like docker run --rm -it -v your-kuma-api-volume:/kuma alpine chown -R 100 /kuma
  3. stop the other container
  4. re-run docker-compose up

Everything should boot up at this point.

More discussion here: https://github.com/MedAziz11/Uptime-Kuma-Web-API/issues/33

There's a PR waiting that addresses this: https://github.com/MedAziz11/Uptime-Kuma-Web-API/pull/37 Or you van visit the fork here: https://github.com/zacharyfleck/Uptime-Kuma-Web-API/tree/fix/db-dir-perms, grab the code, and build your own docker image

tigunia-martin avatar May 25 '23 17:05 tigunia-martin

@tigunia-martin thanks for the fix, I think it's easier to change permissions on the folder: chmod -R 777 db for example. This works only if you have acces to OS and terminal.

Works for me and should for others too. This can be done through entrypoint.sh as well, as extra one command line.

markosole avatar Jul 03 '23 15:07 markosole

docker run --rm -it -v ./api_db:/db alpine chown -R 100 /db worked for me

atribe avatar May 06 '24 03:05 atribe