You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
582 B
31 lines
582 B
package cmd
|
|
|
|
import (
|
|
"github.com/spf13/cobra"
|
|
"io/ioutil"
|
|
"os/exec"
|
|
"runtime"
|
|
"strings"
|
|
)
|
|
|
|
var stopCmd = &cobra.Command{
|
|
Use: "stop",
|
|
Short: "停止http服务",
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
pids, err := ioutil.ReadFile("gofly.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()
|
|
}
|
|
},
|
|
}
|