fix(configuration): keep named instances under the archie- namespace

This commit is contained in:
sam committed 2026-10-22 17:38:40 +11:00
1 parent 5b2c4f9077
commit 01cd599ef7
3 files changed
+13 -10

No files matched your search

+6 -6
View File
@@ -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 <xdg>/NAME and its units end in -NAME
--instance NAME Install a named instance beside others: archie (default)
or archie-X; its dirs are <xdg>/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-<name>, 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 -<instance> 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)"
+3 -3
View File
@@ -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 -<instance> 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
}
@@ -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