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