From 01cd599ef71ff6fcabac6621f3916d8879947c3d Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Thu, 22 Oct 2026 17:38:40 +1100 Subject: [PATCH] fix(configuration): keep named instances under the archie- namespace --- install.sh | 12 ++++++------ internal/app/archied/update_host.go | 6 +++--- internal/infrastructure/configuration/instance.go | 5 ++++- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/install.sh b/install.sh index a49490a56..817c58fc4 100755 --- a/install.sh +++ b/install.sh @@ -38,8 +38,8 @@ Options: --version X.Y.Z Install this release instead of the latest --from-source Build from a checkout (this one, or a fresh clone) instead of a release; needs Go, git and jq - --instance NAME Install a named instance beside others (default: archie); - its dirs are /NAME and its units end in -NAME + --instance NAME Install a named instance beside others: archie (default) + or archie-X; its dirs are /NAME and its units end in -X --port-base N Use ports N..N+6 for web, health, gateway, state store, state store readiness, messaging and daemon --no-systemd Skip systemd user units @@ -67,8 +67,8 @@ while [ $# -gt 0 ]; do shift done -if ! [[ "${INSTANCE}" =~ ^[a-z][a-z0-9-]{0,30}$ ]]; then - echo "Error: --instance '${INSTANCE}' must match ^[a-z][a-z0-9-]{0,30}\$" >&2; exit 1 +if ! [[ "${INSTANCE}" =~ ^archie(-[a-z0-9][a-z0-9-]{0,23})?$ ]]; then + echo "Error: --instance '${INSTANCE}' must be archie or archie-, e.g. archie-dev" >&2; exit 1 fi if [ -n "${PORT_BASE}" ] && ! { [[ "${PORT_BASE}" =~ ^[0-9]+$ ]] && [ "${PORT_BASE}" -ge 1024 ] && [ "${PORT_BASE}" -le 65529 ]; }; then echo "Error: --port-base must be a number from 1024 to 65529" >&2; exit 1 @@ -79,9 +79,9 @@ ARCHIE_DATA_DIR="${XDG_DATA_HOME}/${INSTANCE}" ENV_FILE="${ARCHIE_CONFIG_DIR}/env" # unit maps a base unit name to this instance's: unchanged for the default -# instance, suffixed with - otherwise. +# instance, suffixed with the name after archie- otherwise. unit() { - if [ "${INSTANCE}" = archie ]; then echo "$1"; else echo "$1-${INSTANCE}"; fi + if [ "${INSTANCE}" = archie ]; then echo "$1"; else echo "$1-${INSTANCE#archie-}"; fi } U_DAEMON="$(unit archied)" U_STATE="$(unit archie-state-store)" diff --git a/internal/app/archied/update_host.go b/internal/app/archied/update_host.go index bb517f475..569756b8b 100644 --- a/internal/app/archied/update_host.go +++ b/internal/app/archied/update_host.go @@ -16,11 +16,11 @@ import ( ) // instanceUnit names this instance's systemd unit for a base unit name: -// unchanged for the default instance and suffixed with - otherwise, -// so several instances install side by side. +// unchanged for the default instance and suffixed with the name after +// "archie-" otherwise, so several instances install side by side. func instanceUnit(base string) string { if name := configuration.InstanceName(); name != configuration.DefaultInstance { - return base + "-" + name + return base + "-" + strings.TrimPrefix(name, configuration.DefaultInstance+"-") } return base } diff --git a/internal/infrastructure/configuration/instance.go b/internal/infrastructure/configuration/instance.go index 5c92aac33..a30133708 100644 --- a/internal/infrastructure/configuration/instance.go +++ b/internal/infrastructure/configuration/instance.go @@ -11,7 +11,10 @@ import ( // host-global name derived from it is unchanged from a single-instance host. const DefaultInstance = "archie" -var instancePattern = regexp.MustCompile(`^[a-z][a-z0-9-]{0,30}$`) +// instancePattern keeps every instance under the archie namespace: the name is +// used bare as XDG directory, compose project and container prefix, so +// "archie-dev" cannot collide with another program's "dev". +var instancePattern = regexp.MustCompile(`^archie(-[a-z0-9][a-z0-9-]{0,23})?$`) // InstanceName returns the instance this process belongs to, from // ARCHIE_INSTANCE. It names the config, data, state and cache directories, so