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
4ec0bd2f
Commit
4ec0bd2f
authored
Mar 19, 2020
by
szh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新bityuan更新方式 直接覆盖更新
parent
595f15e8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
117 additions
and
3 deletions
+117
-3
README.md
README.md
+2
-1
node.go
routers/api/v1/node.go
+114
-1
router.go
routers/router.go
+1
-1
No files found.
README.md
View file @
4ec0bd2f
...
...
@@ -348,7 +348,8 @@ response
chain33-pai程序自启动
*/1 * * * * /home/pi/chain33-pai/startup.sh
```
chain33-pai版本oss下载地址文件格式 chain33-pai_x.x.x.tar.gz
bityuan版本下载地址文件格式v7-bityuan_x.x.x.tar.gz (目录wallet-bty)
chain33-pai版本oss下载地址文件格式 chain33-pai_x.x.x.tar.gz (目录chain33-pai)
chain33-pai 打包过程中保持 文件中shell文件执行权限
配置文件默认,用户不需要去更改参数
节点的挂载盘中应当只有一个对应的启动程序,避免auto.sh去挂载盘上找启动程序时出错
...
...
routers/api/v1/node.go
View file @
4ec0bd2f
...
...
@@ -18,6 +18,7 @@ import (
"bytes"
"chain33-pai/pkg/chain33"
"github.com/33cn/chain33/types"
"strings"
)
var
flag
bool
//判断是否正在更新
...
...
@@ -61,7 +62,7 @@ func ResetWallet(c *gin.Context) {
app
.
BityuanFlag
=
false
}
//钱包更新
,只替换执行文件
//钱包更新
func
UpdateNode
(
c
*
gin
.
Context
){
appG
:=
app
.
Gin
{
C
:
c
}
if
app
.
BityuanFlag
{
...
...
@@ -275,6 +276,118 @@ func UpdateNode(c *gin.Context){
app
.
BityuanFlag
=
false
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
"update job started"
)
}
//钱包更新,只替换执行文件和配置文件
//具体更新逻辑不再代码实现
//oss下载包打包要保持执行权限
func
UpdateNodeNew
(
c
*
gin
.
Context
){
appG
:=
app
.
Gin
{
C
:
c
}
if
app
.
BityuanFlag
{
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS_RUNNING
,
"node is updating"
)
return
}
if
app
.
NodeError
!=
nil
{
appG
.
Response
(
http
.
StatusOK
,
e
.
NODE_ERROR
,
"node internal error,could not start node"
)
return
}
absPath
:=
app
.
GetAbsPath
(
setting
.
BityuanSetting
.
Name
)
+
"/"
pwd
,
err
:=
os
.
Getwd
()
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusOK
,
e
.
ERROR
,
"get pwd err"
)
return
}
pwd
=
pwd
+
"/"
app
.
BityuanFlag
=
true
app
.
UpdateInfo
.
Flag
=
false
setting
.
FreshVersion
()
var
pai
pai_service
.
Pai
latestVersion
,
err
:=
pai
.
GetPaiLatestVersion
(
int32
(
1
))
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusOK
,
e
.
NODE_ERROR
,
"get online version err"
)
app
.
BityuanFlag
=
false
app
.
UpdateInfo
.
Flag
=
true
return
}
if
latestVersion
==
setting
.
BityuanSetting
.
Version
{
app
.
UpdateInfo
.
Flag
=
true
app
.
BityuanFlag
=
false
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
"current version is latest"
)
return
}
if
latestVersion
==
""
{
app
.
UpdateInfo
.
Flag
=
true
app
.
BityuanFlag
=
false
appG
.
Response
(
http
.
StatusOK
,
e
.
NETWORK_ERROR
,
"network error,please checkout your network then try again"
)
return
}
stderr
:=
bytes
.
NewBuffer
(
nil
)
name
:=
setting
.
BityuanSetting
.
Name
+
"_"
+
latestVersion
+
".tar.gz"
url
:=
setting
.
Chain33Pai
.
DownloadUrl
+
name
tlog
.
Info
(
"UpdateNode"
,
"dir"
,
setting
.
BityuanSetting
.
Name
+
"_"
+
latestVersion
)
tlog
.
Info
(
"UpdateNode"
,
"path"
,
absPath
)
err
=
app
.
DownLoadFile
(
url
,
name
,
int32
(
1
))
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusOK
,
e
.
DOWNLOAD_ERROR
,
err
)
app
.
UpdateInfo
.
Flag
=
true
app
.
BityuanFlag
=
false
return
}
dirs
:=
strings
.
Split
(
absPath
,
"wallet-bty"
)
if
len
(
dirs
)
!=
2
{
appG
.
Response
(
http
.
StatusOK
,
e
.
ERROR
,
err
)
app
.
UpdateInfo
.
Flag
=
true
app
.
BityuanFlag
=
false
return
}
//解压缩文件
tar
:=
exec
.
Command
(
"tar"
,
"-xvf"
,
name
,
dirs
[
0
])
tar
.
Stderr
=
stderr
err
=
tar
.
Start
()
if
err
!=
nil
{
tlog
.
Error
(
"tar"
,
"err"
,
err
)
appG
.
Response
(
http
.
StatusOK
,
e
.
TAR_XVF_ERROR
,
err
)
app
.
UpdateInfo
.
Flag
=
true
app
.
BityuanFlag
=
false
return
}
err
=
tar
.
Wait
()
if
err
!=
nil
{
tlog
.
Error
(
"tar"
,
"err"
,
stderr
.
String
())
appG
.
Response
(
http
.
StatusOK
,
e
.
TAR_XVF_ERROR
,
stderr
.
String
())
app
.
UpdateInfo
.
Flag
=
true
app
.
BityuanFlag
=
false
return
}
t
,
err
:=
app
.
SafeCloseNode
()
if
err
!=
nil
||
!
t
{
app
.
UpdateInfo
.
Flag
=
true
app
.
BityuanFlag
=
false
appG
.
Response
(
http
.
StatusOK
,
e
.
NODE_ERROR
,
err
)
return
}
remove
:=
exec
.
Command
(
"rm"
,
"-rf"
,
setting
.
BityuanSetting
.
Name
+
"_"
+
latestVersion
,
name
)
remove
.
Stderr
=
stderr
err
=
remove
.
Start
()
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusOK
,
e
.
RM_ERROR
,
err
)
app
.
UpdateInfo
.
Flag
=
true
app
.
BityuanFlag
=
false
return
}
err
=
remove
.
Wait
()
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusOK
,
e
.
RM_ERROR
,
stderr
.
String
())
app
.
UpdateInfo
.
Flag
=
true
app
.
BityuanFlag
=
false
return
}
app
.
BityuanFlag
=
false
app
.
UpdateInfo
.
Flag
=
true
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
"update job started"
)
}
//重置节点只需要删除datadir 然后重启节点
func
ResetNode
(
c
*
gin
.
Context
){
...
...
routers/router.go
View file @
4ec0bd2f
...
...
@@ -18,7 +18,7 @@ func InitRouter() *gin.Engine {
apiv1
.
POST
(
"/devdetail"
,
v1
.
GetDevdetail
)
//获取树莓派基本信息
apiv1
.
POST
(
"/resetwallet"
,
v1
.
ResetWallet
)
apiv1
.
POST
(
"/updatenode"
,
v1
.
UpdateNode
)
apiv1
.
POST
(
"/updatenode"
,
v1
.
UpdateNode
New
)
apiv1
.
POST
(
"/devstatus"
,
v1
.
GetDevstatus
)
apiv1
.
POST
(
"/updatedetail"
,
v1
.
UpdateDetail
)
apiv1
.
POST
(
"/version"
,
v1
.
Version
)
...
...
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