diff --git a/CHANGELOG.md b/CHANGELOG.md index abc270e6..738c91c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ * Env variable `OWNCLOUD_LOGIN_POLICY_GROUP_FORBID_MAP` for the `loginPolicy.groupLoginPolicy.forbidMap` config key [#493](https://github.com/owncloud-docker/base/issues/493) + * Env variable `OWNCLOUD_MEMCACHED_SERVERS` to define multiple memcached + servers (and optional per-server weights) + [#489](https://github.com/owncloud-docker/base/issues/489) ## 2026-07-06 diff --git a/ENVIRONMENT.md b/ENVIRONMENT.md index d4fc7ffc..d5851874 100644 --- a/ENVIRONMENT.md +++ b/ENVIRONMENT.md @@ -227,6 +227,8 @@ Define connection options for memcached (see [documentation](https://doc.owncloud.com/server/latest/admin_manual/configuration/server/config_sample_php_parameters.html#define-connection-options-for-memcached)). - `OWNCLOUD_MEMCACHED_PORT=11211` \ Defines the ports for memcached (see [documentation](https://doc.owncloud.com/server/latest/admin_manual/configuration/server/config_sample_php_parameters.html#define-server-details-for-memcached-servers-to-use-for-memory-caching)). +- `OWNCLOUD_MEMCACHED_SERVERS=` \ + Define multiple memcached servers as a JSON-encoded list of `[host, port]` or `[host, port, weight]` tuples, e.g. `[["mem1",11211,33],["mem2",11211]]`. Overrides the single-server `OWNCLOUD_MEMCACHED_HOST`/`OWNCLOUD_MEMCACHED_PORT` pair when set (see [documentation](https://doc.owncloud.com/server/latest/admin_manual/configuration/server/config_sample_php_parameters.html#define-server-details-for-memcached-servers-to-use-for-memory-caching)). - `OWNCLOUD_MEMCACHED_STARTUP_TIMEOUT=180` \ Time to wait for a successful connection to the memcached service on container startup. - `OWNCLOUD_MEMCACHE_LOCAL=${OWNCLOUD_CACHING_CLASS:-\\OC\\Memcache\\APCu}` \ diff --git a/v24.04/overlay/etc/owncloud.d/15-database.sh b/v24.04/overlay/etc/owncloud.d/15-database.sh index 3a77c8c9..dd4bbf34 100755 --- a/v24.04/overlay/etc/owncloud.d/15-database.sh +++ b/v24.04/overlay/etc/owncloud.d/15-database.sh @@ -31,7 +31,7 @@ case ${OWNCLOUD_DB_TYPE} in ;; esac -if [[ ${OWNCLOUD_MEMCACHED_ENABLED} == "true" ]]; then +if [[ ${OWNCLOUD_MEMCACHED_ENABLED} == "true" ]] && [[ ${OWNCLOUD_MEMCACHED_SERVERS} == "" ]]; then echo "Waiting for Memcached..." wait_error=false wait-for-it -t "${OWNCLOUD_MEMCACHED_STARTUP_TIMEOUT}" "${OWNCLOUD_MEMCACHED_HOST}":"${OWNCLOUD_MEMCACHED_PORT}" || wait_error=true diff --git a/v24.04/overlay/etc/templates/config.php b/v24.04/overlay/etc/templates/config.php index 11a22591..6afba9de 100644 --- a/v24.04/overlay/etc/templates/config.php +++ b/v24.04/overlay/etc/templates/config.php @@ -906,16 +906,30 @@ function getConfigFromEnv() { break; case getenv('OWNCLOUD_MEMCACHED_ENABLED') && getenv('OWNCLOUD_MEMCACHED_ENABLED') === 'true': + // 'memcached_servers' is a list of [host, port] or [host, port, weight] + // tuples. The flat env-var idioms cannot express multiple servers or a + // weight, so multiple servers are passed as a JSON-encoded array, e.g.: + // OWNCLOUD_MEMCACHED_SERVERS='[["mem1",11211,33],["mem2",11211]]' + // When unset, fall back to the single OWNCLOUD_MEMCACHED_HOST/_PORT pair. + $memcachedServers = [ + [ + getenv('OWNCLOUD_MEMCACHED_HOST'), + getenv('OWNCLOUD_MEMCACHED_PORT'), + ], + ]; + + if (getenv('OWNCLOUD_MEMCACHED_SERVERS') != '') { + $servers = json_decode(getenv('OWNCLOUD_MEMCACHED_SERVERS'), true); + if (is_array($servers)) { + $memcachedServers = $servers; + } + } + $config = array_merge_recursive($config, [ 'memcache.distributed' => '\OC\Memcache\Memcached', 'memcache.locking' => '\OC\Memcache\Memcached', - 'memcached_servers' => [ - [ - getenv('OWNCLOUD_MEMCACHED_HOST'), - getenv('OWNCLOUD_MEMCACHED_PORT'), - ], - ], + 'memcached_servers' => $memcachedServers, ]); if (getenv('OWNCLOUD_MEMCACHED_OPTIONS') != '') {