diff --git a/gala-ops/server/httphandler/agent.go b/gala-ops/server/httphandler/agent.go index 661e6c54d36cddf85ac7ca6dd458eed6fbfa3fd4..9b865894a97521a2b74ec0983ba66653ff5ea222 100644 --- a/gala-ops/server/httphandler/agent.go +++ b/gala-ops/server/httphandler/agent.go @@ -20,7 +20,7 @@ func InstallGopher(ctx *gin.Context) { }) } - cmd := "yum install -y gala-gopher" + cmd := "yum install -y gala-gopher && systemctl start gala-gopher" cmdResults, err := pluginclient.Client().RunScript(param.Batch, cmd) if err != nil { ctx.JSON(http.StatusBadRequest, gin.H{ @@ -46,6 +46,8 @@ func InstallGopher(ctx *gin.Context) { d.Error = result.Stderr } + // TODO: add gala-gopher to prometheus monitor target here + ret = append(ret, d) } @@ -58,6 +60,50 @@ func InstallGopher(ctx *gin.Context) { func UpgradeGopher(ctx *gin.Context) { // TODO + param := &struct { + Batch []string + }{} + if err := ctx.BindJSON(param); err != nil { + ctx.JSON(http.StatusBadRequest, gin.H{ + "code": -1, + "status": "parameter error", + }) + } + + cmd := "systemctl stop gala-gopher && yum upgrade -y gala-gopher && systemctl start gala-gopher" + cmdResults, err := pluginclient.Client().RunScript(param.Batch, cmd) + if err != nil { + ctx.JSON(http.StatusBadRequest, gin.H{ + "code": -1, + "status": fmt.Sprintf("run remote script error:%s", err), + }) + } + + ret := []interface{}{} + for _, result := range cmdResults { + d := struct { + MachineUUID string + UninstallStatus string + Error string + }{ + MachineUUID: result.MachineUUID, + UninstallStatus: "ok", + Error: "", + } + + if result.Code != 0 { + d.UninstallStatus = "error" + d.Error = result.Stderr + } + + ret = append(ret, d) + } + + ctx.JSON(http.StatusOK, gin.H{ + "code": 0, + "status": "ok", + "data": ret, + }) } func UninstallGopher(ctx *gin.Context) { @@ -72,7 +118,7 @@ func UninstallGopher(ctx *gin.Context) { }) } - cmd := "yum autoremove -y gala-gopher" + cmd := "systemctl stop gala-gopher && yum autoremove -y gala-gopher" cmdResults, err := pluginclient.Client().RunScript(param.Batch, cmd) if err != nil { ctx.JSON(http.StatusBadRequest, gin.H{