mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-05-27 12:52:27 +02:00
refactor: replace Unix socket log communication with HTTP-based system
Replace the legacy Unix socket log communication between `ctrld start` and `ctrld run` with a modern HTTP-based system for better reliability and maintainability. Benefits: - More reliable communication protocol using standard HTTP - Better error handling and connection management - Cleaner separation of concerns with dedicated endpoints - Easier to test and debug with HTTP-based communication - More maintainable code with proper abstraction layers This change maintains backward compatibility while providing a more robust foundation for inter-process communication between ctrld commands.
This commit is contained in:
committed by
Cuong Manh Le
parent
a04babbbc3
commit
56f8113bb0
+2
-23
@@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"math/rand"
|
||||
"net"
|
||||
@@ -91,7 +92,7 @@ type prog struct {
|
||||
apiReloadCh chan *ctrld.Config
|
||||
apiForceReloadCh chan struct{}
|
||||
apiForceReloadGroup singleflight.Group
|
||||
logConn net.Conn
|
||||
logConn io.WriteCloser
|
||||
cs *controlServer
|
||||
logger atomic.Pointer[ctrld.Logger]
|
||||
csSetDnsDone chan struct{}
|
||||
@@ -1148,28 +1149,6 @@ func randomPort() int {
|
||||
return n
|
||||
}
|
||||
|
||||
// runLogServer starts a unix listener, use by startCmd to gather log from runCmd.
|
||||
func runLogServer(sockPath string) net.Conn {
|
||||
addr, err := net.ResolveUnixAddr("unix", sockPath)
|
||||
if err != nil {
|
||||
mainLog.Load().Warn().Err(err).Msg("Invalid log sock path")
|
||||
return nil
|
||||
}
|
||||
ln, err := net.ListenUnix("unix", addr)
|
||||
if err != nil {
|
||||
mainLog.Load().Warn().Err(err).Msg("Could not listen log socket")
|
||||
return nil
|
||||
}
|
||||
defer ln.Close()
|
||||
|
||||
server, err := ln.Accept()
|
||||
if err != nil {
|
||||
mainLog.Load().Warn().Err(err).Msg("Could not accept connection")
|
||||
return nil
|
||||
}
|
||||
return server
|
||||
}
|
||||
|
||||
func errAddrInUse(err error) bool {
|
||||
var opErr *net.OpError
|
||||
if errors.As(err, &opErr) {
|
||||
|
||||
Reference in New Issue
Block a user