fix log message and add force kill
This commit is contained in:
11
cmd/stop.go
11
cmd/stop.go
@@ -12,6 +12,7 @@ import (
|
||||
var optsStopCmd = struct {
|
||||
Debug *bool
|
||||
PID *int
|
||||
Force *bool
|
||||
}{}
|
||||
|
||||
var stopCmd = &cobra.Command{
|
||||
@@ -34,12 +35,17 @@ var stopCmd = &cobra.Command{
|
||||
panic(err)
|
||||
}
|
||||
*optsStopCmd.PID = pid
|
||||
slog.Debug("restarting server", slog.Int("pid", *optsStopCmd.PID))
|
||||
proc, err := os.FindProcess(*optsStopCmd.PID)
|
||||
if err != nil {
|
||||
slog.Error("failed to find process", slog.Int("pid", *optsStopCmd.PID), slog.String("err", err.Error()))
|
||||
}
|
||||
proc.Signal(syscall.SIGTERM)
|
||||
if *optsStopCmd.Force {
|
||||
slog.Debug("force stopping server by SIGKILL", slog.Int("pid", *optsStopCmd.PID))
|
||||
proc.Signal(syscall.SIGKILL)
|
||||
} else {
|
||||
slog.Debug("stopping server", slog.Int("pid", *optsStopCmd.PID))
|
||||
proc.Signal(syscall.SIGTERM)
|
||||
}
|
||||
slog.Debug("done")
|
||||
},
|
||||
}
|
||||
@@ -47,5 +53,6 @@ var stopCmd = &cobra.Command{
|
||||
func init() {
|
||||
optsStopCmd.Debug = stopCmd.Flags().BoolP("debug", "d", false, "Enable debug logs")
|
||||
optsStopCmd.PID = stopCmd.Flags().IntP("pid", "p", -1, "Define server PID")
|
||||
optsStopCmd.Force = stopCmd.Flags().BoolP("force", "f", false, "Force stop using SIGKILL")
|
||||
rootCmd.AddCommand(stopCmd)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user