-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Replace run.sh with files that do the following:
- configure COPS
- start rsync
- start php-fpm
- start nginx
- start korrasync
Gemini says:
To move from a "Fat Script" (run.sh) to the native S6-overlay system, you need to break your script apart. S6 expects each long-running process (Nginx, PHP, Rsync) to have its own directory and its own run script.
Based on your current Dockerfile, here is the transformation:
1. The Directory Structure
In your repository, create a rootfs folder that mimics the Linux root. You will store your service scripts here:
rootfs/
├── etc/
│ ├── cont-init.d/
│ │ └── 01-setup-cops # Your "writing config" logic goes here
│ └── s6-overlay/
│ └── s6-rc.d/ # Service definitions
│ ├── nginx/
│ │ └── run # Command to start Nginx
│ ├── php-fpm/
│ │ └── run # Command to start PHP
│ └── rsync/
│ └── run # Command to start Rsync
- The "Setup" Script (Initial Logic)
Take the part of your run.sh that writes configurations and move it to /etc/cont-init.d/01-setup-cops.
Important: S6 runs these scripts as root before starting the services. - The Service "Run" Scripts
Each run script must stay in the foreground (do not use &). If the process exits, S6 will see it and restart it automatically.
Nginx (/etc/s6-overlay/s6-rc.d/nginx/run):
#!/command/execlineb -P
nginx -g "daemon off;"PHP-FPM (/etc/s6-overlay/s6-rc.d/php-fpm/run):
#!/command/execlineb -P
php-fpm83 -FRsync (/etc/s6-overlay/s6-rc.d/rsync/run):
#!/usr/bin/with-contenv bashio
exec rsync --daemon --no-detach --config=/etc/rsyncd.conf- Update your Dockerfile
You need to copy these files into the image and remove your old CMD.
Modify your Dockerfile as follows:
Remove: COPY run.sh / and CMD [ "/run.sh" ].
Add: A copy command for your new folder structure.
Permissions: Make sure the scripts are executable.
# ... keep your existing RUN commands (apk add, etc.) ...
# Copy the S6 structure
COPY rootfs /
# Ensure scripts are executable
RUN chmod a+x /etc/cont-init.d/* \
&& chmod a+x /etc/s6-overlay/s6-rc.d/*/run
# S6-overlay is the entrypoint by default in HA base images,
# so you don't need a CMD anymore.
- Why this is a "Power Move"
Parallelism: S6 will start PHP-FPM and Nginx at the same time.
Self-Healing: If PHP crashes because of a memory leak, S6 restarts it in milliseconds without killing your Nginx or Rsync streams.
Logging: HA will now show you clearly labeled logs for each service rather than one messy stream from a single shell script.
To get your Rsync server properly integrated with the Home Assistant config, we’ll use your cont-init.d script to generate the rsyncd.conf file. This ensures that the paths users set in the HA UI are the same paths the Rsync daemon uses.
1. The Dynamic Rsync Config
In your rootfs/etc/cont-init.d/01-setup-cops, add logic to write the Rsync configuration. This allows you to point Rsync directly to the folder the user chose for their Calibre library.
#!/usr/bin/with-contenv bashio
# Get the path from HA options
MEDIA_PATH=$(bashio::config 'calibre_directory')
# Generate rsyncd.conf
bashio::log.info "Generating Rsync configuration for ${MEDIA_PATH}..."
cat <<EOF > /etc/rsyncd.conf
uid = root
gid = root
use chroot = no
max connections = 4
pid file = /run/rsyncd.pid
[calibre]
path = ${MEDIA_PATH}
comment = Calibre Library
read only = no
lock file = /run/rsync.lock
EOF- The S6 Service Dependencies
In S6-overlay v3 (which current HA images use), services need to be "registered." Since your services (Nginx, PHP, Rsync) all rely on the config files being generated first, we define them as a bundle.
Create these small files to tell S6 what to do:
Create a directory for the bundle: rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/
Create empty files inside that folder named after your services:
nginx
php-fpm
rsync
This tells S6: "When the container starts, make sure these three services are running."
3. Handling Logs (The "S6 Way")
One of the best parts of moving away from run.sh is that you stop seeing "blind" errors. To see your PHP or Nginx logs in the Home Assistant "Logs" tab, ensure your service commands redirect to stdout/stderr.
Updated rootfs/etc/s6-overlay/s6-rc.d/nginx/run:
#!/usr/bin/with-contenv bashio
exec nginx -g "daemon off;" 2>&1