Remind users when a VM is still running after hanger vm ssh exits instead of silently dropping them back to the host shell.\n\nAttach a Firecracker vsock device to each VM, persist the host vsock path/CID,\nadd a new guest-side banger-vsock-pingd responder to the runtime bundle and both\nimage-build paths, and expose a vm.ping RPC that the CLI and TUI call after SSH\nreturns. Doctor and start/build preflight now validate the helper plus\n/dev/vhost-vsock so the feature fails early and clearly.\n\nValidated with go mod tidy, bash -n customize.sh, git diff --check, make build,\nand GOCACHE=/tmp/banger-gocache go test ./... outside the sandbox because the\ndaemon tests need real Unix/UDP sockets. Rebuild the image/rootfs used for new\nVMs so the guest ping service is present.
49 lines
1,020 B
Go
49 lines
1,020 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
"net"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
"time"
|
|
|
|
sdkvsock "github.com/firecracker-microvm/firecracker-go-sdk/vsock"
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"banger/internal/vsockping"
|
|
)
|
|
|
|
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), vsockping.Port)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "banger-vsock-pingd: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
defer listener.Close()
|
|
|
|
for {
|
|
conn, err := listener.Accept()
|
|
if err != nil {
|
|
if ctx.Err() != nil || errors.Is(err, net.ErrClosed) {
|
|
return
|
|
}
|
|
fmt.Fprintf(os.Stderr, "banger-vsock-pingd: accept: %v\n", err)
|
|
time.Sleep(200 * time.Millisecond)
|
|
continue
|
|
}
|
|
go func(conn net.Conn) {
|
|
if err := vsockping.ServeConn(conn); err != nil {
|
|
fmt.Fprintf(os.Stderr, "banger-vsock-pingd: %v\n", err)
|
|
}
|
|
}(conn)
|
|
}
|
|
}
|