Files
stalwart-migrator/internal/preflight/deployment.go
T
jcoffey-dev 12ec0c3fd4 Rename the module to the Coffey-Labs organisation
The repositories moved off LINUXexpert-org. Here that is not a
documentation change: the old organisation was the module path, so it is
declared in go.mod and repeated in every internal import.

Leaving it would have been worse than a stale link. GitHub redirects the
repository, but a go.mod whose module line disagrees with the path it was
fetched from is an error rather than a redirect, so `go get` on the new
address would have failed against the old declaration.

go.mod, 34 files of imports, and the repository links in README and
ARCHITECTURE. go mod tidy leaves go.sum untouched -- no dependency moved,
only our own path.
2026-08-30 15:24:18 -07:00

54 lines
1.6 KiB
Go

// SPDX-FileCopyrightText: 2026 Coffey Labs
// SPDX-License-Identifier: GPL-3.0-or-later
package preflight
import (
"context"
"os"
"os/exec"
"github.com/Coffey-Labs/stalwart-migrator/internal/service"
)
// DeploymentKind is how a Stalwart instance appears to be run, which
// determines how cutover restarts it. It's an alias for
// service.Kind rather than a parallel type: detection here and control
// there have to agree on the same vocabulary, and one definition can't
// drift from itself.
type DeploymentKind = service.Kind
const (
DeploymentSystemd = service.Systemd
DeploymentDocker = service.Docker
DeploymentUnknown = service.Unknown
)
var systemdUnitPaths = []string{
"/etc/systemd/system/stalwart.service",
"/lib/systemd/system/stalwart.service",
"/usr/lib/systemd/system/stalwart.service",
}
// DetectDeploymentKind makes a best-effort guess at how Stalwart is run
// here. It's deliberately conservative and cheap (file stats, one docker
// inspect) rather than exhaustive - an operator-supplied override should
// always be able to win over this, since the cost of guessing wrong here is
// cutover targeting the wrong thing.
func DetectDeploymentKind(ctx context.Context, containerName string) DeploymentKind {
for _, p := range systemdUnitPaths {
if _, err := os.Stat(p); err == nil {
return DeploymentSystemd
}
}
if containerName == "" {
containerName = "stalwart"
}
if _, err := exec.LookPath("docker"); err == nil {
if err := exec.CommandContext(ctx, "docker", "inspect", containerName).Run(); err == nil {
return DeploymentDocker
}
}
return DeploymentUnknown
}