Do not create a host file for the entrypoint's PHP session config
The role created ~/podman-data/nextcloud/redis-session.ini and the unit bind-mounted it over the image path, purely because the entrypoint cannot write there itself. Removed: the task, the mount, and -- because it is the only thing that triggers the write -- REDIS_HOST from the environment file. The entrypoint now skips configure_redis_session entirely and starts. The Redis attach stays. The valkey role still puts nextcloud_net on the cache container with the alias `redis`, so an instance whose config.php names that host reaches it. Writing that configuration is config.php's business, and the readme gives the three `occ config:system:set` lines for anyone who wants it, including that this playbook will not do it for them. The only thing lost is PHP session storage, which falls back to the container's own filesystem -- a redeploy logs users out. That is the trade for not shipping a file whose sole purpose is to work around a directory the image owns as root. The env template and the valkey role comment both say why REDIS_HOST is absent, so that adding it back is recognisable as the regression it is.
This commit is contained in:
1 parent
5d63f3f0e0
commit
c3e0e4989c
6 files changed
+41
-60
No files matched your search
+29
-28
@@ -37,7 +37,7 @@ nextcloud/
|
||||
└── roles/
|
||||
├── postgres/ # the database, and this app's network on the cluster
|
||||
├── valkey/ # this app's network on the cache
|
||||
├── nextcloud/ # webroot, env file, unit, session config, cron
|
||||
├── nextcloud/ # webroot, env file, unit, cron
|
||||
└── caddy/ # the site block in the shared Caddyfile
|
||||
```
|
||||
|
||||
@@ -48,8 +48,7 @@ nextcloud/
|
||||
| `~/.config/containers/systemd/*.container.d/50-nextcloud.conf` | attaches Caddy, Postgres and Valkey to it |
|
||||
| `~/.config/containers/systemd/*.container.d/10-network-aliases.conf` | the shared `db` and `redis` aliases |
|
||||
| `~/podman-data/nextcloud/` | the whole `/var/www/html` |
|
||||
| `~/podman-data/nextcloud/nextcloud.env` | `POSTGRES_*` + `REDIS_HOST`, mode `0600` |
|
||||
| `~/podman-data/nextcloud/redis-session.ini` | mounted into the image; see [below](#the-php-session-file) |
|
||||
| `~/podman-data/nextcloud/nextcloud.env` | `POSTGRES_*`, mode `0600` |
|
||||
|
||||
## What is state, and what is not
|
||||
|
||||
@@ -88,12 +87,11 @@ of downtime for every attached app; see
|
||||
|
||||
**Valkey.** The same, via
|
||||
[valkey/roles/attach](../valkey/roles/attach/tasks/main.yaml), with
|
||||
`NetworkAlias=redis`. `redis` is not a name this playbook chose: `REDIS_HOST` is
|
||||
what the image writes PHP's session config from, and Redis is where the setup
|
||||
wizard puts `memcache.locking`. An unresolvable `redis` therefore breaks uploads
|
||||
at write time rather than at startup, which is why the attach is flushed before
|
||||
the app starts as well. The recreate costs a few seconds of cache availability;
|
||||
the keys survive it (see [valkey/readme.md](../valkey/readme.md)).
|
||||
`NetworkAlias=redis`: the attach puts `nextcloud_net` on the cache container and
|
||||
makes the host `redis` resolve from Nextcloud. What *uses* it is `config.php`, and
|
||||
this playbook does not write that — see "Redis" below. The recreate costs a few
|
||||
seconds of cache availability, and the keys survive it
|
||||
(see [valkey/readme.md](../valkey/readme.md)).
|
||||
|
||||
## Background jobs
|
||||
|
||||
@@ -127,7 +125,7 @@ Quadlet units is the alternative, and it is two small files.
|
||||
| `container_port` | `80`, what Caddy proxies to |
|
||||
| `env_file` | `~/podman-data/nextcloud/nextcloud.env`, mode `0600` |
|
||||
| `pg_*` / `db_host` | The database, its credentials, and the `db` alias |
|
||||
| `valkey_container` / `redis_host` | The cache unit, and the `redis` alias |
|
||||
| `valkey_container` / `valkey_unit` | The cache unit this app attaches to |
|
||||
| `nextcloud_admin_user` / `nextcloud_admin_password` | Empty by default; set both to install unattended |
|
||||
| `cron_minute` | The `cron.php` interval |
|
||||
| `caddy_*` | The shared Caddy unit and its Caddyfile |
|
||||
@@ -147,31 +145,34 @@ owned by `tanshu` and plain `tar` and `rm -rf` keep working on it.
|
||||
`123456`. It lives in `nextcloud.env` at mode `0600` rather than in the
|
||||
world-readable unit file.
|
||||
|
||||
## The PHP session file
|
||||
## Redis
|
||||
|
||||
The entrypoint generates PHP's session config on every start, with a redirect:
|
||||
The Valkey attach above makes the host `redis` resolve from the container, and
|
||||
that is all this playbook does about Redis: which caches Nextcloud uses is
|
||||
`config.php`'s business, and this playbook does not write it.
|
||||
|
||||
```sh
|
||||
/entrypoint.sh:121
|
||||
} > /usr/local/etc/php/conf.d/redis-session.ini
|
||||
```
|
||||
|
||||
That directory belongs to the image's root — the php base image creates it with
|
||||
`mkdir -p "$PHP_INI_DIR/conf.d"` and never chowns it — so the write is refused,
|
||||
the entrypoint exits `2` before Apache is reached, `Restart=always` retries it,
|
||||
systemd hits its start limit, and the unit ends up **`failed`** with the only
|
||||
explanation in the journal:
|
||||
It deliberately does **not** set `REDIS_HOST`, which is the one Redis variable the
|
||||
image acts on. That variable exists to write PHP's session config, with a redirect
|
||||
into `/usr/local/etc/php/conf.d` — a directory the image owns as root and this
|
||||
container cannot write:
|
||||
|
||||
```
|
||||
cannot create /usr/local/etc/php/conf.d/redis-session.ini: Permission denied
|
||||
```
|
||||
|
||||
The role creates `~/podman-data/nextcloud/redis-session.ini` and the unit binds it
|
||||
over that exact path. A bind-mounted file replaces the directory entry, so the
|
||||
directory's ownership stops mattering and the write lands on a file owned by
|
||||
`podman_user`. Apache's own runtime directories need none of this — the same base
|
||||
image chowns `/var/run/apache2`, `/var/lock/apache2` and `/var/log/apache2` to
|
||||
`www-data` and chmods them `1777`.
|
||||
The entrypoint exits `2` before Apache is reached, `Restart=always` retries it, and
|
||||
systemd's start limit marks the unit `failed`. Leaving `REDIS_HOST` unset skips
|
||||
that write entirely; the only thing lost is PHP session storage, which falls back
|
||||
to the container's own filesystem.
|
||||
|
||||
So to put Nextcloud's caches on Valkey, set it in `config.php` — `memcache.locking`
|
||||
and `memcache.distributed` to `\OC\Memcache\Redis`, and `redis` `host` to `redis`:
|
||||
|
||||
```bash
|
||||
podman exec -u www-data nextcloud php occ config:system:set memcache.distributed --value='\OC\Memcache\Redis'
|
||||
podman exec -u www-data nextcloud php occ config:system:set memcache.locking --value='\OC\Memcache\Redis'
|
||||
podman exec -u www-data nextcloud php occ config:system:set redis host --value=redis
|
||||
```
|
||||
|
||||
## First run and updates
|
||||
|
||||
|
||||
Reference in new issue
Block a user