Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions internal/daemon/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@ import (
"github.com/schovi/shelli/internal/wait"
)

type Client struct{}
type Client struct {
customSocketPath string
}

func NewClient() *Client {
return &Client{}
}

func NewClientWithSocketPath(path string) *Client {
return &Client{customSocketPath: path}
}

func (c *Client) EnsureDaemon() error {
if c.Ping() {
return nil
Expand Down Expand Up @@ -425,7 +431,11 @@ func (c *Client) Exec(name string, opts ExecOptions) (*ExecResult, error) {
}

func (c *Client) send(req Request) (*Response, error) {
conn, err := net.Dial("unix", SocketPath())
sockPath := SocketPath()
if c.customSocketPath != "" {
sockPath = c.customSocketPath
}
conn, err := net.Dial("unix", sockPath)
if err != nil {
return nil, err
}
Expand Down
19 changes: 13 additions & 6 deletions internal/daemon/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ func WithStoppedTTL(ttl time.Duration) ServerOption {
}
}

func WithSocketDir(dir string) ServerOption {
return func(s *Server) {
s.socketDir = dir
}
}

// Deprecated: use WithStorage instead
func WithMaxOutputSize(size int) ServerOption {
return func(s *Server) {
Expand Down Expand Up @@ -159,8 +165,12 @@ func SocketPath() string {
return filepath.Join(homeDir, ".shelli", "shelli.sock")
}

func (s *Server) socketPath() string {
return filepath.Join(s.socketDir, "shelli.sock")
}

func (s *Server) Start() error {
sockPath := SocketPath()
sockPath := s.socketPath()
os.Remove(sockPath)

listener, err := net.Listen("unix", sockPath)
Expand Down Expand Up @@ -242,7 +252,7 @@ func (s *Server) Shutdown() {
s.listener.Close()
s.listener = nil
}
os.Remove(SocketPath())
os.Remove(s.socketPath())
}

type Request struct {
Expand Down Expand Up @@ -834,14 +844,12 @@ func (s *Server) handleStop(req Request) Response {
}

if h.cmd != nil {
cmd := h.cmd
proc := cmd.Process
proc := h.cmd.Process
h.cmd = nil
proc.Signal(syscall.SIGTERM)
go func() {
time.Sleep(KillGracePeriod)
proc.Signal(syscall.SIGKILL)
cmd.Wait()
}()
}
h.frameDetector = nil
Expand Down Expand Up @@ -891,7 +899,6 @@ func (s *Server) handleKill(req Request) Response {
proc.Signal(syscall.SIGTERM)
time.Sleep(KillGracePeriod)
proc.Signal(syscall.SIGKILL)
proc.Wait()
}()
}

Expand Down
Loading