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
73b7dbe0
Commit
73b7dbe0
authored
Mar 16, 2020
by
szh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新pai代码 无逻辑只覆盖更新 增加isreboot接口提示用户更新完成重启机子 增加自动更新pai代码
parent
e3643641
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
114 additions
and
4 deletions
+114
-4
README.md
README.md
+16
-0
main.go
main.go
+1
-0
process.go
pkg/app/process.go
+55
-1
version.go
pkg/app/version.go
+1
-1
pai.go
routers/api/v1/pai.go
+38
-0
router.go
routers/router.go
+3
-2
No files found.
README.md
View file @
73b7dbe0
...
@@ -324,6 +324,22 @@ response
...
@@ -324,6 +324,22 @@ response
```
```
### pai更新完成后 是否已重启 内网接口
URL /pai/isreboot
请求方法 post json
|参数|类型|是否必填|说明|
```
response
{
"code": 200,
"msg": "ok",
"status": true //true 表示用户需要重启树莓派
}
```
## 节点部署:
## 节点部署:
监控程序代码默认放在/home/pi目录下面
监控程序代码默认放在/home/pi目录下面
钱包节点程序命名为v7-bityuan
钱包节点程序命名为v7-bityuan
...
...
main.go
View file @
73b7dbe0
...
@@ -37,6 +37,7 @@ func main() {
...
@@ -37,6 +37,7 @@ func main() {
gin
.
SetMode
(
setting
.
ServerSetting
.
RunMode
)
gin
.
SetMode
(
setting
.
ServerSetting
.
RunMode
)
go
broadcast
()
go
broadcast
()
go
app
.
CornProcessJob
(
time
.
NewTicker
(
time
.
Second
*
10
))
go
app
.
CornProcessJob
(
time
.
NewTicker
(
time
.
Second
*
10
))
go
app
.
AutoUpdate
(
time
.
NewTicker
(
time
.
Second
*
10
))
routersInit
:=
routers
.
InitRouter
()
routersInit
:=
routers
.
InitRouter
()
readTimeout
:=
setting
.
ServerSetting
.
ReadTimeout
readTimeout
:=
setting
.
ServerSetting
.
ReadTimeout
writeTimeout
:=
setting
.
ServerSetting
.
WriteTimeout
writeTimeout
:=
setting
.
ServerSetting
.
WriteTimeout
...
...
pkg/app/process.go
View file @
73b7dbe0
...
@@ -19,6 +19,7 @@ import (
...
@@ -19,6 +19,7 @@ import (
"chain33-pai/pkg/util"
"chain33-pai/pkg/util"
"chain33-pai/pkg/e"
"chain33-pai/pkg/e"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
"chain33-pai/service/pai_service"
)
)
var
tlog
=
log
.
New
(
"pkg"
,
"app"
)
var
tlog
=
log
.
New
(
"pkg"
,
"app"
)
...
@@ -55,6 +56,7 @@ var Bityuan ProcessInfo
...
@@ -55,6 +56,7 @@ var Bityuan ProcessInfo
var
UpdateInfo
updateInfo
var
UpdateInfo
updateInfo
var
NodeError
error
var
NodeError
error
var
ServerStatus
Server
var
ServerStatus
Server
var
IsReboot
bool
//当更新完成 true表示 需要用户手动重启树莓派
func
getProcessInfo
(
keyfile
string
)
string
{
func
getProcessInfo
(
keyfile
string
)
string
{
var
buffer
bytes
.
Buffer
//
var
buffer
bytes
.
Buffer
//
...
@@ -83,7 +85,7 @@ func getProcessInfo(keyfile string)string{
...
@@ -83,7 +85,7 @@ func getProcessInfo(keyfile string)string{
func
getWalletInfo
()
error
{
func
getWalletInfo
()
error
{
rawProcessInfo
:=
getProcessInfo
(
setting
.
BityuanSetting
.
Name
)
rawProcessInfo
:=
getProcessInfo
(
setting
.
BityuanSetting
.
Name
)
tlog
.
Info
(
"getWalletInfo"
,
rawProcessInfo
)
tlog
.
Info
(
"getWalletInfo"
,
"wallet"
,
rawProcessInfo
)
if
rawProcessInfo
==
""
{
if
rawProcessInfo
==
""
{
//钱包节点未启动
//钱包节点未启动
StartProcess
(
setting
.
Chain33Pai
.
Auto
)
StartProcess
(
setting
.
Chain33Pai
.
Auto
)
...
@@ -461,3 +463,54 @@ func Unlock(){
...
@@ -461,3 +463,54 @@ func Unlock(){
tlog
.
Info
(
"unlock auth failed"
)
tlog
.
Info
(
"unlock auth failed"
)
}
}
}
}
func
AutoUpdate
(
tick
*
time
.
Ticker
)
{
for
{
select
{
case
<-
tick
.
C
:
if
!
DPercent
.
Flag
{
err
:=
AutoUpdatePai
()
if
err
!=
nil
{
tlog
.
Error
(
"autoupdatepai"
,
"err"
,
err
)
}
}
}
}
}
func
AutoUpdatePai
()
error
{
//对比版本号
version
:=
util
.
VersionCompare
(
GetVersion
())
//检查最新版本号online数据库
var
pai
pai_service
.
Pai
latest
,
err
:=
pai
.
GetPaiLatestVersion
(
int32
(
2
))
if
err
!=
nil
{
return
err
}
latestversion
:=
util
.
VersionCompare
(
latest
)
if
version
>
latestversion
{
return
err
}
name
:=
setting
.
Chain33Pai
.
Name
+
"_"
+
latestversion
+
".tar.gz"
url
:=
setting
.
Chain33Pai
.
DownloadUrl
+
name
//oss下载更新包
err
=
DownLoadFile
(
url
,
name
,
int32
(
2
))
if
err
!=
nil
{
return
err
}
//解压缩文件
tar
:=
exec
.
Command
(
"tar"
,
"-xvf"
,
setting
.
Chain33Pai
.
Name
)
err
=
tar
.
Start
()
if
err
!=
nil
{
tlog
.
Error
(
"tar"
,
"err"
,
err
)
return
err
}
err
=
tar
.
Wait
()
if
err
!=
nil
{
tlog
.
Error
(
"tar"
,
"err"
,
err
)
return
err
}
return
nil
}
\ No newline at end of file
pkg/app/version.go
View file @
73b7dbe0
package
app
package
app
const
version
=
"0.
1.8
"
const
version
=
"0.
2.0
"
func
GetVersion
()
string
{
func
GetVersion
()
string
{
return
version
return
version
...
...
routers/api/v1/pai.go
View file @
73b7dbe0
...
@@ -55,6 +55,7 @@ func GetPaiVersion(c *gin.Context) {
...
@@ -55,6 +55,7 @@ func GetPaiVersion(c *gin.Context) {
}
}
//只下载程序 重启生效
//只下载程序 重启生效
//具体更新逻辑写在代码 更新迭代比较麻烦 改为下面new方法
//下载地址阿里云oss地址 固定ip格式+/+chain33-pai+x.x.x+.tar.gz
//下载地址阿里云oss地址 固定ip格式+/+chain33-pai+x.x.x+.tar.gz
func
UpdatePai
(
c
*
gin
.
Context
)
{
func
UpdatePai
(
c
*
gin
.
Context
)
{
appG
:=
app
.
Gin
{
C
:
c
}
appG
:=
app
.
Gin
{
C
:
c
}
...
@@ -206,6 +207,43 @@ func UpdatePai(c *gin.Context) {
...
@@ -206,6 +207,43 @@ func UpdatePai(c *gin.Context) {
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
nil
)
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
nil
)
}
}
//只下载程序 不必关心具体的更新内容 配置文件通用 重启生效
//忽略req.Version 对比自己版本和最新版本 直接更新覆盖最新版本
//下载地址阿里云oss地址 固定ip格式+/+chain33-pai+x.x.x+.tar.gz
func
UpdatePaiNew
(
c
*
gin
.
Context
)
{
appG
:=
app
.
Gin
{
C
:
c
}
if
app
.
DPercent
.
Flag
{
appG
.
Response
(
http
.
StatusOK
,
e
.
DOWNLOAD_ERROR
,
"正在升级中,不要重复点击"
)
return
}
app
.
DPercent
.
Total
=
int64
(
0
)
app
.
DPercent
.
Current
=
int64
(
0
)
var
req
pai_service
.
ReqUpdatePai
err
:=
c
.
ShouldBindJSON
(
&
req
)
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusOK
,
e
.
INVALID_PARAMS
,
nil
)
app
.
DPercent
.
Flag
=
false
return
}
err
=
app
.
AutoUpdatePai
()
if
err
!=
nil
{
app
.
DPercent
.
Flag
=
false
appG
.
Response
(
http
.
StatusOK
,
e
.
VERSION_UPDATE_ERROR
,
nil
)
return
}
app
.
DPercent
.
Flag
=
false
app
.
IsReboot
=
true
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
nil
)
}
func
IsReBoot
(
c
*
gin
.
Context
)
{
appG
:=
app
.
Gin
{
C
:
c
}
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
gin
.
H
{
"status"
:
app
.
IsReboot
,
})
}
func
GetDPercent
(
c
*
gin
.
Context
)
{
func
GetDPercent
(
c
*
gin
.
Context
)
{
appG
:=
app
.
Gin
{
C
:
c
}
appG
:=
app
.
Gin
{
C
:
c
}
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
gin
.
H
{
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
gin
.
H
{
...
...
routers/router.go
View file @
73b7dbe0
...
@@ -28,7 +28,7 @@ func InitRouter() *gin.Engine {
...
@@ -28,7 +28,7 @@ func InitRouter() *gin.Engine {
//本程序版本
//本程序版本
apiv1
.
POST
(
"/paiversion"
,
v1
.
GetPaiVersion
)
apiv1
.
POST
(
"/paiversion"
,
v1
.
GetPaiVersion
)
//本程序下载新版本
//本程序下载新版本
apiv1
.
POST
(
"/updatepai"
,
v1
.
UpdatePai
)
apiv1
.
POST
(
"/updatepai"
,
v1
.
UpdatePai
New
)
//获取下载进度
//获取下载进度
apiv1
.
POST
(
"/dpercent"
,
v1
.
GetDPercent
)
apiv1
.
POST
(
"/dpercent"
,
v1
.
GetDPercent
)
//获取外网ip
//获取外网ip
...
@@ -40,7 +40,8 @@ func InitRouter() *gin.Engine {
...
@@ -40,7 +40,8 @@ func InitRouter() *gin.Engine {
//反馈处理进度
//反馈处理进度
apiv1
.
POST
(
"/iscomplete"
,
v1
.
FeedBackStatus
)
apiv1
.
POST
(
"/iscomplete"
,
v1
.
FeedBackStatus
)
apiv1
.
POST
(
"/escrowpassword"
,
v1
.
EscrowPasswd
)
apiv1
.
POST
(
"/escrowpassword"
,
v1
.
EscrowPasswd
)
//更新完成用户手动重启设备
apiv1
.
POST
(
"/isreboot"
,
v1
.
IsReBoot
)
return
r
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