Files
collector/cmd/main.go
2026-04-24 18:26:01 +08:00

31 lines
706 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package main
import (
"fmt"
"os"
"git.apinb.com/quant/collector/internal/impl"
"git.apinb.com/quant/collector/internal/logic"
"github.com/marcsauter/single"
)
func main() {
// 互斥体名称Global\CollectorSingleInstance 确保会话全局唯一
s := single.New("CollectorSingleInstance")
// 尝试加锁,如果已有实例运行会返回错误
if err := s.CheckLock(); err != nil {
if err == single.ErrAlreadyRunning {
fmt.Println("collector.exe 已有实例正在运行,本次启动退出。")
os.Exit(0)
}
fmt.Fprintf(os.Stderr, "检查单实例失败: %v\n", err)
os.Exit(1)
}
// 进程退出时自动释放锁
defer s.TryUnlock()
impl.NewImpl()
logic.Boot()
}