119 SPDX-FileCopyrightText headers and the README's licence line. The distinction that matters here: LINUXexpert-org appears in this repository in two completely different roles. As a copyright holder in the SPDX headers, which is what changes, and as the GitHub organisation in the module path and 64 import statements, which does not -- the repository still lives at github.com/LINUXexpert-org/stalwart-migrator, and rewriting that would not be a licence change, it would break the build. Both replacements are anchored to their copyright forms, so an import path cannot match either. Import count is 64 before and after, and go.mod is untouched. LICENSE untouched: the FSF's copyright on the GPL text and the "<name of author>" placeholders are not ours to edit. go vet, go build and go test all clean.
54 lines
1.6 KiB
Go
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/LINUXexpert-org/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
|
|
}
|