Start 启动
()
| 110 | |
| 111 | // Start 启动 |
| 112 | func (this *Node) Start() { |
| 113 | // 设置netdns |
| 114 | // 这个需要放在所有网络访问的最前面 |
| 115 | _ = os.Setenv("GODEBUG", "netdns=go") |
| 116 | |
| 117 | _, ok := os.LookupEnv("EdgeDaemon") |
| 118 | if ok { |
| 119 | remotelogs.Println("NODE", "start from daemon") |
| 120 | DaemonIsOn = true |
| 121 | DaemonPid = os.Getppid() |
| 122 | } |
| 123 | |
| 124 | // 处理异常 |
| 125 | this.handlePanic() |
| 126 | |
| 127 | // 监听signal |
| 128 | this.listenSignals() |
| 129 | |
| 130 | // 本地Sock |
| 131 | err := this.listenSock() |
| 132 | if err != nil { |
| 133 | remotelogs.Error("NODE", err.Error()) |
| 134 | return |
| 135 | } |
| 136 | |
| 137 | // 启动IP库 |
| 138 | remotelogs.Println("NODE", "initializing ip library ...") |
| 139 | err = iplib.InitDefault() |
| 140 | if err != nil { |
| 141 | remotelogs.Error("NODE", "initialize ip library failed: "+err.Error()) |
| 142 | } |
| 143 | |
| 144 | // 启动事件 |
| 145 | events.Notify(events.EventStart) |
| 146 | |
| 147 | // 读取API配置 |
| 148 | remotelogs.Println("NODE", "init config ...") |
| 149 | err = this.syncConfig(0) |
| 150 | if err != nil { |
| 151 | _, err = nodeconfigs.SharedNodeConfig() |
| 152 | if err != nil { |
| 153 | // 无本地数据时,会尝试多次读取 |
| 154 | tryTimes := 0 |
| 155 | for { |
| 156 | err = this.syncConfig(0) |
| 157 | if err != nil { |
| 158 | tryTimes++ |
| 159 | |
| 160 | if tryTimes%10 == 0 { |
| 161 | remotelogs.Error("NODE", err.Error()) |
| 162 | } |
| 163 | time.Sleep(1 * time.Second) |
| 164 | |
| 165 | // 不做长时间的无意义的重试 |
| 166 | if tryTimes > 1000 { |
| 167 | return |
| 168 | } |
| 169 | } else { |
nothing calls this directly
no test coverage detected