kefu/cmd/stop.go

32 lines
621 B
Go
Raw Permalink Normal View History

2024-12-10 02:50:12 +00:00
package cmd
import (
"github.com/spf13/cobra"
"io/ioutil"
"kefu/common"
"os/exec"
"runtime"
"strings"
)
var stopCmd = &cobra.Command{
Use: "stop",
Short: "停止客服http服务",
Run: func(cmd *cobra.Command, args []string) {
pids, err := ioutil.ReadFile(common.RootPath + "/kefu.sock")
if err != nil {
return
}
pidSlice := strings.Split(string(pids), ",")
var command *exec.Cmd
for _, pid := range pidSlice {
if runtime.GOOS == "windows" {
command = exec.Command("taskkill.exe", "/f", "/pid", pid)
} else {
command = exec.Command("kill", pid)
}
command.Start()
}
},
}