Skip to content

Commit

Permalink
feat: windows pluign use tcp listen
Browse files Browse the repository at this point in the history
  • Loading branch information
ifooth committed Oct 15, 2024
1 parent 1adb288 commit 1fe7fff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
14 changes: 10 additions & 4 deletions build/nodemanPlugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,7 @@ func serveHttp() error {
return err
}

// 强制清理老的sock文件
unitSocketPath := filepath.Join(conf.PidPath, unitSocketFile)
_ = os.Remove(unitSocketPath)
listen, err := net.Listen("unix", unitSocketPath)
listen, err := netListen()
if err != nil {
logger.Error("start http server failed", logger.ErrAttr(err))
return err
Expand All @@ -221,6 +218,15 @@ func serveHttp() error {
return nil
}

// netListen 默认监听 unix_socket, 可以支持多个实例
func netListen() (net.Listener, error) {
// 强制清理老的sock文件
unitSocketPath := filepath.Join(conf.PidPath, unitSocketFile)
_ = os.Remove(unitSocketPath)

return net.Listen("unix", unitSocketPath)
}

func checkProcess(pidPath string) error {
data, err := os.ReadFile(pidPath)
if err != nil {
Expand Down
13 changes: 13 additions & 0 deletions build/nodemanPlugin/main_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
"fmt"
"net"

"github.com/TencentBlueKing/bscp-go/internal/constant"
)

// netListen windows 2008/2012/2016 不支持 unix_socket, 使用监听 tcp 方式, 只允许一个实例
func netListen() (net.Listener, error) {
return net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", constant.DefaultHttpPort))
}

0 comments on commit 1fe7fff

Please sign in to comment.