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

feat: Move /.firstRunComplete to /tmp to prepare readonly rootfs #80

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mkilchhofer
Copy link

@mkilchhofer mkilchhofer commented Feb 25, 2023

I currently migrate all my Kubernetes workloads to containers with read-only rootfs.

The plex container is a bit tricky with the /.firstRunComplete file. If you'd move that file to /tmp, it would be possible to mount a temporary filesystem which is writable (Kubernetes emptyDir) below /tmp.

The s6 suite also have issues with read-only rootfs but it (officially) supports it by setting S6_READ_ONLY_ROOT=1. Ref: https://github.com/just-containers/s6-overlay#read-only-root-filesystem

@gbooker
Copy link
Contributor

gbooker commented Feb 27, 2023

The /.firstRunComplete is used to indicate whether this is the first time the container is run or whether it is a subsequent run. Moving this to /tmp will likely completely break this (because /tmp is by definition transitory and content there can be deleted without warning).

@mkilchhofer
Copy link
Author

mkilchhofer commented Feb 27, 2023

I would be fine to move it completely elsewhere but having it inside the / (the root) is a really bad practice for the reason I mentioned above.
Are you fine if we move it elsewhere?

Additional I'd like to ask why does something break if the "first run" is executed twice (in case /tmp is cleared to an arbitrary mechanism)? What I understand from reading all init scripts is that if we skip it, we gain speed due to skip of a recursive file chown.

@mkilchhofer
Copy link
Author

@gbooker any update?

@gbooker
Copy link
Contributor

gbooker commented Mar 22, 2023

As stated, moving this indicator to /tmp will break functionality. This PR hasn't changed from that. Any change to this behavior would have to also not break the existing functionality.

Perhaps there's an id or something which doesn't change across updates which could be used to indicate that it is in the same effective container and this be stored in a more permanent location in /config?

@mkilchhofer
Copy link
Author

What ID do you mean? If you recreate the container from a container image (eg. on an update) its not the same container.

In which cases should the firstRun be triggered?

@gbooker
Copy link
Contributor

gbooker commented Mar 23, 2023

I was afraid the container id changes across updates.

Ideally, the firstRun should be triggered when a fresh container is created but not when a container is upgraded. Additionally not when a configuration is changed (such as a volume map, etc) It's a tricky thing to accomplish since docker is really missing a mechanism to do this.

The rationale is the first-run can perform some expensive operations but these should only be done once (such as chown a directory tree).

@saltydk
Copy link

saltydk commented Mar 24, 2023

What container upgrade are you talking about here? The root filesystem does not persist when a container is recreated (or upgraded as you state).

@mkilchhofer mkilchhofer deleted the feature/support_readonly_rootfs branch September 27, 2023 12:17
@mkilchhofer mkilchhofer restored the feature/support_readonly_rootfs branch April 27, 2024 10:06
@mkilchhofer mkilchhofer deleted the feature/support_readonly_rootfs branch April 27, 2024 10:09
@mkilchhofer mkilchhofer restored the feature/support_readonly_rootfs branch April 27, 2024 10:09
@mkilchhofer mkilchhofer reopened this Apr 27, 2024
@mkilchhofer
Copy link
Author

mkilchhofer commented Apr 27, 2024

As I am still affected of this issue, can we talk about it again?

@gbooker is your idea that this script is only executed when plex is initialized for the first time or every time Plex is upgraded (and thus the container is replaced from a new container image)?

/cc: @MarshallAsch as you implemented a helm chart for plex (PR #82) which could also benefit from this change.

@gbooker
Copy link
Contributor

gbooker commented Apr 29, 2024

is your idea that this script is only executed when plex is initialized for the first time or every time Plex is upgraded (and thus the container is replaced from a new container image)?

I previously stated:

Ideally, the firstRun should be triggered when a fresh container is created but not when a container is upgraded. Additionally not when a configuration is changed (such as a volume map, etc) It's a tricky thing to accomplish since docker is really missing a mechanism to do this.

The first run does some things (such as a recursive chown or signing in the PMS with the result stored in prefs) which should only be run once. However, if a server is migrated from one system to another (or potentially migrate to a new container), it likely should be run again. I don't like the idea of modifying the container root image that much (as it is antithetical to how docker is supposed to work) but I couldn't find any good mechanism to accomplish this.

@mkilchhofer
Copy link
Author

I don't like the idea of modifying the container root image that much (as it is antithetical to how docker is supposed to work) but I couldn't find any good mechanism to accomplish this.

Its not a big deal. The real issue is, that this file should not live in a directory which contains other files. We can move it to wherever you want. Would you be okay with another location?

@cilindrox
Copy link
Member

Might be missing some context here, but what about a newer directory that we declare with the VOLUME directive in the dockerfile? This allows users to override it with persistent volumes and signals there's some sort of statefulness expected to operators

@mkilchhofer
Copy link
Author

Might be missing some context here, but what about a newer directory that we declare with the VOLUME directive in the dockerfile? This allows users to override it with persistent volumes and signals there's some sort of statefulness expected to operators

That would be great!

Copy link
Contributor

@gbooker gbooker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving to another directory would be fine (just not /tmp because of the meaning of that name) and users who wish to map a volume to that dir are welcome to do so. Just the if needs to check / as well for containers where this has already run before moving the firstRunComplete file.

root/etc/cont-init.d/40-plex-first-run Show resolved Hide resolved
@@ -136,5 +136,5 @@ if [ -z "$(getPref "TranscoderTempDirectory")" ]; then
setPref "TranscoderTempDirectory" "/transcode"
fi

touch /.firstRunComplete
touch /tmp/.firstRunComplete
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If moving to another dir, this likely would need to run a mkdir for that dir first in case it doesn't already exist

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

Successfully merging this pull request may close these issues.

4 participants