From 08f01c51bbeaee94d88b21a3cf263c3698f4db5a Mon Sep 17 00:00:00 2001 From: sunty <1172534965@qq.com> Date: 星期三, 15 四月 2020 19:57:56 +0800 Subject: [PATCH] add server option --- controllers/swfsControllers.go | 31 ++++++++++++++++++++++--------- 1 files changed, 22 insertions(+), 9 deletions(-) diff --git a/controllers/swfsControllers.go b/controllers/swfsControllers.go index 32aa128..475efc0 100644 --- a/controllers/swfsControllers.go +++ b/controllers/swfsControllers.go @@ -1,6 +1,7 @@ package controllers import ( + "encoding/json" "fmt" "github.com/gin-gonic/gin" "io/ioutil" @@ -80,12 +81,12 @@ func AsMaVo() { AsMaster() - ReplaceLineContentBySearch(StartScriptAsMaVo, Option, config.Server.ScriptPath, StartServerScript) + ReplaceLineContentBySearch(Option+StartScriptAsMaVo, Option, config.Server.ScriptPath, StartServerScript) } func (sc *SeaweedfsController) RoleOfVolumeToMasterController(c *gin.Context) { AsMaster() - ReplaceLineContentBySearch(StartScriptAsMaVo, Option, config.Server.ScriptPath, StartServerScript) + ReplaceLineContentBySearch(Option+StartScriptAsMaVo, Option, config.Server.ScriptPath, StartServerScript) } func (sc *SeaweedfsController) RestartServerController(c *gin.Context) { @@ -134,33 +135,44 @@ //閲嶅惎鎵�鏈夎妭鐐规湇鍔″苟楠岃瘉 func Restart(ip string, timeOut int) { url := "http://" + ip + ":7020/node/api-v/swfs/restartServer" + var info interface{} httpRes, _ := http.Get(url) defer httpRes.Body.Close() body, _ := ioutil.ReadAll(httpRes.Body) - startupItem := "" + json.Unmarshal(body, &info) + res, ok := info.(map[string]interface{}) + if !ok { + fmt.Println("http response interface can not change map[string]interface{}") + } + startupItem := res["data"].(string) if httpRes.StatusCode == 200 { startupItem = string(body) } tick := time.Tick(1 * time.Second) for countdown := timeOut; countdown > 0; countdown-- { - Verification(startupItem, ip) + result := Verification(startupItem, ip) + if result == true { + break + } <-tick } } -func Verification(startupItem string, ip string) { +//楠岃瘉鏈嶅姟鐘舵�� +func Verification(startupItem string, ip string) bool { + resStatu := false switch startupItem { case StartScriptAsVolume: verificationVolumeUrl := "http://" + ip + ":6700" _, volume1Err := http.Get(verificationVolumeUrl) if volume1Err == nil { - break + resStatu = true } case StartScriptAsMaster: verificationMasterUrl := "http://" + ip + ":6333" _, masterErr := http.Get(verificationMasterUrl) if masterErr == nil { - break + resStatu = true } case StartScriptAsMaVo: verificationMasterUrl := "http://" + ip + ":6333" @@ -168,9 +180,10 @@ _, masterErr := http.Get(verificationMasterUrl) _, volume1Err := http.Get(verificationVolumeUrl) if masterErr == nil && volume1Err == nil { - break + resStatu = true } } + return resStatu } //鑾峰彇鏈湴鍚姩椤� @@ -226,7 +239,7 @@ if nowPeers == nil || len(nowPeers) == 0 { return false } - ReplaceLineContentBySearch(StartScriptAsVolume, Option, config.Server.ScriptPath, StartServerScript) + ReplaceLineContentBySearch(Option+StartScriptAsVolume, Option, config.Server.ScriptPath, StartServerScript) ReplaceLineContentBySearch(GetNewPeers(), Peer, config.Server.ScriptPath, StartServerScript) StartServer(config.Server.ScriptPath) return true -- Gitblit v1.8.0