Commit 914999d0 authored by szh's avatar szh

更新钱包重置 和 重置节点逻辑 版本维护由online分支手动控制,执行文件由运维提供oss地址

parent d2408b16
...@@ -44,6 +44,7 @@ type Disk struct { ...@@ -44,6 +44,7 @@ type Disk struct {
SizeK string //硬盘大小 SizeK string //硬盘大小
} }
var BityuanFlag bool //true表示有任务在占用,禁止其他重复操作
var Bityuan ProcessInfo var Bityuan ProcessInfo
var UpdateInfo updateInfo var UpdateInfo updateInfo
var NodeError error var NodeError error
...@@ -130,7 +131,9 @@ func CornProcessJob(ticker *time.Ticker){ ...@@ -130,7 +131,9 @@ func CornProcessJob(ticker *time.Ticker){
for { for {
select { select {
case <-ticker.C: case <-ticker.C:
NodeError = getWalletInfo() if !BityuanFlag {//有更新,重置等节点重启操作时 禁止运行,防止冲突
NodeError = getWalletInfo()
}
} }
} }
} }
......
...@@ -14,6 +14,7 @@ const ( ...@@ -14,6 +14,7 @@ const (
CP_ERROR = 5007 CP_ERROR = 5007
RM_ERROR = 5008 RM_ERROR = 5008
MV_ERROR = 5009 MV_ERROR = 5009
TRY_LATER = 5010
ERROR_EXIST_TAG = 10001 ERROR_EXIST_TAG = 10001
ERROR_EXIST_TAG_FAIL = 10002 ERROR_EXIST_TAG_FAIL = 10002
ERROR_NOT_EXIST_TAG = 10003 ERROR_NOT_EXIST_TAG = 10003
......
...@@ -9,6 +9,7 @@ var MsgFlags = map[int]string{ ...@@ -9,6 +9,7 @@ var MsgFlags = map[int]string{
CP_ERROR: "拷贝文件出错", CP_ERROR: "拷贝文件出错",
RM_ERROR: "删除文件出错", RM_ERROR: "删除文件出错",
MV_ERROR: "移动文件出错", MV_ERROR: "移动文件出错",
TRY_LATER: "其他任务进行中,稍后再试",
ERROR_EXIST_TAG: "已存在该标签名称", ERROR_EXIST_TAG: "已存在该标签名称",
ERROR_EXIST_TAG_FAIL: "获取已存在标签失败", ERROR_EXIST_TAG_FAIL: "获取已存在标签失败",
ERROR_NOT_EXIST_TAG: "该标签不存在", ERROR_NOT_EXIST_TAG: "该标签不存在",
......
...@@ -12,15 +12,22 @@ import ( ...@@ -12,15 +12,22 @@ import (
"chain33-pai/pkg/setting" "chain33-pai/pkg/setting"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"chain33-pai/service/pai_service"
) )
var flag bool//判断是否正在更新 var flag bool//判断是否正在更新
func ResetWallet(c *gin.Context) { func ResetWallet(c *gin.Context) {
appG := app.Gin{C: c} appG := app.Gin{C: c}
if app.BityuanFlag {
appG.Response(http.StatusOK, e.TRY_LATER,"other job is busy,please try later")
return
}
app.BityuanFlag = true
if app.NodeError!=nil{ if app.NodeError!=nil{
log.Println(app.NodeError.Error()) log.Println(app.NodeError.Error())
appG.Response(http.StatusOK, e.NODE_ERROR,"node internal error,could not start node") appG.Response(http.StatusOK, e.NODE_ERROR,"node internal error,could not start node")
app.BityuanFlag = false
return return
} }
cmd:=exec.Command("kill","-9",app.Bityuan.Pid) cmd:=exec.Command("kill","-9",app.Bityuan.Pid)
...@@ -28,12 +35,14 @@ func ResetWallet(c *gin.Context) { ...@@ -28,12 +35,14 @@ func ResetWallet(c *gin.Context) {
if err!=nil{ if err!=nil{
appG.Response(http.StatusOK, e.ENV_ERROR, "fail to reset wallet") appG.Response(http.StatusOK, e.ENV_ERROR, "fail to reset wallet")
log.Fatalln(err) log.Fatalln(err)
app.BityuanFlag = false
return return
} }
err=os.RemoveAll(fmt.Sprintf("%s/wallet",path.Dir(app.Bityuan.Path))) err=os.RemoveAll(fmt.Sprintf("%s/wallet",path.Dir(app.Bityuan.Path)))
if err!=nil{ if err!=nil{
appG.Response(http.StatusOK, e.NODE_ERROR, "fail to reset wallet") appG.Response(http.StatusOK, e.NODE_ERROR, "fail to reset wallet")
log.Fatalln(err) log.Fatalln(err)
app.BityuanFlag = false
return return
} }
...@@ -41,12 +50,14 @@ func ResetWallet(c *gin.Context) { ...@@ -41,12 +50,14 @@ func ResetWallet(c *gin.Context) {
if err!=nil{ if err!=nil{
appG.Response(http.StatusOK, e.NODE_ERROR,"fail to restart node") appG.Response(http.StatusOK, e.NODE_ERROR,"fail to restart node")
log.Fatalln(err) log.Fatalln(err)
app.BityuanFlag = false
return return
} }
appG.Response(http.StatusOK, e.SUCCESS,"reset complete") appG.Response(http.StatusOK, e.SUCCESS,"reset complete")
app.BityuanFlag = false
} }
//钱包更新涉及到配置文件更新以及是否重新同步等规则不明确,先暂时不开放
func UpdateNode(c *gin.Context){ func UpdateNode(c *gin.Context){
appG := app.Gin{C: c} appG := app.Gin{C: c}
if flag{ if flag{
...@@ -110,58 +121,39 @@ func UpdateNode(c *gin.Context){ ...@@ -110,58 +121,39 @@ func UpdateNode(c *gin.Context){
}() }()
} }
//重置节点只需要删除datadir 然后重启节点
func ResetNode(c* gin.Context){ func ResetNode(c* gin.Context){
appG := app.Gin{C: c} appG := app.Gin{C: c}
app.UpdateInfo.Status=false if app.BityuanFlag {
app.UpdateInfo.Info="updating..." appG.Response(http.StatusOK, e.TRY_LATER,"other job is busy,please try later")
if flag{ return
appG.Response(http.StatusOK,e.SUCCESS_RUNNING,"node is resetting") }
app.BityuanFlag = true
kill := exec.Command("kill", "-9", app.Bityuan.Pid)
err:=kill.Start()
if err != nil {
appG.Response(http.StatusOK, e.NODE_ERROR,"kill node err")
app.BityuanFlag = false
return return
} }
appG.Response(http.StatusOK,e.SUCCESS,"reset job started")
go func() {
flag=true
err := app.DownLoadLatestVersion()
if err != nil {
flag=false
app.UpdateInfo.Info = err.Error()
return
}
app.Copy(setting.BityuanSetting.Name, path.Dir(setting.BityuanSetting.Path))//pro err=kill.Wait()
app.Copy(fmt.Sprintf("%s-cli",setting.BityuanSetting.Name), path.Dir(setting.BityuanSetting.Path)) if err != nil {
os.Chdir("..")//make操作进入了该目录 appG.Response(http.StatusOK, e.NODE_ERROR,"kill node cmd wait err")
os.RemoveAll(setting.BityuanSetting.Name) app.BityuanFlag = false
//os.Chdir(setting.BityuanSetting.Path)
os.RemoveAll(fmt.Sprint("%s/datadir",app.Bityuan.Path))
//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
}
err=kill.Wait() return
if err != nil { }
flag=false os.RemoveAll(fmt.Sprint("%s/datadir",app.Bityuan.Path))
app.UpdateInfo.Info = fmt.Sprintf("fail to reset node:%s",err.Error()) err=app.StartProcess(setting.Chain33Pai.Auto)
return
}
err=app.StartProcess(setting.Chain33Pai.Auto)
//err = start.Start()
if err != nil {
flag=false
app.UpdateInfo.Info = fmt.Sprintf("fail to reset node:%s",err.Error())
return
}
app.UpdateInfo.Status=true if err != nil {
app.UpdateInfo.Info = "complete" app.BityuanFlag = false
flag=false appG.Response(http.StatusOK, e.NODE_ERROR,"start auto sh err")
}() return
}
app.BityuanFlag = false
appG.Response(http.StatusOK,e.SUCCESS,"reset job ok")
} }
func UpdateDetail(c* gin.Context){ func UpdateDetail(c* gin.Context){
...@@ -180,8 +172,12 @@ func UpdateDetail(c* gin.Context){ ...@@ -180,8 +172,12 @@ func UpdateDetail(c* gin.Context){
func Version(c* gin.Context){ func Version(c* gin.Context){
appG := app.Gin{C: c} appG := app.Gin{C: c}
setting.FreshVersion() setting.FreshVersion()
latestVersion:=app.GetLatestVersion() //latestVersion:=app.GetLatestVersion()
if latestVersion==""{ var pai pai_service.Pai
//1 bityuan 2 chain33-pai
latestVersion,err := pai.GetPaiLatestVersion(int32(1))
if latestVersion=="" || err != nil{
appG.Response(http.StatusOK,e.NETWORK_ERROR,"network error,please try again") appG.Response(http.StatusOK,e.NETWORK_ERROR,"network error,please try again")
return return
} }
......
...@@ -39,7 +39,7 @@ func GetPaiVersion(c *gin.Context) { ...@@ -39,7 +39,7 @@ func GetPaiVersion(c *gin.Context) {
version := app.GetVersion() version := app.GetVersion()
var pai pai_service.Pai var pai pai_service.Pai
latest,err := pai.GetPaiLatestVersion() latest,err := pai.GetPaiLatestVersion(int32(2))
if err != nil { if err != nil {
appG.Response(http.StatusOK, e.NETWORK_ERROR, nil) appG.Response(http.StatusOK, e.NETWORK_ERROR, nil)
return return
......
...@@ -136,9 +136,9 @@ func getPaiConfig(command string ,arg ...string) (config map[string]string,err e ...@@ -136,9 +136,9 @@ func getPaiConfig(command string ,arg ...string) (config map[string]string,err e
return list, nil return list, nil
} }
func (p *Pai) GetPaiLatestVersion() (string,error) { func (p *Pai) GetPaiLatestVersion(t int32) (string,error) {
data := make(map[string]interface{}) data := make(map[string]interface{})
data["type"] = 2 data["type"] = t
bytesData, _ := json.Marshal(data) bytesData, _ := json.Marshal(data)
resp, err := http.Post(setting.Chain33Pai.VersionUrl,"application/json", bytes.NewReader(bytesData)) resp, err := http.Post(setting.Chain33Pai.VersionUrl,"application/json", bytes.NewReader(bytesData))
if err != nil { if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment