krateng / maloja

Self-hosted music scrobble database to create personal listening statistics and charts
https://maloja.krateng.ch
GNU General Public License v3.0
1.18k stars 69 forks source link

PermissionError: [Errno 13] Permission denied: '/var/cache/maloja' #283

Closed DanGarion closed 1 year ago

DanGarion commented 1 year ago

Hello, I have an install that has been running fine for about 6 months. Just recently I noticed the following error when maloja attempts to start.

It appears it is trying to access a volume that doesn't exist. It also wasn't part of the docker-compose that I initially used. This install worked fine for several months and I'm a bit confused as to what occurred in a recent update that would have broken this. My assumption is that I just need to create another volume for /var/cache/maloja?

Here are my current volumes.

volumes:
- "$DOCKERDIR/maloja/config:/etc/maloja"
- "$DOCKERDIR/maloja/data:/var/lib/maloja"
- "$DOCKERDIR/maloja/logs:/var/log/maloja"

This matches up with the current example compose here https://github.com/krateng/maloja/blob/master/example-compose.yml

It appears this started on 10/29/2023.

DanGarion commented 1 year ago

If this helps, even a clean installation has the same issue. I took my compose and created a new installation of Maloja and I got the same error message. If I console into the running container and add the directory and I then see a series of different errors about accessing the database referencing this link https://docs.sqlalchemy.org/en/20/errors.html#error-e3q8. Not sure what is going on at this point.

krateng commented 1 year ago

Please post the full errors you're getting.

DanGarion commented 1 year ago

Here you go.

2023-11-07T17:28:05.410308689Z Maloja is starting! 2023-11-07T17:28:05.473615350Z Traceback (most recent call last): 2023-11-07T17:28:05.473634905Z File "/usr/lib/python3.10/runpy.py", line 187, in _run_module_as_main 2023-11-07T17:28:05.473657674Z mod_name, mod_spec, code = _get_module_details(mod_name, _Error) 2023-11-07T17:28:05.473668779Z File "/usr/lib/python3.10/runpy.py", line 146, in _get_module_details 2023-11-07T17:28:05.473804412Z return _get_module_details(pkg_main_name, error) 2023-11-07T17:28:05.473814259Z File "/usr/lib/python3.10/runpy.py", line 110, in _get_module_details 2023-11-07T17:28:05.473852323Z import(pkg_name) 2023-11-07T17:28:05.473863009Z File "/usr/lib/python3.10/site-packages/maloja/init.py", line 4, in 2023-11-07T17:28:05.473946330Z from .pkg_global import conf 2023-11-07T17:28:05.473957435Z File "/usr/lib/python3.10/site-packages/maloja/pkg_global/conf.py", line 301, in 2023-11-07T17:28:05.474084757Z os.makedirs(path,exist_ok=True) 2023-11-07T17:28:05.474092928Z File "/usr/lib/python3.10/os.py", line 225, in makedirs 2023-11-07T17:28:05.474173456Z mkdir(name, mode) 2023-11-07T17:28:05.474179742Z PermissionError: [Errno 13] Permission denied: '/var/cache/maloja'

krateng commented 1 year ago

Do you have your folders explicitly defined in settings? Like MALOJA_DATA_DIRECTORY or MALOJA_DIRECTORY_CACHE?

DanGarion commented 1 year ago

This is the compose I use. So to answer your question, I would say no...?

services:
  maloja:
    container_name: maloja 
    image: "krateng/maloja:latest"
    restart: unless-stopped
    ports:
    - "42010:42010"
    # different directories for configuration, state and logs
    volumes:
    - "$DOCKERDIR/maloja/config:/etc/maloja"
    - "$DOCKERDIR/maloja/data:/var/lib/maloja"
    - "$DOCKERDIR/maloja/logs:/var/log/maloja"

    environment:
      TZ: $TZ
      PUID: $PUID
      PGID: $PGID
      MALOJA_FORCE_PASSWORD: $PASSWORD
      MALOJA_LASTFM_API_SECRET: $SECRET
      MALOJA_LASTFM_API_KEY: $KEY
      MALOJA_LASTFM_USERNAME: $LASTFM_USERNAME
      MALOJA_LASTFM_PASSWORD: $LASTFM_PASSWORD
      MALOJA_TRACK_SEARCH_PROVIDER: LASTFM
      #MALOJA_METADATA_PROVIDERS: LASTFM
    networks:
      - npm_proxy    
networks:
  npm_proxy:
    external: true

Then I set the variables separately.

PUID=1000
PGID=1000
TZ="America/Los_Angeles"
DOCKERDIR="/mnt/drive4/appdata"
CONTENTDIR="/mnt"
PASSWORD=XXXXX
SECRET=XXXX
KEY=XXXX
LASTFM_USERNAME=XXXX
LASTFM_PASSWORD=XXXX
krateng commented 1 year ago

They might be in your $DOCKERDIR/maloja/config/settings.ini file. If they are there, can you remove the line for cache and try again?

DanGarion commented 1 year ago

Ok, I commented it out and I'm still seeing the same error...

Here are my settings.ini

[MALOJA]
directory_config = /etc/maloja
directory_state = /var/lib/maloja
directory_logs = /var/log/maloja
spotify_api_id = False
spotify_api_secret = False
audiodb_api_key = False
charts_display_tiles = True

2023-11-07T18:13:46.853876699Z Maloja is starting! 2023-11-07T18:13:46.917162036Z Traceback (most recent call last): 2023-11-07T18:13:46.917182081Z File "/usr/lib/python3.10/runpy.py", line 187, in _run_module_as_main 2023-11-07T18:13:46.917277415Z mod_name, mod_spec, code = _get_module_details(mod_name, _Error) 2023-11-07T18:13:46.917296203Z File "/usr/lib/python3.10/runpy.py", line 146, in _get_module_details 2023-11-07T18:13:46.917365905Z return _get_module_details(pkg_main_name, error) 2023-11-07T18:13:46.917376731Z File "/usr/lib/python3.10/runpy.py", line 110, in _get_module_details 2023-11-07T18:13:46.917447830Z import(pkg_name) 2023-11-07T18:13:46.917454116Z File "/usr/lib/python3.10/site-packages/maloja/init.py", line 4, in 2023-11-07T18:13:46.917493646Z from .pkg_global import conf 2023-11-07T18:13:46.917498396Z File "/usr/lib/python3.10/site-packages/maloja/pkg_global/conf.py", line 301, in 2023-11-07T18:13:46.917664410Z os.makedirs(path,exist_ok=True) 2023-11-07T18:13:46.917674956Z File "/usr/lib/python3.10/os.py", line 225, in makedirs 2023-11-07T18:13:46.917762189Z mkdir(name, mode) 2023-11-07T18:13:46.917772316Z PermissionError: [Errno 13] Permission denied: '/var/cache/maloja'

FYI, I also checked the new "fake" install I tested and there was no cache line in its settings.ini already.

krateng commented 1 year ago

Can you run from source by any chance? There should now be some additional info in the logs.

DanGarion commented 1 year ago

Not really, unfortunately, this server is all just running containers I don't do bare metal on it nowadays...

krateng commented 1 year ago

You can still run as a container, just not from dockerhub - you can build from the included Containerfile.

krateng commented 1 year ago

Have you tried creating a volume for /var/cache/maloja as mentioned above? I think that might make it work for now.

DanGarion commented 1 year ago

Have you tried creating a volume for /var/cache/maloja as mentioned above? I think that might make it work for now.

There we go. I set that volume (and then I had to change the permissions on the directory it created). Back up and running. Getting some LastFM invalid response errors but I will figure that one out.

Just in case you want to see that I'm using your awesome app! Thanks!

image

FoxxMD commented 1 year ago

@krateng just tested docker built from your latest commit 44f58e31bcc35ca0d34d72e690f3a5309350da0b

Using the same compose settings (without a volume) I am reproducing the error:


Maloja is starting!

/etc/maloja has been selected as maloja's folder for config

Traceback (most recent call last):

  File "/usr/lib/python3.10/runpy.py", line 187, in _run_module_as_main

    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)

  File "/usr/lib/python3.10/runpy.py", line 146, in _get_module_details

    return _get_module_details(pkg_main_name, error)

  File "/usr/lib/python3.10/runpy.py", line 110, in _get_module_details

    __import__(pkg_name)

  File "/usr/lib/python3.10/site-packages/maloja/__init__.py", line 4, in <module>

    from .pkg_global import conf

  File "/usr/lib/python3.10/site-packages/maloja/pkg_global/conf.py", line 259, in <module>

    find_good_folder(datatype,malojaconfig)

  File "/usr/lib/python3.10/site-packages/maloja/pkg_global/conf.py", line 102, in find_good_folder

    raise PermissionError(f"No folder could be found for {datatype}")

PermissionError: No folder could be found for cache

This does not occur if MALOJA_DATA_DIRECTORY or (Data Directory in settings) is set because then the config folder is set as MALOJA_DATA_DIRECTORY/config

EDIT: I suspect the original permission denied error is due to folder ownership. The image is built with /var/cache owned by root but the maloja process is run under abc UID/GID 1000:1000 image

krateng commented 1 year ago

Yeah I thought it would fall through to .local/share/maloja/cache then, but maybe this doesn't exist? In any case I'm probably gonna follow linuxserver.io specs and use /config for containers when nothing is specified.

FoxxMD commented 1 year ago

LSIO doesn't really have the concept of a $HOME folder which is why it isn't working, perhaps.

Could also do this

Create folder and modify permissions during image build

Add these commands to Containerfile somewhere before the end

RUN mkdir /var/cache/maloja && chown -R 777 # give read/write permissions to everyone

It's pretty permissive but will ensure abc can use the folder regardless of uid.

Using /config

Probably the better option. Though please make sure its a subfolder (/config/cache) and do a check to make sure its not already in use for MALOJA_DATA_DIRECTORY beforehand.

undaunt commented 12 months ago

I think this may be related to a change in the container if the container recently implemented LSIO style PUID/PGID. I looked at my compose and was previously using:

  maloja:
    image: krateng/maloja
    container_name: maloja
    <<: *common-apps
    user: $PUID:$PGID
    volumes:
      - $DOCKERDIR/maloja:/data
    environment:
      - MALOJA_DATA_DIRECTORY=/data

Even after adding skip setup, I was still getting mkdir and suid errors. After changing to the below, it started working again:

    image: krateng/maloja
    container_name: maloja
    <<: *common-apps
    volumes:
      - $DOCKERDIR/maloja:/data
    environment:
      - PUID
      - PGID
      - MAOLJA_SKIP_SETUP=true
      - MALOJA_DATA_DIRECTORY=/data