From 08fa44c8053e7ae7df4abbc503dd786178b783cd Mon Sep 17 00:00:00 2001 From: wyaode <33099640+wyaode@users.noreply.github.com> Date: Mon, 13 Apr 2020 09:03:18 +0800 Subject: [PATCH] Update main.go --- cmd/frps/main.go | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/cmd/frps/main.go b/cmd/frps/main.go index 50be5862..7f3758ec 100644 --- a/cmd/frps/main.go +++ b/cmd/frps/main.go @@ -22,11 +22,42 @@ import ( _ "github.com/fatedier/frp/assets/frps/statik" _ "github.com/fatedier/frp/models/metrics" + "github.com/kardianos/service" + "os" + "path/filepath" ) func main() { crypto.DefaultSalt = "frp" rand.Seed(time.Now().UnixNano()) - Execute() + svcConfig := &service.Config{ + Name: "FRPS", + } + prg := &FRPS{} + s, err := service.New(prg, svcConfig) + if err != nil { + Execute() + return + } + + dir, err := filepath.Abs(filepath.Dir(os.Args[0])) //chang workdir + err = os.Chdir(dir) + _ = s.Run() +} + +type FRPS struct {} + +func (p *FRPS) Start(s service.Service) error { + _, _ = s.Status() + go Execute() + return nil +} + +func (p *FRPS) Stop(s service.Service) error { + _, _ = s.Status() + if service.Interactive() { + os.Exit(0) + } + return nil }