Skip to content
Open
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
24 changes: 24 additions & 0 deletions cmd_signal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import (
"fmt"
"strings"

"github.com/DarthSim/overmind/v2/utils"
"github.com/urfave/cli"
)

type cmdSignalHandler struct{ dialer }

func (h *cmdSignalHandler) Run(c *cli.Context) error {
if len(c.Args()) < 1 {
utils.Fatal("Signal name is required")
}

conn, err := h.Dial()
utils.FatalOnErr(err)

fmt.Fprintf(conn, "signal %v\n", strings.Join(c.Args(), " "))

return nil
}
13 changes: 13 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ func setupQuitCmd() cli.Command {
}
}

func setupSignalCmd() cli.Command {
c := cmdSignalHandler{}

return cli.Command{
Name: "signal",
Usage: "Send a signal to specified processes (or all if none specified)",
Action: c.Run,
ArgsUsage: "<signal> [process name...]",
Flags: socketFlags(&c.SocketPath, &c.Network),
}
}

func setupKillCmd() cli.Command {
c := cmdKillHandler{}

Expand Down Expand Up @@ -192,6 +204,7 @@ func main() {
setupStartCmd(),
setupRestartCmd(),
setupStopCmd(),
setupSignalCmd(),
setupConnectCmd(),
setupQuitCmd(),
setupKillCmd(),
Expand Down
29 changes: 29 additions & 0 deletions start/command_center.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ func (c *commandCenter) handleConnection(conn net.Conn) {
c.processRestart(args)
case "stop":
c.processStop(args)
case "signal":
c.processSignal(args)
case "quit":
c.processQuit()
case "kill":
Expand Down Expand Up @@ -132,6 +134,33 @@ func (c *commandCenter) processStop(args []string) {
}
}

func (c *commandCenter) processSignal(args []string) {
if len(args) == 0 {
return
}

sig, ok := signalMap[args[0]]
if !ok {
return
}

processes := args[1:]

for _, p := range c.cmd.processes {
if len(processes) == 0 {
p.Signal(sig)
continue
}

for _, pattern := range processes {
if utils.WildcardMatch(pattern, p.Name) {
p.Signal(sig)
break
}
}
}
}

func (c *commandCenter) processKill() {
for _, p := range c.cmd.processes {
p.Kill(false)
Expand Down
1 change: 1 addition & 0 deletions start/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

var signalMap = map[string]syscall.Signal{
"ABRT": syscall.SIGABRT,
"HUP": syscall.SIGHUP,
"INT": syscall.SIGINT,
"KILL": syscall.SIGKILL,
"QUIT": syscall.SIGQUIT,
Expand Down
9 changes: 9 additions & 0 deletions start/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ func (p *process) Kill(keepAlive bool) {
}
}

func (p *process) Signal(sig syscall.Signal) {
if p.Running() {
p.output.WriteBoldLinef(p, "Sending signal %v...", sig)
if err := p.groupSignal(sig); err != nil {
p.output.WriteErr(p, fmt.Errorf("Can't send signal: %s", err))
}
}
}

func (p *process) Info() {
p.groupSignal(SIGINFO)
}
Expand Down