Files
at-container-registry/deploy/upcloud/status.go
T
Evan JarrettandClaude Fable 5.1 83092d9aee deploy: give the scanner its own server, and stop the tool from undoing production fixes on provision
The scanner shared the hold's 1 GB host and thrashed it twice: 11 hours on
2026-09-12 and again on the 13th (644 MiB resident plus 1.9 GB of swap, 504
on every repo page). It is memory-bound, not CPU-bound, so it now gets a
dedicated STARTER-2xCPU-4GB server: own state entry, own plan flag (pinned
name, shape match if UpCloud renames the tier again, picker last), own
cloud-init, firewall, `update scanner`, `ssh scanner`, status, backup and
teardown. Its config reaches the hold over the private network and its unit
sets MemorySwapMax=0 so an overshoot is an OOM kill and a restart, not a
wedged host. The hold's cloud-init and update paths no longer carry it.

Three defects the first provision run exposed, all fixed here:

- Frontend HTTP/2 defaulted to on and was reconciled onto the LB every run.
  Re-enabling it on the 12th stranded the appview<->hold connections for
  25 minutes. Default is now off and reconciled off, with a guard test.
- The TLS step requested Let's Encrypt bundles for every registry domain,
  re-adding the .cr ones that were removed when those moved behind Bunny.
  It now skips any domain whose DNS does not resolve to the LB.
- Each prompt built its own bufio.Scanner on stdin, so the first swallowed
  every piped answer and the second read EOF and took the default, which
  re-ran cloud-init on the production hold. One shared reader, and no answer
  now means skip.

Also: STARTER- plans take standard storage (maxiops fails with TIER_INVALID),
and the cloud-init wait polls for up to 20 minutes instead of one SSH call
capped at five, which a first boot with npm exceeds.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hho5da4daoCoPBJ9tCrL7s
2026-09-12 21:49:26 -05:00

130 lines
3.4 KiB
Go

package main
import (
"context"
"fmt"
"strings"
"time"
"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud/request"
"github.com/spf13/cobra"
)
var statusCmd = &cobra.Command{
Use: "status",
Short: "Show infrastructure state and health",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
token, _ := cmd.Root().PersistentFlags().GetString("token")
return cmdStatus(token)
},
}
func init() {
rootCmd.AddCommand(statusCmd)
}
func cmdStatus(token string) error {
state, err := loadState()
if err != nil {
return err
}
naming := state.Naming()
svc, err := newService(token)
if err != nil {
return err
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
fmt.Printf("Zone: %s\n\n", state.Zone)
// Server status
servers := []struct {
name string
ss ServerState
serviceName string
healthURL string
}{
{"Appview", state.Appview, naming.Appview(), "http://localhost:5000/health"},
{"Hold", state.Hold, naming.Hold(), "http://localhost:8080/xrpc/_health"},
}
if state.ScannerEnabled || state.Scanner.UUID != "" {
servers = append(servers, struct {
name string
ss ServerState
serviceName string
healthURL string
}{"Scanner", state.Scanner, naming.Scanner(), "http://localhost:9090/healthz"})
}
for _, s := range servers {
fmt.Printf("%-8s UUID: %s\n", s.name, s.ss.UUID)
fmt.Printf(" Public: %s\n", s.ss.PublicIP)
fmt.Printf(" Private: %s\n", s.ss.PrivateIP)
if s.ss.UUID != "" {
details, err := svc.GetServerDetails(ctx, &request.GetServerDetailsRequest{
UUID: s.ss.UUID,
})
if err != nil {
fmt.Printf(" State: error (%v)\n", err)
} else {
fmt.Printf(" State: %s\n", details.State)
}
}
// SSH health check
if s.ss.PublicIP != "" {
output, err := runSSH(s.ss.PublicIP, fmt.Sprintf(
"systemctl is-active %s 2>/dev/null || echo 'inactive'; curl -sf %s > /dev/null 2>&1 && echo 'health:ok' || echo 'health:fail'",
s.serviceName, s.healthURL,
), false)
if err != nil {
fmt.Printf(" Service: unreachable\n")
} else {
lines := strings.SplitSeq(strings.TrimSpace(output), "\n")
for line := range lines {
line = strings.TrimSpace(line)
if line == "active" || line == "inactive" {
fmt.Printf(" Service: %s\n", line)
} else if after, ok := strings.CutPrefix(line, "health:"); ok {
fmt.Printf(" Health: %s\n", after)
}
}
}
}
fmt.Println()
}
// LB status
if state.LB.UUID != "" {
fmt.Printf("Load Balancer: %s\n", state.LB.UUID)
lb, err := svc.GetLoadBalancer(ctx, &request.GetLoadBalancerRequest{
UUID: state.LB.UUID,
})
if err != nil {
fmt.Printf(" State: error (%v)\n", err)
} else {
fmt.Printf(" State: %s\n", lb.OperationalState)
for _, n := range lb.Networks {
fmt.Printf(" Network (%s): %s\n", n.Type, n.DNSName)
}
}
}
fmt.Printf("\nNetwork: %s\n", state.Network.UUID)
if state.ObjectStorage.UUID != "" {
fmt.Printf("\nObject Storage: %s\n", state.ObjectStorage.UUID)
fmt.Printf(" Endpoint: %s\n", state.ObjectStorage.Endpoint)
fmt.Printf(" Region: %s\n", state.ObjectStorage.Region)
fmt.Printf(" Bucket: %s\n", state.ObjectStorage.Bucket)
fmt.Printf(" Access Key: %s\n", state.ObjectStorage.AccessKeyID)
}
return nil
}