diff --git a/client/control.go b/client/control.go index ba37a2db..1a8b8453 100644 --- a/client/control.go +++ b/client/control.go @@ -172,6 +172,7 @@ func (ctl *Control) Close() error { ctl.mu.Lock() defer ctl.mu.Unlock() ctl.exit = true + ctl.conn.Close() ctl.pm.CloseProxies() return nil } diff --git a/client/service.go b/client/service.go index e2c65e65..866118d0 100644 --- a/client/service.go +++ b/client/service.go @@ -52,9 +52,11 @@ func (svr *Service) Run(cmd bool) error { if cmd { <-svr.closedCh + log.Info("svr closed") } else { go func() { <-svr.closedCh + log.Info("svr closed") }() } return nil @@ -62,4 +64,5 @@ func (svr *Service) Run(cmd bool) error { func (svr *Service) Close() { svr.ctl.Close() + svr.closedCh <- 0 } diff --git a/cmd/frpc/sub/root.go b/cmd/frpc/sub/root.go index 459480cd..0c3e8dc5 100644 --- a/cmd/frpc/sub/root.go +++ b/cmd/frpc/sub/root.go @@ -112,6 +112,16 @@ func RunFrpc(cfgFilePath string) (err error) { return runClient(cfgFilePath) } +func StopFrp() (err error) { + if service == nil { + return fmt.Errorf("frp not start") + } + + service.Close() + log.Info("frpc is stoped") + return +} + func handleSignal(svr *client.Service) { ch := make(chan os.Signal) signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM) @@ -225,13 +235,3 @@ func startService(pxyCfgs map[string]config.ProxyConf, visitorCfgs map[string]co err = svr.Run(cmd) return } - -func StopFrp() (err error) { - if service == nil { - return fmt.Errorf("frp not start") - } - - service.Close() - log.Info("frpc is stoped") - return -}