RaunoT / plex-rewind

Present Plex user statistics and habits in a beautiful and organized manner.
GNU General Public License v3.0
155 stars 7 forks source link

Permission denied when creating settings.json #144

Closed sincrack closed 1 month ago

sincrack commented 1 month ago

Plex Rewind Version

Latest

Description

where is the settings file?

Steps to reproduce

Config docker

Screenshots

No response

Logs

No response

Platform

desktop

Device

PC

Operating System

Windows 11

Browser and version

Chrome latests

Additional context

No response

RaunoT commented 1 month ago

The settings file should be auto-generated upon first launch. Please provide log output from docker ps and docker logs <container-id>

PatrickDollard commented 1 month ago

I have the same issue on Unraid.

Failed to handle settings file: Error: EACCES: permission denied, open '/app/config/settings.json'
    at async open (node:internal/fs/promises:639:25)
    at async Object.writeFile (node:internal/fs/promises:1219:14)
    at async n (/app/.next/server/chunks/529.js:7:5346)
    at async p (/app/.next/server/app/page.js:1:253255) {
  errno: -13,
  code: 'EACCES',
  syscall: 'open',
  path: '/app/config/settings.json'
}
Error: Unexpected error handling settings file
    at n (/app/.next/server/chunks/529.js:7:5576)
    at async p (/app/.next/server/app/page.js:1:253255) {
  digest: '3340238426'
}
Failed to handle settings file: Error: EACCES: permission denied, open '/app/config/settings.json'
    at async open (node:internal/fs/promises:639:25)
    at async Object.writeFile (node:internal/fs/promises:1219:14)
    at async n (/app/.next/server/chunks/529.js:7:5346)
    at async x (/app/.next/server/chunks/529.js:7:652) {
  errno: -13,
  code: 'EACCES',
  syscall: 'open',
  path: '/app/config/settings.json'
}
Error: Unexpected error handling settings file
    at n (/app/.next/server/chunks/529.js:7:5576)
    at async x (/app/.next/server/chunks/529.js:7:652) {
  digest: '4155864519'
}
Error: Unexpected error handling settings file
    at n (/app/.next/server/chunks/529.js:7:5576)
    at async x (/app/.next/server/chunks/529.js:7:652) {
  digest: '4155864519'
}``

I've set the container to privileged with no luck.

stukinnear commented 1 month ago

I chmod 777 config/settings.json - made my change, saved then reset to 665.

On Thu, 18 Jul 2024 at 08:35, PatrickDollard @.***> wrote:

I have the same issue on Unraid.

Failed to handle settings file: Error: EACCES: permission denied, open '/app/config/settings.json' at async open (node:internal/fs/promises:639:25) at async Object.writeFile (node:internal/fs/promises:1219:14) at async n (/app/.next/server/chunks/529.js:7:5346) at async p (/app/.next/server/app/page.js:1:253255) { errno: -13, code: 'EACCES', syscall: 'open', path: '/app/config/settings.json' } Error: Unexpected error handling settings file at n (/app/.next/server/chunks/529.js:7:5576) at async p (/app/.next/server/app/page.js:1:253255) { digest: '3340238426' } Failed to handle settings file: Error: EACCES: permission denied, open '/app/config/settings.json' at async open (node:internal/fs/promises:639:25) at async Object.writeFile (node:internal/fs/promises:1219:14) at async n (/app/.next/server/chunks/529.js:7:5346) at async x (/app/.next/server/chunks/529.js:7:652) { errno: -13, code: 'EACCES', syscall: 'open', path: '/app/config/settings.json' } Error: Unexpected error handling settings file at n (/app/.next/server/chunks/529.js:7:5576) at async x (/app/.next/server/chunks/529.js:7:652) { digest: '4155864519' } Error: Unexpected error handling settings file at n (/app/.next/server/chunks/529.js:7:5576) at async x (/app/.next/server/chunks/529.js:7:652) { digest: '4155864519' }``

I've set the container to privileged with no luck.

— Reply to this email directly, view it on GitHub https://github.com/RaunoT/plex-rewind/issues/144#issuecomment-2235827591, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH22XJKIO7BUKJ5ZPM3T3VDZM5V3NAVCNFSM6AAAAABLCBYRJOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMZVHAZDONJZGE . You are receiving this because you are subscribed to this thread.Message ID: @.***>

RaunoT commented 1 month ago

I think the issue is that nextjs should be the owner of the file, not nodejs

Please try the following image (make sure you dont already have a settings.json locally) and let me know if it works - ghcr.io/raunot/plex-rewind:447747b835cd8b6c5490b2c9d235ac344177e95f

nwithan8 commented 1 month ago

I think the issue is that nextjs should be the owner of the file, not nodejs

Please try the following image (make sure you dont already have a settings.json locally) and let me know if it works - ghcr.io/raunot/plex-rewind:447747b835cd8b6c5490b2c9d235ac344177e95f

That new container doesn't fix the issue. The issue is likely on the Unraid side of things, as the "config" path that's getting passed in is using the host system (Unraid) user:group permissions, which is different than the nextjs:nodejs permissions:

image
zahidhanif commented 1 month ago

I'm also having the same problem with a non-root docker deployment. My log errors were the same as the OP

RaunoT commented 1 month ago

Anyone running into this issue, please try the image based on #162 ghcr.io/raunot/plex-rewind:2888fc187e387969310d15ead63fbad7fa171f9b

pedroalmaguer commented 1 month ago

Still running in to the same permission error.

zahidhanif commented 1 month ago

I'm also having the same problem with a non-root docker deployment. My log errors were the same as the OP

After removing the config directory and files, I manually created the settings file and it worked. I see there is a new docker image and tested that but getting same permissions issue after clearing everything out.

jjscaria commented 1 month ago

I'm also having the same problem with a non-root docker deployment. My log errors were the same as the OP

same here on Debian 12 with non-root docker deployment

Anyone running into this issue, please try the image based on #162 [ghcr.io/raunot/plex-rewind:2888fc187e387969310d15ead63fbad7fa171f9b](http://ghcr.io/raunot/plex-rewind:2888fc187e387969310d15ead63fbad7fa171f9b)

This didnt work either

sideh commented 1 month ago

I think the issue is that nextjs should be the owner of the file, not nodejs

That new container doesn't fix the issue. The issue is likely on the Unraid side of things, as the "config" path that's getting passed in is using the host system (Unraid) user:group permissions, which is different than the nextjs:nodejs permissions:

@nwithan8 Just want to say, the link in in Unraid to the settings.json file doesn't work. Leads to no where.

https://github.com/RaunoT/plex-rewind/blob/develop/config/settings.json

I found one but rather get one that I am directed to. Sorry if this isn't the appropiate place for this information.

RaunoT commented 1 month ago

@nwithan8 Regarding Unraid, is there anything we can learn from Overseerr installation docs about this?

Specifically this part about configuring appdata:

On the following Add Container screen, make changes to the Host Port and Host Path 1(Appdata) as needed.

The general config creation and volume mounting logic is otherwise actually quite similar to Overseerr, as it was something I drew inspiration from during the development of this functionality.

Unfortunately, I don't have too much experience with different Linux distros. Any input that gets us closer to solving this issue is very welcome!

hflatoey commented 1 month ago

Anyone running into this issue, please try the image based on #162 ghcr.io/raunot/plex-rewind:2888fc187e387969310d15ead63fbad7fa171f9b

This worked for me on unRAID.

modem7 commented 1 month ago

ghcr.io/raunot/plex-rewind:2888fc187e387969310d15ead63fbad7fa171f9b seems to have fixed the settings.json issue, however:

Failed to update prerender cache for 13f6ac5f058c9b663b3f4be14b23e583900e870fe09a3f4e32d7deee1562497c Error: EACCES: permission denied, mkdir '/app/.next/cache'
    at async Object.mkdir (node:internal/fs/promises:858:10)
    at async FileSystemCache.set (/app/node_modules/.pnpm/next@14.2.5_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/lib/incremental-cache/file-system-cache.js:276:13)
    at async IncrementalCache.set (/app/node_modules/.pnpm/next@14.2.5_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/lib/incremental-cache/index.js:411:13)
    at async /app/node_modules/.pnpm/next@14.2.5_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:33864
    at async l (/app/.next/server/app/api/auth/[...nextauth]/route.js:1:5393)
    at async /app/.next/server/app/rewind/page.js:1:46573
    at async Promise.all (index 5)
    at async a (/app/.next/server/app/rewind/page.js:1:46530)
    at async o (/app/.next/server/app/dashboard/[slug]/page.js:1:4760)
    at async Promise.all (index 0) {
  errno: -13,
  code: 'EACCES',
  syscall: 'mkdir',
  path: '/app/.next/cache'
}

I've even tried running it as a particular user.

  plexrewind:
    # image: ghcr.io/raunot/plex-rewind
    image: ghcr.io/raunot/plex-rewind:2888fc187e387969310d15ead63fbad7fa171f9b
    container_name: Plex-Rewind
    user: $PUID:$PGID
    environment:
      - NEXTAUTH_SECRET=$PRW_NEXTAUTH_SECRET # (required) used to encrypt auth JWT token, generate one with `openssl rand -base64 32`
      - NEXTAUTH_URL=https://plexrewind.$DOMAINNAME # change to your domain if you are exposing the app to the internet
      - NEXT_PUBLIC_SITE_URL=https://plexrewind.$DOMAINNAME # change to your domain if you are exposing the app to the internet
      - NEXT_PUBLIC_STATISTICS_START_DATE=2018-01-01 # starting date for "all time" option (YYYY-MM-DD)
    volumes:
      - $USERDIR/PlexRewind:/app/config
    networks:
      pihole:
        ipv4_address: '172.22.0.116'
    ports:
      - 8383:8383
RaunoT commented 1 month ago

@hflatoey and @modem7 thanks for testing, this is of great help. Could you please try a clean install with ghcr.io/raunot/plex-rewind:4282e388feabd5245996ea307a35855402451a99 and see if any issues persist? Hopefully this new image will clear up any cache issues also.

RaunoT commented 1 month ago

@hflatoey and @modem7 thanks for testing, this is of great help. Could you please try a clean install with ghcr.io/raunot/plex-rewind:4282e388feabd5245996ea307a35855402451a99 and see if any issues persist? Hopefully this new image will clear up any cache issues also.

EDIT: the correct image is ghcr.io/raunot/plex-rewind:7b2d68f7494861956ce3bf008ad6e614eb2b1ea8

hflatoey commented 1 month ago

I did a clean install and now it created the setting file in unRAID but I gave my url to a few friends of mine and one of them broke it right away by changing the API key in settings...

I was wrong, I just checked the log for errors and didn't see any so I though it had created it, none of them creates a setting file for me in unRAID.

RaunoT commented 1 month ago

I was wrong, I just checked the log for errors and didn't see any so I though it had created it, none of them creates a setting file for me in unRAID.

The settings file will not be created on install, but rather when visiting the app in the browser for the first time. The app then creates a settings.json if it doesn't exist already on the volume mount. If creation is not successful, you should have an error in the logs, as the app cannot run without it.

hflatoey commented 1 month ago

Application error: a server-side exception has occurred (see the server logs for more information). Digest: 1762202026

ghcr.io/raunot/plex-rewind:4282e388feabd5245996ea307a35855402451a99

`Settings file not found. Creating a new one. Settings file not found. Creating a new one. Failed to handle settings file: Error: EACCES: permission denied, open '/app/config/settings.json' at async open (node:internal/fs/promises:639:25) at async Object.writeFile (node:internal/fs/promises:1219:14) at async a (/app/.next/server/app/page.js:8:1799) at async p (/app/.next/server/app/page.js:7:1996) { errno: -13, code: 'EACCES', syscall: 'open', path: '/app/config/settings.json' } Failed to handle settings file: Error: EACCES: permission denied, open '/app/config/settings.json' at async open (node:internal/fs/promises:639:25) at async Object.writeFile (node:internal/fs/promises:1219:14) at async a (/app/.next/server/app/page.js:8:1799) at async (/app/.next/server/app/page.js:7:650) { errno: -13, code: 'EACCES', syscall: 'open', path: '/app/config/settings.json' } Error: Unexpected error handling settings file at a (/app/.next/server/app/page.js:8:2029) at async p (/app/.next/server/app/page.js:7:1996) { digest: '606872913' } Error: Unexpected error handling settings file at a (/app/.next/server/app/page.js:8:2029) at async (/app/.next/server/app/page.js:7:650) { digest: '1762202026' } Error: Unexpected error handling settings file at a (/app/.next/server/app/page.js:8:2029) at async (/app/.next/server/app/page.js:7:650) { digest: '1762202026' } Settings file not found. Creating a new one. Settings file not found. Creating a new one. Failed to handle settings file: Error: EACCES: permission denied, open '/app/config/settings.json' at async open (node:internal/fs/promises:639:25) at async Object.writeFile (node:internal/fs/promises:1219:14) at async a (/app/.next/server/app/page.js:8:1799) at async p (/app/.next/server/app/page.js:7:1996) { errno: -13, code: 'EACCES', syscall: 'open', path: '/app/config/settings.json' } Failed to handle settings file: Error: EACCES: permission denied, open '/app/config/settings.json' at async open (node:internal/fs/promises:639:25) at async Object.writeFile (node:internal/fs/promises:1219:14) at async a (/app/.next/server/app/page.js:8:1799) at async (/app/.next/server/app/page.js:7:650) { errno: -13, code: 'EACCES', syscall: 'open', path: '/app/config/settings.json' } Error: Unexpected error handling settings file at a (/app/.next/server/app/page.js:8:2029) at async p (/app/.next/server/app/page.js:7:1996) { digest: '606872913' } Error: Unexpected error handling settings file at a (/app/.next/server/app/page.js:8:2029) at async (/app/.next/server/app/page.js:7:650) { digest: '1762202026' } Error: Unexpected error handling settings file at a (/app/.next/server/app/page.js:8:2029) at async (/app/.next/server/app/page.js:7:650) { digest: '1762202026' } ▲ Next.js 14.2.5

ghcr.io/raunot/plex-rewind:7b2d68f7494861956ce3bf008ad6e614eb2b1ea8

`Settings file not found. Creating a new one. Settings file not found. Creating a new one. Failed to handle settings file: Error: EACCES: permission denied, open '/app/config/settings.json' at async open (node:internal/fs/promises:639:25) at async Object.writeFile (node:internal/fs/promises:1219:14) at async a (/app/.next/server/app/page.js:8:1799) at async p (/app/.next/server/app/page.js:7:1996) { errno: -13, code: 'EACCES', syscall: 'open', path: '/app/config/settings.json' } Failed to handle settings file: Error: EACCES: permission denied, open '/app/config/settings.json' at async open (node:internal/fs/promises:639:25) at async Object.writeFile (node:internal/fs/promises:1219:14) at async a (/app/.next/server/app/page.js:8:1799) at async (/app/.next/server/app/page.js:7:650) { errno: -13, code: 'EACCES', syscall: 'open', path: '/app/config/settings.json' } Error: Unexpected error handling settings file at a (/app/.next/server/app/page.js:8:2029) at async p (/app/.next/server/app/page.js:7:1996) { digest: '606872913' } Error: Unexpected error handling settings file at a (/app/.next/server/app/page.js:8:2029) at async (/app/.next/server/app/page.js:7:650) { digest: '1762202026' } Error: Unexpected error handling settings file at a (/app/.next/server/app/page.js:8:2029) at async _ (/app/.next/server/app/page.js:7:650) { digest: '1762202026' } ▲ Next.js 14.2.5

RaunoT commented 1 month ago

@hflatoey Can you see a config directory being created next to the docker-compose.yml after you run docker compose up?

modem7 commented 1 month ago

I haven't had time to test this, but I did come across this:

https://forum.codewithmosh.com/t/docker-npm-permission-denied/4766/6

Specifically the default user alpine uses overrides users.

This may be a red herring, but thought I'd share it just in case.

Will try to test any requests tonight.

hflatoey commented 1 month ago

@hflatoey Can you see a config directory being created next to the docker-compose.yml after you run docker compose up?

I don't use docker compose, I used the "app store" in unRAID.

image

modem7 commented 1 month ago

@hflatoey and @modem7 thanks for testing, this is of great help. Could you please try a clean install with ghcr.io/raunot/plex-rewind:4282e388feabd5245996ea307a35855402451a99 and see if any issues persist? Hopefully this new image will clear up any cache issues also.

EDIT: the correct image is ghcr.io/raunot/plex-rewind:7b2d68f7494861956ce3bf008ad6e614eb2b1ea8

No errors now, however, no images either:

image

▲ Next.js 14.2.5
  - Local:        http://localhost:8383
  - Network:      http://0.0.0.0:8383/
all values are hidden
 ✓ Starting...
 ✓ Ready in 62ms
RaunoT commented 1 month ago

No errors now, however, no images either:

That's some progress at least I guess :D Anything in the browser console regarding images (right click, inspect, console tab)?

github-actions[bot] commented 1 month ago

:tada: This issue has been resolved in version 2.3.1-develop.1 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

RaunoT commented 1 month ago

:tada: This issue has been resolved in version 2.3.1 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

jjscaria commented 1 month ago

Im still getting the error with the new image on Debian 12 with non-root docker deployment:

▲ Next.js 14.2.5
  - Local:        http://localhost:8383/
  - Network:      http://0.0.0.0:8383/

    all values are hidden

 ✓ Starting...
 ✓ Ready in 42ms
Settings file not found. Creating a new one.
Settings file not found. Creating a new one.
Error: Unexpected error handling settings file
    at a (/app/.next/server/app/page.js:8:1831)
    at async p (/app/.next/server/app/page.js:7:1996) {
  digest: '131405523'
}
Error: Unexpected error handling settings file
    at a (/app/.next/server/app/page.js:8:1831)
    at async _ (/app/.next/server/app/page.js:7:650) {
  digest: '1499927976'
}
Error: Unexpected error handling settings file
    at a (/app/.next/server/app/page.js:8:1831)
    at async _ (/app/.next/server/app/page.js:7:650) {
  digest: '1499927976'
}
nwithan8 commented 1 month ago

@RaunoT Sorry I've been absent on this thread. I tried to no avail to figure out what exactly is causing the permission discrepancy and a way to alter them. I do think I found a way around the issue:

The Unraid template has been updated to, instead of mount a folder to /app/config, to mount a file at /app/config/settings.json. A prerequisite note on the container instructs users will need to download the settings.json file (backed up here since you have since deleted it) and place it on their host filesystem BEFORE starting the container. Unfortunately, if the file doesn't exist, Docker will treat the path as a directory mapping rather than a file mapping and will accidentally create an unnecessary folder that users will have to delete.

In initial testing, it seemed that this worked. Anyone who has tried it, please feel free to chime in.

I apologize that, in attempts to fix this issue that seemed to be contained to only Unraid Community Apps, that this has now extended to traditional Docker Compose installations (re: #170)

RaunoT commented 1 month ago

@nwithan8 No worries and thanks for getting back to me.

If that's a way we can work around the issues on Unraid, perhaps you could open a PR to update the README and create a settings-example.json for it in this repo also when you have some free time 🙏

I added the original settings.json to .gitignore to avoid any chance of accidentaly commiting a file with my personal keys while developing. If including it in the repo (as before) would lessen the troubles and simplify the setup on Unraid, I'm open to adding it back.

jjscaria commented 1 month ago

@RaunoT Sorry I've been absent on this thread. I tried to no avail to figure out what exactly is causing the permission discrepancy and a way to alter them. I do think I found a way around the issue:

The Unraid template has been updated to, instead of mount a folder to /app/config, to mount a file at /app/config/settings.json. A prerequisite note on the container instructs users will need to download the settings.json file (backed up here since you have since deleted it) and place it on their host filesystem BEFORE starting the container. Unfortunately, if the file doesn't exist, Docker will treat the path as a directory mapping rather than a file mapping and will accidentally create an unnecessary folder that users will have to delete.

In initial testing, it seemed that this worked. Anyone who has tried it, please feel free to chime in.

I apologize that, in attempts to fix this issue that seemed to be contained to only Unraid Community Apps, that this has now extended to traditional Docker Compose installations (re: #170)

I didnt change the mount point but, copied that settings file, then recreated the container and got to the connection settings page.

When I try to save the settings, I am getting "Something went wrong!" and the log shows the following:

Error writing to settings file! Error: EACCES: permission denied, open '/app/config/settings.json'
    at async open (node:internal/fs/promises:639:25)
    at async Object.writeFile (node:internal/fs/promises:1219:14)
    at async d (/app/.next/server/app/settings/connection/page.js:1:8841)
    at async /app/node_modules/.pnpm/next@14.2.5_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:16:418
    at async rR (/app/node_modules/.pnpm/next@14.2.5_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:15:7978)
    at async r7 (/app/node_modules/.pnpm/next@14.2.5_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:18:1144)
    at async doRender (/app/node_modules/.pnpm/next@14.2.5_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/base-server.js:1438:30)
    at async cacheEntry.responseCache.get.routeKind (/app/node_modules/.pnpm/next@14.2.5_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/base-server.js:1599:28)
    at async NextNodeServer.renderToResponseWithComponentsImpl (/app/node_modules/.pnpm/next@14.2.5_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/base-server.js:1507:28)
    at async NextNodeServer.renderPageComponent (/app/node_modules/.pnpm/next@14.2.5_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/base-server.js:1931:24) {
  errno: -13,
  code: 'EACCES',
  syscall: 'open',
  path: '/app/config/settings.json'
}