Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
chain33-pai
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
szh
chain33-pai
Commits
ef99e865
Commit
ef99e865
authored
Mar 25, 2020
by
szh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加安全关节点 以及 安全重启节点接口
parent
855ffb29
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
2 deletions
+60
-2
README.md
README.md
+17
-0
main.go
main.go
+1
-0
node.go
routers/api/v1/node.go
+38
-1
router.go
routers/router.go
+4
-1
No files found.
README.md
View file @
ef99e865
...
...
@@ -357,6 +357,23 @@ response
```
### bityuan安全关闭接口 内网接口
URL /pai/closenode
请求方法 post json
|参数|类型|是否必填|说明|
```
response
{
"code": 200,
"msg": "ok",
"data":""
}
此接口是为了有需要重启或者关机树莓派的时候,调用的接口 保证节点数据不损坏
```
## 节点部署:
监控程序代码默认放在/home/pi目录下面
钱包节点程序命名为v7-bityuan
...
...
main.go
View file @
ef99e865
...
...
@@ -38,6 +38,7 @@ func main() {
go
broadcast
()
go
app
.
CornProcessJob
(
time
.
NewTicker
(
time
.
Second
*
10
))
go
app
.
AutoUpdate
(
time
.
NewTicker
(
time
.
Second
*
60
))
//go app.ClearLog(time.NewTicker(time.Hour*1))
routersInit
:=
routers
.
InitRouter
()
readTimeout
:=
setting
.
ServerSetting
.
ReadTimeout
writeTimeout
:=
setting
.
ServerSetting
.
WriteTimeout
...
...
routers/api/v1/node.go
View file @
ef99e865
...
...
@@ -254,12 +254,27 @@ func NodeInfo(c *gin.Context){
func
RestartNode
(
c
*
gin
.
Context
){
appG
:=
app
.
Gin
{
C
:
c
}
app
.
BityuanFlag
=
true
_
,
err
:=
app
.
SafeCloseNode
()
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusOK
,
e
.
NODE_ERROR
,
"node err"
)
app
.
BityuanFlag
=
false
return
}
app
.
BityuanFlag
=
false
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
"node close safe"
)
}
func
CloseNode
(
c
*
gin
.
Context
){
appG
:=
app
.
Gin
{
C
:
c
}
app
.
BityuanFlag
=
true
_
,
err
:=
app
.
SafeCloseNode
()
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusOK
,
e
.
NODE_ERROR
,
"node err"
)
app
.
BityuanFlag
=
false
return
}
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
"node
restarted
"
)
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
"node
close safe
"
)
}
//反馈信息
...
...
@@ -428,4 +443,25 @@ func UpdateNodeStatus(c *gin.Context){
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
gin
.
H
{
"status"
:
update
,
})
}
func
PoweroffPai
(
c
*
gin
.
Context
)
{
appG
:=
app
.
Gin
{
C
:
c
}
app
.
BityuanFlag
=
true
_
,
err
:=
app
.
SafeCloseNode
()
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusOK
,
e
.
NODE_ERROR
,
err
)
app
.
BityuanFlag
=
false
return
}
var
buf
bytes
.
Buffer
cmd
:=
exec
.
Command
(
"sudo"
,
"poweroff"
)
cmd
.
Stdout
=
&
buf
err
=
cmd
.
Run
()
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusOK
,
e
.
NODE_ERROR
,
err
)
app
.
BityuanFlag
=
false
return
}
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
"pai restarted"
)
}
\ No newline at end of file
routers/router.go
View file @
ef99e865
...
...
@@ -47,7 +47,10 @@ func InitRouter() *gin.Engine {
//apiv1.POST("/isreboot",v1.IsReBoot)
//重启节点
apiv1
.
POST
(
"/restartnode"
,
v1
.
RestartNode
)
//安全关闭节点,不会再重启 除非是重启树莓派
apiv1
.
POST
(
"/closenode"
,
v1
.
CloseNode
)
//sudo poweroff
apiv1
.
POST
(
"/poweroff"
,
v1
.
PoweroffPai
)
return
r
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment