dev
This commit is contained in:
parent
65cdca43c1
commit
78dbac4b2e
|
@ -0,0 +1,72 @@
|
||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"git.apinb.com/bsm-sdk/engine/env"
|
||||||
|
"git.apinb.com/bsm-sdk/engine/utils"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var restartCmd = &cobra.Command{
|
||||||
|
Use: "restart",
|
||||||
|
Short: "<ServiceKey> 更新一个微服务服务,并重启该服务.",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
if len(args) != 1 {
|
||||||
|
fmt.Println("Update a microservice service and restart it!")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
srv := args[0]
|
||||||
|
execbin := filepath.Join(env.MeshEnv.Prefix, srv)
|
||||||
|
binExists := utils.PathExists(execbin)
|
||||||
|
if !binExists {
|
||||||
|
fmt.Println(srv, "microservice not install")
|
||||||
|
} else {
|
||||||
|
restartExecute(srv)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func restartExecute(srv string) {
|
||||||
|
localVersion := getCurrentVersion(srv)
|
||||||
|
fmt.Println("[1/5] Check local microservice version:", localVersion)
|
||||||
|
|
||||||
|
service := getService(srv)
|
||||||
|
if service == nil {
|
||||||
|
fmt.Println("ERR:", srv, "Not Found!")
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("[2/5] Check registry microservice version:", service.Version)
|
||||||
|
|
||||||
|
service.Stop()
|
||||||
|
|
||||||
|
yamlUrl := fmt.Sprintf("%s%s/%s/%s_%s.yaml", service.OssUrl, service.EtcPath, env.MeshEnv.Workspace, srv, env.MeshEnv.RuntimeMode)
|
||||||
|
body, err := utils.HttpGet(yamlUrl)
|
||||||
|
checkError(err)
|
||||||
|
fmt.Println("[3/5] Download YAML Configure:", yamlUrl, " [OK]")
|
||||||
|
yamlPath := filepath.Join(env.MeshEnv.Prefix, service.EtcPath, fmt.Sprintf("%s_%s.yaml", srv, env.MeshEnv.RuntimeMode))
|
||||||
|
utils.StringToFile(yamlPath, string(body))
|
||||||
|
|
||||||
|
if localVersion != service.Version {
|
||||||
|
downUrl := service.OssUrl + service.FilePath
|
||||||
|
fmt.Println("[4/5] Download Binrary File:", downUrl)
|
||||||
|
binPath := filepath.Join(env.MeshEnv.Prefix, srv)
|
||||||
|
DownloadFile(downUrl, binPath, func(length, downLen int64) {
|
||||||
|
fmt.Fprintf(os.Stdout, "Total:%d KB, Current:%d KB, Percent:%.2f%%\r", length, downLen, (float32(downLen)/float32(length))*100)
|
||||||
|
})
|
||||||
|
|
||||||
|
fmt.Println("[5/5] Start Microservice:", srv)
|
||||||
|
service.Start()
|
||||||
|
fmt.Println("Updated Success!")
|
||||||
|
} else {
|
||||||
|
fmt.Println("[4/5] "+srv+" Already the latest version:", localVersion)
|
||||||
|
fmt.Println("[5/5] Restart Microservice:", srv)
|
||||||
|
service.Start()
|
||||||
|
fmt.Println("Restart Success!")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -22,7 +22,7 @@ func init() {
|
||||||
registryUrl = env.GetEnvDefault("BlocksMesh_Registry", "http://registry.apinb.com")
|
registryUrl = env.GetEnvDefault("BlocksMesh_Registry", "http://registry.apinb.com")
|
||||||
}
|
}
|
||||||
|
|
||||||
rootCmd.AddCommand(psCmd, installCmd, updateCmd, checkCmd)
|
rootCmd.AddCommand(psCmd, installCmd, updateCmd, checkCmd, restartCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
|
|
|
@ -61,7 +61,7 @@ func updateExecute(srv string) {
|
||||||
|
|
||||||
fmt.Println("[5/5] Start Microservice:", srv)
|
fmt.Println("[5/5] Start Microservice:", srv)
|
||||||
service.Start()
|
service.Start()
|
||||||
fmt.Println("Install Successful!")
|
fmt.Println("Updated Success!")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue