Make iterating on a Firecracker-friendly Void guest practical without replacing the Debian default image path. Add local Void rootfs build/register/verify plumbing, a language-agnostic dev package baseline, and guest SSH/work-disk hardening so new images use the runtime bundle key, keep a normal root bash environment, and repair stale nested /root layouts on restart. Replace the guest PING/PONG responder with an HTTP /healthz agent over vsock, rename the runtime bundle and config surface from ping helper to agent while still accepting the legacy keys, and route the post-SSH reminder through the new vm.health path. Validated with GOCACHE=/tmp/banger-gocache go test ./..., make build, bash -n customize.sh make-rootfs-void.sh, and git diff --check.
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
"time"
|
|
|
|
sdkvsock "github.com/firecracker-microvm/firecracker-go-sdk/vsock"
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"banger/internal/vsockagent"
|
|
)
|
|
|
|
func main() {
|
|
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
|
defer cancel()
|
|
|
|
logger := logrus.New()
|
|
logger.SetOutput(io.Discard)
|
|
listener, err := sdkvsock.Listener(ctx, logrus.NewEntry(logger), vsockagent.Port)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "banger-vsock-agent: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
defer listener.Close()
|
|
|
|
server := &http.Server{
|
|
Handler: vsockagent.NewHandler(),
|
|
ReadHeaderTimeout: 3 * time.Second,
|
|
}
|
|
|
|
errCh := make(chan error, 1)
|
|
go func() {
|
|
errCh <- server.Serve(listener)
|
|
}()
|
|
|
|
select {
|
|
case <-ctx.Done():
|
|
shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
defer shutdownCancel()
|
|
_ = server.Shutdown(shutdownCtx)
|
|
if err := <-errCh; err != nil && !errors.Is(err, http.ErrServerClosed) {
|
|
fmt.Fprintf(os.Stderr, "banger-vsock-agent: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
case err := <-errCh:
|
|
if err != nil && !errors.Is(err, http.ErrServerClosed) {
|
|
fmt.Fprintf(os.Stderr, "banger-vsock-agent: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
}
|