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
25ceb096
Commit
25ceb096
authored
Dec 11, 2019
by
ligaishun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update node.go
parent
5d497e3e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
34 deletions
+52
-34
node.go
routers/api/v1/node.go
+52
-34
No files found.
routers/api/v1/node.go
View file @
25ceb096
...
...
@@ -19,53 +19,61 @@ var flag bool//判断是否正在更新
func
ResetWallet
(
c
*
gin
.
Context
)
{
appG
:=
app
.
Gin
{
C
:
c
}
if
app
.
NodeError
!=
nil
{
appG
.
Response
(
http
.
StatusOK
,
e
.
ERROR
,
app
.
NodeError
.
Error
())
log
.
Println
(
app
.
NodeError
.
Error
())
appG
.
Response
(
http
.
StatusOK
,
e
.
NODE_ERROR
,
"node internal error,could not start node"
)
return
}
cmd
:=
exec
.
Command
(
"kill"
,
"-9"
,
app
.
Wallet
.
Pid
)
cmd
:=
exec
.
Command
(
"kill"
,
"-9"
,
app
.
Bityuan
.
Pid
)
err
:=
cmd
.
Start
()
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusOK
,
e
.
ERROR
,
"fail to reset wallet"
)
appG
.
Response
(
http
.
StatusOK
,
e
.
E
NV_E
RROR
,
"fail to reset wallet"
)
log
.
Fatalln
(
err
)
return
}
err
=
os
.
RemoveAll
(
fmt
.
Sprintf
(
path
.
Dir
(
app
.
Wallet
.
Path
),
"/wallet"
))
err
=
os
.
RemoveAll
(
fmt
.
Sprintf
(
"%s/wallet"
,
path
.
Dir
(
app
.
Bityuan
.
Path
)
))
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusOK
,
e
.
ERROR
,
"fail to reset wallet"
)
appG
.
Response
(
http
.
StatusOK
,
e
.
NODE_
ERROR
,
"fail to reset wallet"
)
log
.
Fatalln
(
err
)
return
}
err
=
app
.
StartProcess
(
setting
.
Chain33Pai
.
Auto
)
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusOK
,
e
.
ERROR
,
"fail to restart node"
)
appG
.
Response
(
http
.
StatusOK
,
e
.
NODE_
ERROR
,
"fail to restart node"
)
log
.
Fatalln
(
err
)
return
}
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
nil
)
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
"reset complete"
)
}
func
UpdateNode
(
c
*
gin
.
Context
){
appG
:=
app
.
Gin
{
C
:
c
}
if
flag
{
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
"node is updating"
)
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS_RUNNING
,
"node is updating"
)
}
if
app
.
NodeError
!=
nil
{
appG
.
Response
(
http
.
StatusOK
,
e
.
NODE_ERROR
,
"node internal error,could not start node"
)
return
}
setting
.
FreshVersion
()
app
.
UpdateInfo
.
Status
=
false
app
.
UpdateInfo
.
Info
=
"updating..."
latestVersion
:=
app
.
GetLatestVersion
()
app
.
UpdateInfo
.
Status
=
false
if
latestVersion
==
setting
.
BityuanSetting
.
Version
{
app
.
UpdateInfo
.
Info
=
"current version is latest"
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
"current version is latest"
)
return
}
if
flag
{
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
"node is updating"
)
app
.
UpdateInfo
.
Info
=
"Updating..."
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS_RUNNING
,
"node is updating"
)
return
}
if
latestVersion
==
""
{
flag
=
false
appG
.
Response
(
http
.
StatusOK
,
e
.
ERROR
,
"network error"
)
app
.
UpdateInfo
.
Info
=
"network error"
appG
.
Response
(
http
.
StatusOK
,
e
.
NETWORK_ERROR
,
"network error,please checkout your network then try again"
)
return
}
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
"update job started"
)
...
...
@@ -77,18 +85,18 @@ func UpdateNode(c *gin.Context){
app
.
UpdateInfo
.
Info
=
err
.
Error
()
return
}
app
.
Copy
(
setting
.
BityuanSetting
.
Name
,
setting
.
BityuanSetting
.
Path
)
app
.
Copy
(
setting
.
BityuanSetting
.
Name
+
"-cli"
,
setting
.
BityuanSetting
.
Path
)
app
.
Copy
(
setting
.
BityuanSetting
.
Name
,
app
.
Bityuan
.
Path
)
app
.
Copy
(
fmt
.
Sprintf
(
"%s-cli"
,
setting
.
BityuanSetting
.
Name
),
app
.
Bityuan
.
Path
)
os
.
Chdir
(
".."
)
os
.
RemoveAll
(
"bityuan"
)
kill
:=
exec
.
Command
(
"kill"
,
"-9"
,
app
.
Wallet
.
Pid
)
os
.
RemoveAll
(
setting
.
BityuanSetting
.
Name
)
kill
:=
exec
.
Command
(
"kill"
,
"-9"
,
app
.
Bityuan
.
Pid
)
kill
.
Start
()
err
=
kill
.
Wait
()
if
err
!=
nil
{
flag
=
false
app
.
UpdateInfo
.
Info
=
"fail to update node "
return
}
if
err
!=
nil
{
flag
=
false
app
.
UpdateInfo
.
Info
=
"fail to update node "
return
}
err
=
app
.
StartProcess
(
setting
.
Chain33Pai
.
Auto
)
if
err
!=
nil
{
flag
=
false
...
...
@@ -106,7 +114,7 @@ func ResetNode(c* gin.Context){
app
.
UpdateInfo
.
Status
=
false
app
.
UpdateInfo
.
Info
=
"updating..."
if
flag
{
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
"node is resetting"
)
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
_RUNNING
,
"node is resetting"
)
return
}
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
"reset job started"
)
...
...
@@ -118,17 +126,19 @@ func ResetNode(c* gin.Context){
app
.
UpdateInfo
.
Info
=
err
.
Error
()
return
}
app
.
Copy
(
setting
.
BityuanSetting
.
Name
,
path
.
Dir
(
setting
.
BityuanSetting
.
Path
))
app
.
Copy
(
setting
.
BityuanSetting
.
Name
,
path
.
Dir
(
setting
.
BityuanSetting
.
Path
))
//pro
app
.
Copy
(
setting
.
BityuanSetting
.
Name
+
"-cli"
,
path
.
Dir
(
setting
.
BityuanSetting
.
Path
))
os
.
Chdir
(
".."
)
os
.
RemoveAll
(
"bityuan"
)
os
.
Chdir
(
setting
.
BityuanSetting
.
Path
)
os
.
RemoveAll
(
"datadir"
)
os
.
Chdir
(
setting
.
Chain33Pai
.
Path
)
kill
:=
exec
.
Command
(
"kill"
,
"-9"
,
app
.
Wallet
.
Pid
)
os
.
Chdir
(
".."
)
//make操作进入了该目录
os
.
RemoveAll
(
setting
.
BityuanSetting
.
Name
)
//
os.Chdir(setting.BityuanSetting.Path)
os
.
RemoveAll
(
fmt
.
Sprint
(
app
.
Bityuan
.
Path
,
"/datadir"
)
)
//
os.Chdir(setting.Chain33Pai.Path)
kill
:=
exec
.
Command
(
"kill"
,
"-9"
,
app
.
Bityuan
.
Pid
)
//start := exec.Command(path.Dir(app.Wallet.Path) + "/" + app.Wallet.PName)
err
=
kill
.
Start
()
if
err
!=
nil
{
app
.
UpdateInfo
.
Info
=
fmt
.
Sprintf
(
"fail to reset node:%s"
,
err
.
Error
())
return
}
...
...
@@ -155,25 +165,34 @@ func ResetNode(c* gin.Context){
func
UpdateDetail
(
c
*
gin
.
Context
){
appG
:=
app
.
Gin
{
C
:
c
}
if
flag
{
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS_RUNNING
,
app
.
UpdateInfo
)
return
}
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
app
.
UpdateInfo
)
}
//get current version and latest version
func
Version
(
c
*
gin
.
Context
){
appG
:=
app
.
Gin
{
C
:
c
}
setting
.
FreshVersion
()
latestVersion
:=
app
.
GetLatestVersion
()
if
latestVersion
==
""
{
appG
.
Response
(
http
.
StatusOK
,
e
.
NETWORK_ERROR
,
"network error,please try again"
)
return
}
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
gin
.
H
{
"current"
:
setting
.
BityuanSetting
.
Version
,
"latest"
:
app
.
GetLatestVersion
()
,
"latest"
:
latestVersion
,
})
}
func
NodeInfo
(
c
*
gin
.
Context
){
appG
:=
app
.
Gin
{
C
:
c
}
if
app
.
NodeError
!=
nil
{
appG
.
Response
(
http
.
StatusOK
,
e
.
ERROR
,
app
.
NodeError
.
Error
()
)
appG
.
Response
(
http
.
StatusOK
,
e
.
NODE_ERROR
,
"node down"
)
return
}
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
"node is running"
)
}
\ No newline at end of file
}
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