| | |
| | | |
| | | func (sc *SeaweedfsController) RestartServerController(c *gin.Context) { |
| | | StopServer(config.Server.ScriptPath) |
| | | time.Sleep(time.Second * 1) |
| | | StartServer(config.Server.ScriptPath) |
| | | time.Sleep(time.Second * 1) |
| | | //fmt.Println("GetLocalStartupItem: ", GetLocalStartupItem(config.Server.ScriptPath, StartServerScript)) |
| | | result := strings.Split(GetLocalStartupItem(config.Server.ScriptPath, StartServerScript), "=")[1] |
| | | fmt.Println("result: ", result) |
| | |
| | | |
| | | //启动服务 |
| | | func StartServer(scriptPath string) { |
| | | util.RunScript("sh " + scriptPath + StartServerScript) |
| | | //fmt.Println("sh " + scriptPath + "/" + StartServerScript) |
| | | util.RunScript("sh " + scriptPath + "/" + StartServerScript) |
| | | } |
| | | |
| | | //停止服务 |
| | | func StopServer(scriptPath string) { |
| | | util.RunScript("sh " + scriptPath + StopServerScript) |
| | | //fmt.Println("sh " + scriptPath + "/" + StopServerScript) |
| | | util.RunScript("sh " + scriptPath + "/" + StopServerScript) |
| | | } |
| | | |
| | | //根据搜索内容替换整行内容 |
| | |
| | | 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) |
| | | json.Unmarshal(body, &info) |
| | | res, ok := info.(map[string]interface{}) |
| | | if !ok { |
| | | fmt.Println("http response interface can not change map[string]interface{}") |
| | | } |
| | | fmt.Println("res: ", res) |
| | | startupItem := res["data"].(string) |
| | | if httpRes.StatusCode == 200 { |
| | | startupItem = string(body) |
| | | } |
| | | fmt.Println("Restart startupItem: ", startupItem) |
| | | tick := time.Tick(1 * time.Second) |
| | | fmt.Println("准备开始验证节点服务") |
| | | for countdown := timeOut; countdown > 0; countdown-- { |
| | |
| | | //验证服务状态 |
| | | func Verification(startupItem string, ip string) bool { |
| | | resStatu := false |
| | | fmt.Println("Verification startupItem: ", startupItem) |
| | | switch startupItem { |
| | | case StartScriptAsVolume: |
| | | verificationVolumeUrl := "http://" + ip + ":6700" |
| | | verificationVolumeUrl := "http://" + ip + ":6700/ui/index.html" |
| | | _, volume1Err := http.Get(verificationVolumeUrl) |
| | | if volume1Err == nil { |
| | | resStatu = true |
| | |
| | | } |
| | | case StartScriptAsMaVo: |
| | | verificationMasterUrl := "http://" + ip + ":6333" |
| | | verificationVolumeUrl := "http://" + ip + ":6700" |
| | | verificationVolumeUrl := "http://" + ip + ":6700/ui/index.html" |
| | | _, masterErr := http.Get(verificationMasterUrl) |
| | | fmt.Println("masterErr", masterErr) |
| | | _, volume1Err := http.Get(verificationVolumeUrl) |
| | | fmt.Println("volume1Err", volume1Err) |
| | | if masterErr == nil && volume1Err == nil { |
| | | resStatu = true |
| | | } |
| | |
| | | var waitGroup sync.WaitGroup |
| | | fmt.Println("当前并行度coreThread:", coreThread) |
| | | for i, ip := range peersIp { |
| | | fmt.Println("重启第一组服务" + ip) |
| | | fmt.Println("重启当前组服务" + ip) |
| | | if (i+1)%coreThread == 0 { |
| | | masterIp = append(masterIp, strings.Split(ip, ":")[0]) |
| | | fmt.Println("加入第一组并开始验证第一组 masterIp: ", masterIp) |
| | | for i := 0; i < len(masterIp); i++ { |
| | | fmt.Println("len masterIp: ", len(masterIp)) |
| | | fmt.Println("第" + strconv.Itoa(i) + "个线程") |
| | | go Restart(masterIp[i], timeOut) |
| | | fmt.Println("当前goroutinebe") |
| | | waitGroup.Add(1) //每创建一个goroutine,就把任务队列中任务的数量+1 |
| | | fmt.Println("当前goroutineaf") |
| | | go Restart(masterIp[i], timeOut) |
| | | waitGroup.Done() |
| | | } |
| | | fmt.Println("这里为阻塞!!!!!") |
| | | waitGroup.Wait() //.Wait()这里会发生阻塞,直到队列中所有的任务结束就会解除阻塞 |
| | | fmt.Println("当前组任务完成") |
| | | masterIp = make([]string, 0) |
| | | fmt.Println("清空当前组成员:", masterIp) |
| | | } else { |
| | | masterIp = append(masterIp, strings.Split(ip, ":")[0]) |
| | | if len(peersIp) == i+1 { |
| | | var waitGroup sync.WaitGroup |
| | | for i := 0; i < len(masterIp); i++ { |
| | | go Restart(masterIp[i], timeOut) |
| | | waitGroup.Add(1) //每创建一个goroutine,就把任务队列中任务的数量+1 |
| | | go Restart(masterIp[i], timeOut) |
| | | waitGroup.Done() |
| | | } |
| | | waitGroup.Wait() //.Wait()这里会发生阻塞,直到队列中所有的任务结束就会解除阻塞 |
| | | masterIp = make([]string, 0) |
| | | break |
| | | } |
| | | } |
| | | |
| | | } |
| | | fmt.Println("服务流程执行完毕") |
| | | |
| | | } |
| | | |
| | | //获取查找内容当前行内容 |