`inbuxa join https://mail.example.com --key KEY` installs the front ends on this machine for a mail server already running on another one. That server is reached only over its own HTTPS, with an API key a server administrator made in the console (--key -, or INBUXA_JOIN_KEY, keeps it out of the shell's history; it is never written down). Through it the front ends' addresses and a webmail client secret made here go into the server's inbuxa:FrontEnds (server #195), which registers their sign-in and allows the console's origin on every node, with no restart and nothing done by hand on that machine. It asks first, dry runs included, and refuses with the reason when the key is wrong, the server has no inbuxa:FrontEnds, it already lists other front ends (--replace), or its environment owns the webmail's secret. Then it installs the console and the webmail in containers with Caddy, registers them, exempts the webmail's address from the server's auto-ban (what its name resolves to, loopback for a loopback server, or --exempt-address), and checks that the server lets the console call it. A second join with the same addresses converges. The compose file learns a server elsewhere: the webmail reaches it at its address, and Caddy serves only the front ends' names. Container and host-server installs render as before. INBUXA_SERVER_BINARY installs a server build instead of the release wherever the server goes on the host, for testing a server change before it is released; e2e/vm/run.sh passes one in with SERVER_BINARY=. e2e/cases/join.sh: 24 checks on Debian 13 against a build of server #195, ending with a person signing in to the joined webmail. install-local, install-host, install-public, status-export and topology pass unchanged.
78 lines
2.8 KiB
Go
78 lines
2.8 KiB
Go
// SPDX-FileCopyrightText: 2026 Coffey Labs LLC
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
// Package state is what this machine remembers about what was installed on
|
|
// it, so a second run converges instead of building a second one.
|
|
//
|
|
// It is deliberately small, and deliberately not the truth: the truth is the
|
|
// machine, and a plan is built by reading both. What this adds is intent --
|
|
// which components this installer put here, in which shape, from which
|
|
// topology -- which the machine itself cannot tell you. A container that was
|
|
// stopped by hand is still ours; a container we never installed is not.
|
|
package state
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"time"
|
|
)
|
|
|
|
// Path is where it lives. /etc, not the deployment directory: it survives
|
|
// the deployment directory being moved or rebuilt, and an operator looking
|
|
// for "what did this thing do to my machine" looks in /etc.
|
|
const Path = "/etc/inbuxa/install.json"
|
|
|
|
// State is the file.
|
|
type State struct {
|
|
Version int `json:"version"`
|
|
Machine string `json:"machine"` // its name in the topology
|
|
Dir string `json:"dir"` // the deployment directory
|
|
Runtime string `json:"runtime,omitempty"` // docker or podman
|
|
Domain string `json:"domain,omitempty"` //
|
|
Shapes map[string]string `json:"shapes"` // component -> container|host
|
|
Topology string `json:"topology,omitempty"` // the file this came from, if any
|
|
ServerURL string `json:"serverUrl,omitempty"` // the server on another machine these front ends were joined to
|
|
Updated time.Time `json:"updated"` //
|
|
Installer string `json:"installer,omitempty"` // the version that wrote this
|
|
}
|
|
|
|
const Version = 1
|
|
|
|
// Load reads the state, returning an empty one when there is none. A machine
|
|
// with nothing installed is not an error; it is the ordinary first case.
|
|
func Load() (*State, error) {
|
|
b, err := os.ReadFile(Path)
|
|
if os.IsNotExist(err) {
|
|
return &State{Version: Version, Shapes: map[string]string{}}, nil
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var s State
|
|
if err := json.Unmarshal(b, &s); err != nil {
|
|
return nil, err
|
|
}
|
|
if s.Shapes == nil {
|
|
s.Shapes = map[string]string{}
|
|
}
|
|
return &s, nil
|
|
}
|
|
|
|
// Save writes it, creating /etc/inbuxa if it is not there.
|
|
func (s *State) Save() error {
|
|
s.Version = Version
|
|
s.Updated = time.Now().UTC().Truncate(time.Second)
|
|
if err := os.MkdirAll(filepath.Dir(Path), 0o755); err != nil {
|
|
return err
|
|
}
|
|
b, err := json.MarshalIndent(s, "", " ")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return os.WriteFile(Path, append(b, '\n'), 0o644)
|
|
}
|
|
|
|
// Installed is whether anything is recorded here at all.
|
|
func (s *State) Installed() bool { return len(s.Shapes) > 0 }
|