Skip to content

Commit f6ba3ed

Browse files
feat(config): support multiple memcached servers via OWNCLOUD_MEMCACHED_SERVERS (#517)
* feat(config): support multiple memcached servers via OWNCLOUD_MEMCACHED_SERVERS The memcached config block hard-coded a single [host, port] pair built from OWNCLOUD_MEMCACHED_HOST / OWNCLOUD_MEMCACHED_PORT, with no way to define multiple servers or per-server weights that core's 'memcached_servers' supports. Add OWNCLOUD_MEMCACHED_SERVERS, a JSON-encoded list of [host, port] or [host, port, weight] tuples, reusing the json_decode pattern already used for OWNCLOUD_LOG_CONDITIONS. It overrides the single-server pair when set and falls back to it when unset or when the JSON is invalid, so existing deployments are unaffected. Added to v24.04 only, matching the convention that v20.04/v22.04 are frozen. The container startup readiness probe (wait-for-it in 15-database.sh) still targets HOST:PORT only and is intentionally left unchanged. Closes #489 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com> * fix(memcached): skip startup wait when OWNCLOUD_MEMCACHED_SERVERS is set The startup wait in 15-database.sh probed OWNCLOUD_MEMCACHED_HOST:PORT whenever memcached was enabled and exited on timeout. With OWNCLOUD_MEMCACHED_SERVERS set (and HOST left at its default), the container could fail to start even though the configured servers are reachable. Guard the wait with `&& [[ ${OWNCLOUD_MEMCACHED_SERVERS} == "" ]]`, mirroring how the redis wait is skipped when OWNCLOUD_REDIS_SEEDS is set. Also drop the now-inaccurate ENVIRONMENT.md note that described the old probing behaviour as a caveat of the new variable. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com> --------- Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 12b306c commit f6ba3ed

4 files changed

Lines changed: 26 additions & 7 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
* Env variable `OWNCLOUD_LOGIN_POLICY_GROUP_FORBID_MAP` for the
1212
`loginPolicy.groupLoginPolicy.forbidMap` config key
1313
[#493](https://github.com/owncloud-docker/base/issues/493)
14+
* Env variable `OWNCLOUD_MEMCACHED_SERVERS` to define multiple memcached
15+
servers (and optional per-server weights)
16+
[#489](https://github.com/owncloud-docker/base/issues/489)
1417

1518
## 2026-07-06
1619

‎ENVIRONMENT.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@
227227
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)).
228228
- `OWNCLOUD_MEMCACHED_PORT=11211` \
229229
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)).
230+
- `OWNCLOUD_MEMCACHED_SERVERS=` \
231+
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)).
230232
- `OWNCLOUD_MEMCACHED_STARTUP_TIMEOUT=180` \
231233
Time to wait for a successful connection to the memcached service on container startup.
232234
- `OWNCLOUD_MEMCACHE_LOCAL=${OWNCLOUD_CACHING_CLASS:-\\OC\\Memcache\\APCu}` \

‎v24.04/overlay/etc/owncloud.d/15-database.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ case ${OWNCLOUD_DB_TYPE} in
3131
;;
3232
esac
3333

34-
if [[ ${OWNCLOUD_MEMCACHED_ENABLED} == "true" ]]; then
34+
if [[ ${OWNCLOUD_MEMCACHED_ENABLED} == "true" ]] && [[ ${OWNCLOUD_MEMCACHED_SERVERS} == "" ]]; then
3535
echo "Waiting for Memcached..."
3636
wait_error=false
3737
wait-for-it -t "${OWNCLOUD_MEMCACHED_STARTUP_TIMEOUT}" "${OWNCLOUD_MEMCACHED_HOST}":"${OWNCLOUD_MEMCACHED_PORT}" || wait_error=true

‎v24.04/overlay/etc/templates/config.php‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -906,16 +906,30 @@ function getConfigFromEnv() {
906906

907907
break;
908908
case getenv('OWNCLOUD_MEMCACHED_ENABLED') && getenv('OWNCLOUD_MEMCACHED_ENABLED') === 'true':
909+
// 'memcached_servers' is a list of [host, port] or [host, port, weight]
910+
// tuples. The flat env-var idioms cannot express multiple servers or a
911+
// weight, so multiple servers are passed as a JSON-encoded array, e.g.:
912+
// OWNCLOUD_MEMCACHED_SERVERS='[["mem1",11211,33],["mem2",11211]]'
913+
// When unset, fall back to the single OWNCLOUD_MEMCACHED_HOST/_PORT pair.
914+
$memcachedServers = [
915+
[
916+
getenv('OWNCLOUD_MEMCACHED_HOST'),
917+
getenv('OWNCLOUD_MEMCACHED_PORT'),
918+
],
919+
];
920+
921+
if (getenv('OWNCLOUD_MEMCACHED_SERVERS') != '') {
922+
$servers = json_decode(getenv('OWNCLOUD_MEMCACHED_SERVERS'), true);
923+
if (is_array($servers)) {
924+
$memcachedServers = $servers;
925+
}
926+
}
927+
909928
$config = array_merge_recursive($config, [
910929
'memcache.distributed' => '\OC\Memcache\Memcached',
911930
'memcache.locking' => '\OC\Memcache\Memcached',
912931

913-
'memcached_servers' => [
914-
[
915-
getenv('OWNCLOUD_MEMCACHED_HOST'),
916-
getenv('OWNCLOUD_MEMCACHED_PORT'),
917-
],
918-
],
932+
'memcached_servers' => $memcachedServers,
919933
]);
920934

921935
if (getenv('OWNCLOUD_MEMCACHED_OPTIONS') != '') {

0 commit comments

Comments
 (0)