From ceb44e936f71fae0e5c8874710ff89a92cc6997e Mon Sep 17 00:00:00 2001 From: ayflying Date: Thu, 30 Oct 2025 18:16:14 +0800 Subject: [PATCH] =?UTF-8?q?linux=E4=BD=BF=E7=94=A8=E8=BD=AF=E9=87=8D?= =?UTF-8?q?=E5=90=AF=EF=BC=8C=E9=A2=84=E9=98=B2=E5=8D=A1=E8=BF=9B=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/logic/system/system.go | 2 +- internal/logic/system/update.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/internal/logic/system/system.go b/internal/logic/system/system.go index 5ca3fb8..e901047 100644 --- a/internal/logic/system/system.go +++ b/internal/logic/system/system.go @@ -26,4 +26,4 @@ func init() { } } -func (system *sSystem) Init() {} +func (s *sSystem) Init() {} diff --git a/internal/logic/system/update.go b/internal/logic/system/update.go index 8b0bfde..5f94bb5 100644 --- a/internal/logic/system/update.go +++ b/internal/logic/system/update.go @@ -17,6 +17,7 @@ import ( "github.com/ayflying/p2p/internal/service" "github.com/gogf/gf/v2/encoding/gcompress" "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" "github.com/gogf/gf/v2/os/gcmd" "github.com/gogf/gf/v2/os/gctx" "github.com/gogf/gf/v2/os/gfile" @@ -84,6 +85,16 @@ func (s *sSystem) Update(ctx context.Context, gzFile string) (err error) { // RestartSelf 实现 Windows 平台下的程序自重启 func (s *sSystem) RestartSelf() error { + ctx := gctx.New() + // 判断是否为linux平台 + if runtime.GOOS == "linux" { + err := ghttp.RestartAllServer(ctx, os.Args[0]) + if err != nil { + g.Log().Errorf(ctx, "重启失败:%v", err) + } + return err + } + // 1. 获取当前程序的绝对路径 exePath, err := os.Executable() if err != nil {