mirror of
https://github.com/profullstack/agentbbs.git
synced 2026-11-29 15:31:53 +00:00
feat: add isolated operational-status pilot (#177)
* feat: add isolated operational-status pilot * fix: allow tailnet peers through loopback sidecar * build: add pinned non-root pilot container
This commit is contained in:
parent
5f1c3f4985
commit
8a6e2f905f
9 changed files with 1509 additions and 0 deletions
|
|
@ -78,6 +78,7 @@ import (
|
|||
"github.com/profullstack/agentbbs/internal/motd"
|
||||
"github.com/profullstack/agentbbs/internal/news"
|
||||
"github.com/profullstack/agentbbs/internal/payments"
|
||||
"github.com/profullstack/agentbbs/internal/pilot"
|
||||
"github.com/profullstack/agentbbs/internal/plugin"
|
||||
"github.com/profullstack/agentbbs/internal/pods"
|
||||
"github.com/profullstack/agentbbs/internal/sandbox"
|
||||
|
|
@ -143,6 +144,23 @@ func main() {
|
|||
return
|
||||
}
|
||||
dataDir := env("AGENTBBS_DATA", "./data")
|
||||
if env("AGENTBBS_PILOT", "") == "1" {
|
||||
cfg := pilot.ConfigFromEnv(dataDir)
|
||||
if len(os.Args) > 1 && os.Args[1] == "pilot-backup" {
|
||||
pilotBackup(cfg, os.Args[2:])
|
||||
return
|
||||
}
|
||||
if len(os.Args) > 1 && os.Args[1] == "pilot-restore" {
|
||||
pilotRestore(cfg, os.Args[2:])
|
||||
return
|
||||
}
|
||||
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
|
||||
defer cancel()
|
||||
if err := pilot.Run(ctx, cfg); err != nil {
|
||||
log.Fatal("pilot", "err", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
_ = os.MkdirAll(filepath.Join(dataDir, "users"), 0o755)
|
||||
|
||||
st, err := store.Open(filepath.Join(dataDir, "agentbbs.db"))
|
||||
|
|
|
|||
59
cmd/agentbbs/pilot_ops.go
Normal file
59
cmd/agentbbs/pilot_ops.go
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/profullstack/agentbbs/internal/pilot"
|
||||
)
|
||||
|
||||
func requireExistingPilotDatabase(path string) error {
|
||||
info, err := os.Lstat(path)
|
||||
if err != nil {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return errors.New("pilot database does not exist; start the pilot before taking a backup")
|
||||
}
|
||||
return err
|
||||
}
|
||||
if !info.Mode().IsRegular() || info.Mode()&os.ModeSymlink != 0 {
|
||||
return errors.New("pilot database is not a regular file")
|
||||
}
|
||||
if info.Mode().Perm()&0o077 != 0 {
|
||||
return fmt.Errorf("pilot database permissions %04o are too broad", info.Mode().Perm())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func pilotBackup(cfg pilot.Config, args []string) {
|
||||
if len(args) != 1 {
|
||||
fmt.Fprintln(os.Stderr, "usage: agentbbs pilot-backup <new-destination>")
|
||||
os.Exit(2)
|
||||
}
|
||||
if err := requireExistingPilotDatabase(cfg.DatabasePath); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "pilot-backup:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
st, err := pilot.Open(cfg.DatabasePath)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "pilot-backup:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer st.Close()
|
||||
if err := st.Backup(args[0]); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "pilot-backup:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Fprintln(os.Stdout, args[0])
|
||||
}
|
||||
|
||||
func pilotRestore(cfg pilot.Config, args []string) {
|
||||
if len(args) != 1 {
|
||||
fmt.Fprintln(os.Stderr, "usage: agentbbs pilot-restore <verified-source>")
|
||||
os.Exit(2)
|
||||
}
|
||||
if err := pilot.Restore(args[0], cfg.DatabasePath); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "pilot-restore:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Fprintln(os.Stdout, cfg.DatabasePath)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue