feat: add Unix control service and rvc queue path

This commit is contained in:
2026-09-06 09:57:36 +00:00
parent ca26d35632
commit 3f6fb89a41
10 changed files with 1371 additions and 5 deletions
+31 -2
View File
@@ -13,10 +13,13 @@ import (
"os/signal"
"syscall"
rvboxv1 "github.com/rvbox/rvbox/gen/go/rvbox/v1"
"github.com/rvbox/rvbox/internal/agentproto"
"github.com/rvbox/rvbox/internal/config"
"github.com/rvbox/rvbox/internal/server/control"
"github.com/rvbox/rvbox/internal/server/session"
"github.com/rvbox/rvbox/internal/server/store"
"google.golang.org/grpc"
)
func main() {
@@ -60,6 +63,21 @@ func run(configPath string) error {
if err != nil {
return fmt.Errorf("listen for agents: %w", err)
}
defer listener.Close()
controlListener, cleanupControl, err := control.ListenUnix(configured.Server.ControlSocket)
if err != nil {
return err
}
defer func() { _ = cleanupControl() }()
controlService, err := control.NewService(control.Options{
Store: persistence, DefaultQueueTTL: configured.Queue.DefaultTTL, DefaultQueueTTLSet: true,
Limits: agentproto.Limits{MaxEnvelopeBytes: configured.Protocol.MaxAgentEnvelopeBytes, MaxExecutionSpecBytes: configured.Protocol.MaxExecutionSpecBytes, MaxRawChunkBytes: configured.Protocol.MaxRawChunkBytes, MaxScriptBytes: configured.Protocol.MaxScriptBytes, MaxDetailBytes: configured.Storage.ProtocolDetailMaxBytes},
})
if err != nil {
return err
}
grpcServer := grpc.NewServer(grpc.MaxRecvMsgSize(int(configured.Protocol.MaxControlRequestBytes)), grpc.MaxSendMsgSize(int(configured.Protocol.MaxControlRequestBytes)))
rvboxv1.RegisterControlServer(grpcServer, controlService)
agent := &session.AgentServer{
Store: persistence, Registry: session.NewRegistry(), Path: configured.Server.AgentPath,
Limits: agentproto.Limits{
@@ -73,8 +91,9 @@ func run(configPath string) error {
HeartbeatIdle: configured.Protocol.HeartbeatIdle, LivenessTimeout: configured.Protocol.LivenessTimeout,
}
httpServer := &http.Server{Handler: agent, ReadHeaderTimeout: configured.Flow.WriteDeadline}
serveError := make(chan error, 1)
serveError := make(chan error, 2)
go func() { serveError <- httpServer.Serve(listener) }()
go func() { serveError <- grpcServer.Serve(controlListener) }()
signals := make(chan os.Signal, 1)
signal.Notify(signals, os.Interrupt, syscall.SIGTERM)
@@ -82,12 +101,22 @@ func run(configPath string) error {
select {
case err := <-serveError:
if errors.Is(err, http.ErrServerClosed) {
grpcServer.Stop()
return nil
}
grpcServer.Stop()
return err
case <-signals:
shutdownContext, cancel := context.WithTimeout(context.Background(), configured.Server.ShutdownGrace)
defer cancel()
return httpServer.Shutdown(shutdownContext)
httpErr := httpServer.Shutdown(shutdownContext)
grpcDone := make(chan struct{})
go func() { grpcServer.GracefulStop(); close(grpcDone) }()
select {
case <-grpcDone:
case <-shutdownContext.Done():
grpcServer.Stop()
}
return httpErr
}
}