feat:支持自动退出多余守护进程
This commit is contained in:
@@ -1,9 +1,22 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"autoLogin/util"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type daemon struct {
|
||||||
|
Mark string
|
||||||
|
Path string
|
||||||
|
}
|
||||||
|
|
||||||
|
var Daemon = daemon{
|
||||||
|
Mark: fmt.Sprint(time.Now().UnixNano()),
|
||||||
|
Path: "autoLoginDaemon",
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
goDaemon := flag.Bool("daemon", false, "")
|
goDaemon := flag.Bool("daemon", false, "")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
@@ -11,3 +24,15 @@ func init() {
|
|||||||
Guardian(false)
|
Guardian(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *daemon) MarkDaemon() error {
|
||||||
|
return util.File.Write(a.Path, []byte(a.Mark))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *daemon) CheckDaemon() bool {
|
||||||
|
if data, err := util.File.Read(a.Path); err != nil {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return string(data) == a.Mark
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,8 +9,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Guardian(output bool) {
|
func Guardian(output bool) {
|
||||||
|
global.Status.Output = output
|
||||||
|
|
||||||
|
if e := Daemon.MarkDaemon(); e != nil {
|
||||||
|
util.Log.Fatalln(e)
|
||||||
|
}
|
||||||
|
|
||||||
var c = make(chan bool)
|
var c = make(chan bool)
|
||||||
for {
|
for {
|
||||||
|
if !Daemon.CheckDaemon() {
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
global.Status.Output = output
|
global.Status.Output = output
|
||||||
time.Sleep(time.Duration(global.Config.Settings.Guardian) * time.Second)
|
time.Sleep(time.Duration(global.Config.Settings.Guardian) * time.Second)
|
||||||
go func() {
|
go func() {
|
||||||
|
|||||||
Reference in New Issue
Block a user