ahembree / ansible-hms-docker

Ansible playbook for automated home media server setup
GNU General Public License v3.0
407 stars 51 forks source link

Plex container doesn't start properly #88

Closed xavpitz closed 1 month ago

xavpitz commented 3 months ago

Hello,

I noticed a problem in the startup of the plex container (see log below)

I was able to somehow make it better by creating the following folder : root@xxxxxxxx:/opt/hms-docker/apps/plex/config/Library/Application Support/Plex Media Server# mkdir Cache

but then I noticed that the ownership of the whole "Application\ Support/" folder had to be changed : root@xxxxxxxx:/opt/hms-docker/apps/plex/config/Library# chown -R 1234:1234 Application\ Support/

Actions

  ██╗     ███████╗██╗ ██████╗
  ██║     ██╔════╝██║██╔═══██╗
  ██║     ███████╗██║██║   ██║
  ██║     ╚════██║██║██║   ██║
  ███████╗███████║██║╚██████╔╝
  ╚══════╝╚══════╝╚═╝ ╚═════╝

Brought to you by linuxserver.io ─────────────────────────────────────── To support LSIO projects visit: https://www.linuxserver.io/donate/ ─────────────────────────────────────── GID/UID ─────────────────────────────────────── User UID: 1234 User GID: 1234 ─────────────────────────────────────── Temporarily starting Plex Media Server. Waiting for Plex to generate its config libc++abi: terminating with uncaught exception of type boost::filesystem::filesystem_error: boost::filesystem::create_directories: Permission denied [system:13]: "/config/Library/Application Support/Plex Media Server/Cache", "/config/Library/Application Support/Plex Media Server/Cache" /etc/s6-overlay/s6-rc.d/init-plex-claim/run: line 69: 123 Aborted (core dumped) s6-setuidgid abc /bin/bash -c 'LD_LIBRARY_PATH=/usr/lib/plexmediaserver:/usr/lib/plexmediaserver/lib /usr/lib/plexmediaserver/Plex\ Media\ Server' [migrations] started [migrations] no migrations found usermod: no changes ───────────────────────────────────────

██╗ ███████╗██╗ ██████╗ ██║ ██╔════╝██║██╔═══██╗ ██║ ███████╗██║██║ ██║ ██║ ╚════██║██║██║ ██║ ███████╗███████║██║╚██████╔╝ ╚══════╝╚══════╝╚═╝ ╚═════╝

Brought to you by linuxserver.io ─────────────────────────────────────── To support LSIO projects visit: https://www.linuxserver.io/donate/ ─────────────────────────────────────── GID/UID ─────────────────────────────────────── User UID: 1234 User GID: 1234 ─────────────────────────────────────── Temporarily starting Plex Media Server. Waiting for Plex to generate its config PMS: failure detected. Read/write access is required for path: /config/Library/Application Support/Plex Media Server [migrations] started [migrations] no migrations found usermod: no changes

───────────────────────────────────────

  ██╗     ███████╗██╗ ██████╗
  ██║     ██╔════╝██║██╔═══██╗
  ██║     ███████╗██║██║   ██║
  ██║     ╚════██║██║██║   ██║
  ███████╗███████║██║╚██████╔╝
  ╚══════╝╚══════╝╚═╝ ╚═════╝

Brought to you by linuxserver.io ─────────────────────────────────────── To support LSIO projects visit: https://www.linuxserver.io/donate/ ─────────────────────────────────────── GID/UID ─────────────────────────────────────── User UID: 1234 User GID: 1234 ─────────────────────────────────────── Temporarily starting Plex Media Server. Waiting for Plex to generate its config Waiting for database creation to complete... Waiting for database creation to complete... Waiting for database creation to complete... Waiting for pref file creation to complete... Waiting for pref file creation to complete... Critical: libusb_init failed Stopping Plex to claim server

ahembree commented 3 months ago

Not sure if there's anything I'm able to fix here since the Plex container codebase is not in this repo and permissions usually come down to the system being deployed to, and the specified folder having an issue (Cache) is pretty deep in a folder path that is already owned by the container user.

GitHub Actions deployments and a new recent deployment by myself to a new system did not encounter this issue.

ahembree commented 3 months ago

I've been doing some testing and I've had mixed and weird results, but I believe I've narrowed down a solution, I think I was wrong previously and this may be an issue with how the config directories are created on first run by not setting owner and group (essentially defaulting to root:root instead of the UID/GID specified for the container to run under).

I've created a new branch here for testing and may merge it into master: https://github.com/ahembree/ansible-hms-docker/tree/fix-container-config-dir-perms

Had to be very careful with this one as to not break existing setups due to needing to change permissions on the config directories since it was creating them under root and not 1234.

ahembree commented 3 months ago

Merged in https://github.com/ahembree/ansible-hms-docker/pull/90.

Config directory should now have correct permissions upon initial creation. Any further permission issues within the <app name>/config directory may be due to an issue within the container.

While going through this I discovered another way I can declare the UID/GID of the process in the container and may try to move to that at some point in the future. Right now, it relies on the container supporting a UID/GID environment variable to declare the owner and group. Not all containers have this, so some config folders are owned by root:root once the container launches (also why it was decided to ignore any existing folders instead of forcefully updating permissions)

xavpitz commented 2 months ago

This WE I re-did a full ansible-hms installation after a fresh Ubuntu 24.04 re-installation. I wanted to document all the steps. The Plex container is still struggling to start.

My : container_uid: 1001 (hms) container_gid: 1001 (hms)

Proper permissions are applied as deep as : /opt/hms-docker/apps/plex/config/Library But starting at /opt/hms-docker/apps/plex/config/Library/'Application Support' , the root:root ownership prevents the contained_uid to create the required folders/files for proper Plex startup.

ubuntu@xxxxxxxxx:/opt/hms-docker$ ll apps total 52 drwxr-xr-x 13 root root 4096 Aug 3 20:48 ./ drwxr-xr-x 5 root root 4096 Aug 4 05:00 ../ drwxr-xr-x 3 hms hms 4096 Aug 3 20:48 bazarr/ drwxr-xr-x 3 hms hms 4096 Aug 3 20:48 overseerr/ drwxr-xr-x 3 hms hms 4096 Aug 3 20:48 plex/ drwxr-xr-x 3 hms hms 4096 Aug 3 20:48 portainer/ drwxr-xr-x 3 hms hms 4096 Aug 3 20:48 prowlarr/ drwxr-xr-x 3 hms hms 4096 Aug 3 20:48 radarr/ drwxr-xr-x 3 hms hms 4096 Aug 3 20:48 requestrr/ drwxr-xr-x 3 hms hms 4096 Aug 3 20:48 sonarr/ drwxr-xr-x 3 hms hms 4096 Aug 3 20:48 tautulli/ drwxr-xr-x 3 hms hms 4096 Aug 3 20:48 traefik/ drwxr-xr-x 4 hms hms 4096 Aug 3 20:49 transmission/ ubuntu@xxxxxxxxx:/opt/hms-docker$ ll apps/plex/ total 12 drwxr-xr-x 3 hms hms 4096 Aug 3 20:48 ./ drwxr-xr-x 13 root root 4096 Aug 3 20:48 ../ drwxr-xr-x 3 hms hms 4096 Aug 4 05:00 config/ ubuntu@xxxxxxxxx:/opt/hms-docker$ ll apps/plex/config/ total 20 drwxr-xr-x 3 hms hms 4096 Aug 4 05:00 ./ drwxr-xr-x 3 hms hms 4096 Aug 3 20:48 ../ drwxr-xr-x 3 hms hms 4096 Aug 3 20:49 Library/ -rw------- 1 hms hms 4218 Aug 4 05:00 yyyyyyyyy.pfx ubuntu@xxxxxxxxx:/opt/hms-docker$ ll apps/plex/config/Library/ total 12 drwxr-xr-x 3 hms hms 4096 Aug 3 20:49 ./ drwxr-xr-x 3 hms hms 4096 Aug 4 05:00 ../ drwxr-xr-x 3 root root 4096 Aug 3 20:49 'Application Support'/

Workaround : sudo chown -R hms:hms /opt/hms-docker/apps/plex/config/Library

ubuntu@xxxxxxxxx:/opt/hms-docker$ ll apps/plex/config/Library/ total 12 drwxr-xr-x 3 hms hms 4096 Aug 3 20:49 ./ drwxr-xr-x 3 hms hms 4096 Aug 4 05:00 ../ drwxr-xr-x 3 hms hms 4096 Aug 3 20:49 'Application Support'/

xavpitz commented 2 months ago

Also the folder /opt/hms-docker/media_data is owned by root, which prevents any content to be written in this directory.

hms@xxxxxxxxx:/opt/hms-docker$ ll total 76 drwxr-xr-x 5 root root 4096 Aug 4 06:58 ./ drwxr-xr-x 4 root root 4096 Aug 3 20:48 ../ drwxr-xr-x 5 root root 4096 Aug 3 21:52 .venv/ drwxr-xr-x 13 root root 4096 Aug 3 20:48 apps/ -rw-r--r-- 1 root root 745 Aug 4 05:00 cert_convert.log -rw-r--r-- 1 root docker 11594 Aug 3 20:48 docker-compose.yml drwxr-xr-x 3 root root 4096 Aug 3 20:48 media_data/ -rw-r--r-- 1 root root 189 Aug 3 21:52 requirements.txt -rwx------ 1 hms hms 12402 Aug 3 21:52 traefik_cert_convert.py*

Workaround : hms@xxxxxxxxx:/opt/hms-docker$ sudo chown -R hms:hms /opt/hms-docker/media_data hms@xxxxxxxxx:/opt/hms-docker$ ll total 76 drwxr-xr-x 5 root root 4096 Aug 4 06:58 ./ drwxr-xr-x 4 root root 4096 Aug 3 20:48 ../ drwxr-xr-x 5 root root 4096 Aug 3 21:52 .venv/ drwxr-xr-x 13 root root 4096 Aug 3 20:48 apps/ -rw-r--r-- 1 root root 745 Aug 4 05:00 cert_convert.log -rw-r--r-- 1 root docker 11594 Aug 3 20:48 docker-compose.yml drwxr-xr-x 3 hms hms 4096 Aug 3 20:48 media_data/ -rw-r--r-- 1 root root 189 Aug 3 21:52 requirements.txt -rwx------ 1 hms hms 12402 Aug 3 21:52 traefik_cert_convert.py*

ahembree commented 2 months ago

the folder /opt/hms-docker/media_data is owned by root

This one could be very tricky due to CIFS and NFS permissions if using a network mount. I could potentially update it to create the folder initially under the specified UID/GID as I did with the container config folders (https://github.com/ahembree/ansible-hms-docker/commit/d0b8e20450e52ffdcd6d8f0d99b34a8894028c86), but updating existing folders could be problematic, though I'll try it out on my new raspberry pi testing setup once I get a testing NAS up

ahembree commented 2 months ago

Proper permissions are applied as deep as : /opt/hms-docker/apps/plex/config/Library But starting at /opt/hms-docker/apps/plex/config/Library/'Application Support' , the root:root ownership prevents the contained_uid to create the required folders/files for proper Plex startup.

I'm not sure if your version/branch is out of date from the main branch, but I added (https://github.com/ahembree/ansible-hms-docker/commit/d0b8e20450e52ffdcd6d8f0d99b34a8894028c86#diff-5b0fe0dbee07f3e536cdfd8537a38e27efd363b9c144eaa52dc107e36f286947R61) the creation of up to .../config/Library/Application Support/Plex Media Server/Logs under the correct UID:GID specified