ae42450ec1
Full server backup (spec 7.5.A): internal/backup produces a tar.gz of all of /data — a consistent SQLite snapshot via VACUUM INTO, DKIM keys, sasldb2 and a version manifest; TLS certs (tls/) and the Postfix queue are excluded. Two equal paths: the panel button (POST /backup, no-store) and the selfpost-backup CLI via docker exec (spec 11.6). CheckRestore runs before store.Open: a manifest version mismatch refuses to boot with the image tag to use; a match consumes the manifest so it only guards the first post-restore boot. Restore is not a separate branch — Postfix/OpenDKIM regenerate from the restored SQLite as on any start. Domain export/import (spec 7.5.B): DomainExport carries the DKIM private key and each application's working password. SASL secrets are read from sasldb2 via db_dump (the userPassword property is plaintext) and, on import, re-keyed under the local realm with saslpasswd2 — so credentials keep working on an instance with a different hostname, with no DKIM DNS change. Import validates and rolls back atomically on any failure. db-util (db_dump) is now an explicit image dep. Verified on the server (selfpost:p9): gofmt/vet/test green; container e2e for cross-realm domain export/import (SMTP AUTH 235 under the new realm), CLI and panel backups, same-version restore, and version-mismatch refusal. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
63 lines
1.9 KiB
Go
63 lines
1.9 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"log"
|
|
"net/http"
|
|
"time"
|
|
|
|
"codeberg.org/mix/selfpost/internal/app"
|
|
"codeberg.org/mix/selfpost/internal/buildinfo"
|
|
"codeberg.org/mix/selfpost/internal/domain"
|
|
"codeberg.org/mix/selfpost/internal/postfix"
|
|
"codeberg.org/mix/selfpost/internal/store"
|
|
"codeberg.org/mix/selfpost/internal/web"
|
|
)
|
|
|
|
// serveHTTP runs the control-panel HTTP server until ctx is cancelled, using
|
|
// the database handle shared by all roles. From Phase 2 this serves the real
|
|
// setup, login and authenticated panel surface (spec 7.6).
|
|
func serveHTTP(ctx context.Context, cfg config, st *store.Store) error {
|
|
// Applications own the SASL accounts and the Postfix sender map; the domain
|
|
// service delegates to them when a domain (and its applications) is deleted.
|
|
pf := postfix.New(cfg.postfixDir)
|
|
apps := app.NewService(st, app.NewSASLDB(cfg.saslDBPath, cfg.saslRealm), pf)
|
|
domains := domain.NewService(st, domain.NewOpenDKIM(cfg.opendkimDir), apps, cfg.dkimSelectorDef)
|
|
|
|
srvApp, err := web.New(st, domains, apps, web.Config{
|
|
Hostname: cfg.hostname,
|
|
CookieSecure: cfg.cookieSecure,
|
|
MailLogPath: cfg.mailLog,
|
|
DataDir: cfg.dataDir,
|
|
DBPath: cfg.dbPath,
|
|
Version: buildinfo.Version,
|
|
}, cfg.setupTokenPath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if err := srvApp.Start(); err != nil {
|
|
return err
|
|
}
|
|
|
|
srv := &http.Server{
|
|
Addr: cfg.httpAddr,
|
|
Handler: srvApp.Handler(),
|
|
ReadHeaderTimeout: 10 * time.Second,
|
|
}
|
|
|
|
// Shut the server down cleanly when the process is asked to stop.
|
|
go func() {
|
|
<-ctx.Done()
|
|
shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
defer cancel()
|
|
_ = srv.Shutdown(shutdownCtx)
|
|
}()
|
|
|
|
log.Printf("http panel listening on %s", cfg.httpAddr)
|
|
if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|