Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on Docker Boot #38

Open
reisdiegoss opened this issue May 17, 2023 · 3 comments
Open

Error on Docker Boot #38

reisdiegoss opened this issue May 17, 2023 · 3 comments

Comments

@reisdiegoss
Copy link

reisdiegoss commented May 17, 2023

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.

@tigunia-martin
Copy link

tigunia-martin commented May 25, 2023

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:
#33

There's a PR waiting that addresses this:
#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

@markosole
Copy link

@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.

@atribe
Copy link

atribe commented May 6, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants