Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
oceanbase
obagent
提交
bcb13a5c
O
obagent
项目概览
oceanbase
/
obagent
1 年多 前同步成功
通知
3
Star
15
Fork
4
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
obagent
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
未验证
提交
bcb13a5c
编写于
2月 07, 2022
作者:
C
chris-sun-star
提交者:
GitHub
2月 07, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #23 from chris-sun-star/optimize_startup
fix #22 quit when start http server failed
上级
4f256847
f46a2072
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
26 addition
and
8 deletion
+26
-8
engine/monagent_server.go
engine/monagent_server.go
+26
-8
未找到文件。
engine/monagent_server.go
浏览文件 @
bcb13a5c
...
@@ -16,13 +16,16 @@ import (
...
@@ -16,13 +16,16 @@ import (
"context"
"context"
"net/http"
"net/http"
"sync"
"sync"
"time"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
"github.com/pkg/errors"
log
"github.com/sirupsen/logrus"
"github.com/oceanbase/obagent/api/route"
"github.com/oceanbase/obagent/api/route"
"github.com/oceanbase/obagent/api/web"
"github.com/oceanbase/obagent/api/web"
"github.com/oceanbase/obagent/config"
"github.com/oceanbase/obagent/config"
"github.com/oceanbase/obagent/utils"
)
)
var
monitorAgentServer
*
MonitorAgentServer
var
monitorAgentServer
*
MonitorAgentServer
...
@@ -38,8 +41,8 @@ type MonitorAgentServer struct {
...
@@ -38,8 +41,8 @@ type MonitorAgentServer struct {
Server
*
web
.
HttpServer
Server
*
web
.
HttpServer
// server of pprof
// server of pprof
AdminServer
*
web
.
HttpServer
AdminServer
*
web
.
HttpServer
//
two servers concurrent waitGrou
p
//
server status ma
p
wg
*
sync
.
WaitGrou
p
serverStatusMap
sync
.
Ma
p
}
}
// NewMonitorAgentServer init monagent server: init configs and logger, register routers
// NewMonitorAgentServer init monagent server: init configs and logger, register routers
...
@@ -60,7 +63,6 @@ func NewMonitorAgentServer(conf *config.MonitorAgentConfig) *MonitorAgentServer
...
@@ -60,7 +63,6 @@ func NewMonitorAgentServer(conf *config.MonitorAgentConfig) *MonitorAgentServer
Server
:
&
http
.
Server
{},
Server
:
&
http
.
Server
{},
Address
:
conf
.
Server
.
AdminAddress
,
Address
:
conf
.
Server
.
AdminAddress
,
},
},
wg
:
&
sync
.
WaitGroup
{},
}
}
monitorAgentServer
=
monagentServer
monitorAgentServer
=
monagentServer
return
monitorAgentServer
return
monitorAgentServer
...
@@ -68,21 +70,37 @@ func NewMonitorAgentServer(conf *config.MonitorAgentConfig) *MonitorAgentServer
...
@@ -68,21 +70,37 @@ func NewMonitorAgentServer(conf *config.MonitorAgentConfig) *MonitorAgentServer
// Run start mongagent servers: admin server, monitor server
// Run start mongagent servers: admin server, monitor server
func
(
server
*
MonitorAgentServer
)
Run
()
error
{
func
(
server
*
MonitorAgentServer
)
Run
()
error
{
server
.
wg
.
Add
(
1
)
// check port available before start server
go
func
()
{
go
func
()
{
defer
server
.
wg
.
Done
(
)
defer
server
.
serverStatusMap
.
Store
(
"adminServer"
,
false
)
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
server
.
AdminServer
.
Cancel
=
cancel
server
.
AdminServer
.
Cancel
=
cancel
server
.
AdminServer
.
Run
(
ctx
)
server
.
AdminServer
.
Run
(
ctx
)
log
.
Info
(
"start admin server"
)
}()
}()
server
.
wg
.
Add
(
1
)
go
func
()
{
go
func
()
{
defer
server
.
wg
.
Done
(
)
defer
server
.
serverStatusMap
.
Store
(
"server"
,
false
)
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
server
.
Server
.
Cancel
=
cancel
server
.
Server
.
Cancel
=
cancel
server
.
Server
.
Run
(
ctx
)
server
.
Server
.
Run
(
ctx
)
log
.
Info
(
"start server"
)
}()
}()
server
.
wg
.
Wait
()
for
{
adminServerStatus
,
_
:=
server
.
serverStatusMap
.
LoadOrStore
(
"adminServer"
,
true
)
serverStatus
,
_
:=
server
.
serverStatusMap
.
LoadOrStore
(
"server"
,
true
)
adminServerOk
,
convertAdminServerOk
:=
utils
.
ConvertToBool
(
adminServerStatus
)
serverOk
,
convertServerOk
:=
utils
.
ConvertToBool
(
serverStatus
)
if
!
(
convertAdminServerOk
&&
convertServerOk
)
{
return
errors
.
New
(
"check monagent server status failed"
)
}
if
!
(
adminServerOk
&&
serverOk
)
{
log
.
Infof
(
"server status ok: %v"
,
serverOk
)
log
.
Infof
(
"admin server status ok: %v"
,
adminServerOk
)
return
errors
.
New
(
"start monagent server failed"
)
}
time
.
Sleep
(
time
.
Second
*
1
)
}
return
nil
return
nil
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录