feat: add command to stop running holesail processes

This commit is contained in:
2025-02-16 09:30:02 +01:00
parent 5c958b2b2d
commit f33ccec5c4
4 changed files with 69 additions and 1 deletions

46
cmd/down.go Normal file
View 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)
},
}

View File

@ -84,7 +84,10 @@ var upCmd = &cobra.Command{
httputil.NewSingleHostReverseProxy(appUrl).ServeHTTP(w, r)
})
http.ListenAndServe(":80", nil)
err := http.ListenAndServe(":80", nil)
if err != nil {
fmt.Println(err)
}
},
}