update
This commit is contained in:
@@ -22,6 +22,12 @@ var ExecPath, _ = filepath.Abs(filepath.Dir(os.Args[0]))
|
||||
var Config Yaml
|
||||
|
||||
func init() {
|
||||
killp()
|
||||
for _, arg := range os.Args {
|
||||
if arg == "-d" {
|
||||
Daemon()
|
||||
}
|
||||
}
|
||||
ReadYaml(ExecPath+"/conf/", &Config, "https://raw.githubusercontent.com/cdle/sillyGirl/main/conf/demo_config.yaml")
|
||||
InitReplies()
|
||||
initToHandleMessage()
|
||||
|
||||
+31
@@ -2,8 +2,10 @@ package core
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
@@ -55,3 +57,32 @@ func CompileCode() error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func killp() {
|
||||
pids, err := ppid()
|
||||
if err == nil {
|
||||
if len(pids) == 0 {
|
||||
return
|
||||
} else {
|
||||
exec.Command("sh", "-c", "kill -9 "+strings.Join(pids, " ")).Output()
|
||||
}
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func ppid() ([]string, error) {
|
||||
pid := fmt.Sprint(os.Getpid())
|
||||
pids := []string{}
|
||||
rtn, err := exec.Command("sh", "-c", "pidof "+pname).Output()
|
||||
if err != nil {
|
||||
return pids, err
|
||||
}
|
||||
re := regexp.MustCompile(`[\d]+`)
|
||||
for _, v := range re.FindAll(rtn, -1) {
|
||||
if string(v) != pid {
|
||||
pids = append(pids, string(v))
|
||||
}
|
||||
}
|
||||
return pids, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user