mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2026-03-02 13:05:36 +08:00
优化Daemon代码
This commit is contained in:
@@ -24,7 +24,6 @@ import (
|
|||||||
"github.com/iwind/gosock/pkg/gosock"
|
"github.com/iwind/gosock/pkg/gosock"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
@@ -43,7 +42,9 @@ type Node struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewNode() *Node {
|
func NewNode() *Node {
|
||||||
return &Node{}
|
return &Node{
|
||||||
|
sock: gosock.NewTmpSock(teaconst.ProcessName),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test 检查配置
|
// Test 检查配置
|
||||||
@@ -155,11 +156,10 @@ func (this *Node) Start() {
|
|||||||
|
|
||||||
// Daemon 实现守护进程
|
// Daemon 实现守护进程
|
||||||
func (this *Node) Daemon() {
|
func (this *Node) Daemon() {
|
||||||
path := os.TempDir() + "/edge-node.sock"
|
|
||||||
isDebug := lists.ContainsString(os.Args, "debug")
|
isDebug := lists.ContainsString(os.Args, "debug")
|
||||||
isDebug = true
|
isDebug = true
|
||||||
for {
|
for {
|
||||||
conn, err := net.DialTimeout("unix", path, 1*time.Second)
|
conn, err := this.sock.Dial()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if isDebug {
|
if isDebug {
|
||||||
log.Println("[DAEMON]starting ...")
|
log.Println("[DAEMON]starting ...")
|
||||||
@@ -457,8 +457,6 @@ func (this *Node) checkClusterConfig() error {
|
|||||||
|
|
||||||
// 监听本地sock
|
// 监听本地sock
|
||||||
func (this *Node) listenSock() error {
|
func (this *Node) listenSock() error {
|
||||||
this.sock = gosock.NewTmpSock(teaconst.ProcessName)
|
|
||||||
|
|
||||||
// 检查是否在运行
|
// 检查是否在运行
|
||||||
if this.sock.IsListening() {
|
if this.sock.IsListening() {
|
||||||
reply, err := this.sock.Send(&gosock.Command{Code: "pid"})
|
reply, err := this.sock.Send(&gosock.Command{Code: "pid"})
|
||||||
|
|||||||
Reference in New Issue
Block a user