This commit is contained in:
cdle
2021-09-30 19:09:55 +08:00
parent 2489b6e3f5
commit 4367b0e268
+17 -11
View File
@@ -8,6 +8,7 @@ import (
"regexp" "regexp"
"runtime" "runtime"
"strings" "strings"
"syscall"
"time" "time"
"github.com/astaxie/beego/logs" "github.com/astaxie/beego/logs"
@@ -15,6 +16,8 @@ import (
var BeforeStop = []func(){} var BeforeStop = []func(){}
var pidf = "/var/run/sillyGirl.pid"
func Daemon() { func Daemon() {
for _, bs := range BeforeStop { for _, bs := range BeforeStop {
bs() bs()
@@ -34,7 +37,7 @@ func Daemon() {
panic(err) panic(err)
} }
logs.Info(sillyGirl.Get("name", "傻妞") + "以静默形式运行") logs.Info(sillyGirl.Get("name", "傻妞") + "以静默形式运行")
os.Exit(0) os.WriteFile(pidf, []byte(fmt.Sprintf("%d", proc.Process.Pid)), 0o644)
} }
func GitPull(filename string) (bool, error) { func GitPull(filename string) (bool, error) {
@@ -66,16 +69,19 @@ func CompileCode() error {
} }
func killp() { func killp() {
pids, err := ppid() data, _ := os.ReadFile(pidf)
if err == nil { pid := Int(string(data))
if len(pids) == 0 { syscall.Kill(-pid, syscall.SIGKILL)
return // pids, err := ppid()
} else { // if err == nil {
exec.Command("sh", "-c", "kill -9 "+strings.Join(pids, " ")).Output() // if len(pids) == 0 {
} // return
} else { // } else {
return // exec.Command("sh", "-c", "kill -9 "+strings.Join(pids, " ")).Output()
} // }
// } else {
// return
// }
} }
func ppid() ([]string, error) { func ppid() ([]string, error) {