mirror of
https://github.com/CyberL1/holesail-proxy.git
synced 2025-06-28 08:09:42 -04:00
feat: add command to stop running holesail processes
This commit is contained in:
46
cmd/down.go
Normal file
46
cmd/down.go
Normal file
@ -0,0 +1,46 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/shirou/gopsutil/process"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(downCmd)
|
||||
}
|
||||
|
||||
var downCmd = &cobra.Command{
|
||||
Use: "down",
|
||||
Short: "Stop running holesail processes",
|
||||
Args: cobra.NoArgs,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
processes, err := process.Processes()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
var stoppedProcesses int
|
||||
|
||||
for _, process := range processes {
|
||||
processName, _ := process.Name()
|
||||
cmdLine, _ := process.Cmdline()
|
||||
|
||||
if processName == "node" {
|
||||
cmdLineSplitted := strings.Split(cmdLine, "/")
|
||||
cmdLineWithoutBloat := strings.Join(cmdLineSplitted[len(cmdLineSplitted)-3:], "/")
|
||||
|
||||
if strings.HasPrefix(cmdLineWithoutBloat, "node_modules/holesail/index.js") {
|
||||
process.SendSignal(syscall.SIGINT)
|
||||
stoppedProcesses++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("Stopped %v holesail processes\n", stoppedProcesses)
|
||||
},
|
||||
}
|
Reference in New Issue
Block a user