Drapersniper / Qbitrr

A simple Python script to talk to Qbit and Arr's
MIT License
27 stars 4 forks source link

attempt to write a readonly database #59

Closed Skyline404 closed 1 year ago

Skyline404 commented 2 years ago

I'm using docker version of the script, mounted db files like this:

   - ${DOCKERDIR}/sonarr/config/sonarr.db:/sonarr/sonarr.db:ro 
   - ${DOCKERDIR}/radarr/config/radarr.db:/radarr/radarr.db:ro

but getting errors on container start:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 3160, in execute_sql
    cursor.execute(sql, params or ())
sqlite3.OperationalError: attempt to write a readonly database

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/multiprocess/process.py", line 315, in _bootstrap
    self.run()
  File "/usr/local/lib/python3.10/site-packages/multiprocess/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.10/site-packages/qBitrr/arss.py", line 2985, in run_search_loop
    self.db_update()
  File "/usr/local/lib/python3.10/site-packages/qBitrr/arss.py", line 1295, in db_update
    self.db_update_todays_releases()
  File "/usr/local/lib/python3.10/site-packages/qBitrr/arss.py", line 1280, in db_update_todays_releases
    for series in self.model_arr_file.select().where(
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 6923, in __iter__
    self.execute()
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 1911, in inner
    return method(self, database, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 1982, in execute
    return self._execute(database)
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 2155, in _execute
    cursor = database.execute(self)
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 3173, in execute
    return self.execute_sql(sql, params, commit=commit)
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 3157, in execute_sql
    with __exception_wrapper__:
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 2933, in __exit__
    reraise(new_type, new_type(exc_value, *exc_args), traceback)
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 191, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 3160, in execute_sql
    cursor.execute(sql, params or ())
peewee.OperationalError: attempt to write a readonly database
Drapersniper commented 2 years ago

Can you please share your full docker start up command/docker compose file for this image.

Feel free to obfuscate any PII but keep the fields there so I can see what is being set.

Would also like to see the permission on those 2 db files

Skyline404 commented 2 years ago

docker-compose:

  qbitrr:
    image: drapersniper/qbitrr
    container_name: qbitrr
    user: ${PUID}:${PGID} # Required to ensure teh container is run as the user who has perms to see the 2 mount points and the ability to write to the CompletedDownloadFolder mount
    tty: true # Ensure the output of docker-compose logs qbitrr are properly colored.
    restart: unless-stopped
    depends_on: # Not needed but this ensures qBitrr only starts if the dependencies are up and running
      - qbittorrent
      - sonarr
      - radarr
    security_opt:
      - no-new-privileges:true
    network_mode: 'service:gluetun'
    environment:
      - TZ=${TZ}
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - ${DOCKERDIR}/qbitrr/config:/config # All qbitrr files are stored in the `/config` folder when using a docker container
      - ${DOCKERDIR}/sonarr/config/sonarr.db:/sonarr/sonarr.db # This is only needed if you want episode search handling :ro means it is only ever mounted as a read-only folder, the script never needs more than read access
      - ${DOCKERDIR}/radarr/config/radarr.db:/radarr/radarr.db # This is only needed if you want movie search handling, :ro means it is only ever mounted as a read-only folder, the script never needs more than read access
      - ${STORAGE}/complete:/data/complete:rw # The script will ALWAYS require write permission in this folder if mounted, this folder is used to monitor completed downloads and if not present will cause the script to ignore downloaded file monitoring.

config: link

compose: link

permissions on db files everywhere the same: .rwxrwxr--

Drapersniper commented 2 years ago

Soo looking at the code and the tracebacks these sections aren't trying to write ... having a quick look online about the root issue sqlite3.OperationalError: attempt to write a readonly database

It appears to be somewhat of what I was expecting:

Skyline404 commented 2 years ago

Error is definitely in permissions, DB files mounting with root-only permissions, so if I start the container as root it will work just fine.

Drapersniper commented 2 years ago

When I get home i'll double check the docker image to see if the permissions are being broken during container creation - I don't run as root and I don't have any issues but just in case.

Just to clarify it, it's probably one of the parent folders with the incorrect perms rather than the file themselves given that the files have rwxrwxr-- i.e 774

Maybe one of the parent folder has something like rwx------ i.e 700

Skyline404 commented 2 years ago

Created folder and mounted DB files inside are owned by root:

Drapersniper commented 2 years ago

Hmm in that case the files should still have read access .. can you cd up one directory and run ls -la . I'm wondering what the perms are in the actual folders

Skyline404 commented 2 years ago

Permissions inside a container are right 1000:993, but still, he can't work with the database, strange, only if I mount DB files in the exposed "/config" folder and then manually change owner on host bind from root to 1000:993 it starts to work.

Drapersniper commented 1 year ago

Due to no further reports, will be closing this. Please reopen if it happens again, but it seems like a permission issue.