Commit 97ce2093 authored by ligaishun's avatar ligaishun

Update node.go

parent d258ef93
...@@ -19,40 +19,41 @@ var flag bool//判断是否正在更新 ...@@ -19,40 +19,41 @@ 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.NodeError!=nil{ 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 return
} }
cmd:=exec.Command("kill","-9",app.Bityuan.Pid) cmd:=exec.Command("kill","-9",app.Bityuan.Pid)
err:=cmd.Start() err:=cmd.Start()
if err!=nil{ if err!=nil{
appG.Response(http.StatusOK, e.ERROR, "fail to reset wallet") appG.Response(http.StatusOK, e.ENV_ERROR, "fail to reset wallet")
log.Fatalln(err) log.Fatalln(err)
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.ERROR, "fail to reset wallet") appG.Response(http.StatusOK, e.NODE_ERROR, "fail to reset wallet")
log.Fatalln(err) log.Fatalln(err)
return return
} }
err=app.StartProcess(setting.Chain33Pai.Auto) err=app.StartProcess(setting.Chain33Pai.Auto)
if err!=nil{ 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) log.Fatalln(err)
return return
} }
appG.Response(http.StatusOK, e.SUCCESS,nil) appG.Response(http.StatusOK, e.SUCCESS,"reset complete")
} }
func UpdateNode(c *gin.Context){ func UpdateNode(c *gin.Context){
appG := app.Gin{C: c} appG := app.Gin{C: c}
if flag{ 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{ if app.NodeError!=nil{
appG.Response(http.StatusOK, e.ERROR, app.NodeError.Error()) appG.Response(http.StatusOK, e.NODE_ERROR,"node internal error,could not start node")
return return
} }
setting.FreshVersion() setting.FreshVersion()
...@@ -66,13 +67,13 @@ func UpdateNode(c *gin.Context){ ...@@ -66,13 +67,13 @@ func UpdateNode(c *gin.Context){
if flag{ if flag{
app.UpdateInfo.Info="Updating..." app.UpdateInfo.Info="Updating..."
appG.Response(http.StatusOK,e.SUCCESS,"node is updating") appG.Response(http.StatusOK,e.SUCCESS_RUNNING,"node is updating")
return return
} }
if latestVersion==""{ if latestVersion==""{
flag=false flag=false
app.UpdateInfo.Info="network error" app.UpdateInfo.Info="network error"
appG.Response(http.StatusOK,e.ERROR,"network error") appG.Response(http.StatusOK,e.NETWORK_ERROR,"network error,please checkout your network then try again")
return return
} }
appG.Response(http.StatusOK,e.SUCCESS,"update job started") appG.Response(http.StatusOK,e.SUCCESS,"update job started")
...@@ -113,7 +114,7 @@ func ResetNode(c* gin.Context){ ...@@ -113,7 +114,7 @@ func ResetNode(c* gin.Context){
app.UpdateInfo.Status=false app.UpdateInfo.Status=false
app.UpdateInfo.Info="updating..." app.UpdateInfo.Info="updating..."
if flag{ if flag{
appG.Response(http.StatusOK,e.SUCCESS,"node is resetting") appG.Response(http.StatusOK,e.SUCCESS_RUNNING,"node is resetting")
return return
} }
appG.Response(http.StatusOK,e.SUCCESS,"reset job started") appG.Response(http.StatusOK,e.SUCCESS,"reset job started")
...@@ -137,6 +138,7 @@ func ResetNode(c* gin.Context){ ...@@ -137,6 +138,7 @@ func ResetNode(c* gin.Context){
//start := exec.Command(path.Dir(app.Wallet.Path) + "/" + app.Wallet.PName) //start := exec.Command(path.Dir(app.Wallet.Path) + "/" + app.Wallet.PName)
err=kill.Start() err=kill.Start()
if err != nil { if err != nil {
app.UpdateInfo.Info = fmt.Sprintf("fail to reset node:%s",err.Error()) app.UpdateInfo.Info = fmt.Sprintf("fail to reset node:%s",err.Error())
return return
} }
...@@ -163,6 +165,10 @@ func ResetNode(c* gin.Context){ ...@@ -163,6 +165,10 @@ func ResetNode(c* gin.Context){
func UpdateDetail(c* gin.Context){ func UpdateDetail(c* gin.Context){
appG := app.Gin{C: c} 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) appG.Response(http.StatusOK,e.SUCCESS,app.UpdateInfo)
} }
...@@ -172,7 +178,7 @@ func Version(c* gin.Context){ ...@@ -172,7 +178,7 @@ func Version(c* gin.Context){
setting.FreshVersion() setting.FreshVersion()
latestVersion:=app.GetLatestVersion() latestVersion:=app.GetLatestVersion()
if latestVersion==""{ if latestVersion==""{
appG.Response(http.StatusOK,e.ERROR,"network error,please try again") appG.Response(http.StatusOK,e.NETWORK_ERROR,"network error,please try again")
return return
} }
appG.Response(http.StatusOK,e.SUCCESS,gin.H{ appG.Response(http.StatusOK,e.SUCCESS,gin.H{
...@@ -181,11 +187,10 @@ func Version(c* gin.Context){ ...@@ -181,11 +187,10 @@ func Version(c* gin.Context){
}) })
} }
func NodeInfo(c *gin.Context){ func NodeInfo(c *gin.Context){
appG:=app.Gin{C:c} appG:=app.Gin{C:c}
if app.NodeError!=nil{ if app.NodeError!=nil{
appG.Response(http.StatusOK,e.ERROR,app.NodeError.Error()) appG.Response(http.StatusOK,e.NODE_ERROR,"node down")
return return
} }
appG.Response(http.StatusOK,e.SUCCESS,"node is running") appG.Response(http.StatusOK,e.SUCCESS,"node is running")
......
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