Fix panic bug when server stop with alias (#5054)

Signed-off-by: yangxuan <xuan.yang@zilliz.com>
pull/5027/head
XuanYang-cn 2021-04-26 20:45:16 +08:00 committed by GitHub
parent 4cec3924cc
commit 6ad2252f2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 9 deletions

View File

@ -22,10 +22,10 @@ import (
"github.com/milvus-io/milvus/cmd/distributed/roles"
)
func run(serverType, runtTimeDir, svrAliase string) error {
func run(serverType, runtTimeDir, svrAlias string) error {
var fileName string
if len(svrAliase) != 0 {
fileName = fmt.Sprintf("%s-%s.pid", serverType, svrAliase)
if len(svrAlias) != 0 {
fileName = fmt.Sprintf("%s-%s.pid", serverType, svrAlias)
} else {
fileName = serverType + ".pid"
}
@ -76,8 +76,13 @@ func run(serverType, runtTimeDir, svrAliase string) error {
return nil
}
func stop(serverType, runtimeDir string) error {
fileName := serverType + ".pid"
func stop(serverType, runtimeDir, svrAlias string) error {
var fileName string
if len(svrAlias) != 0 {
fileName = fmt.Sprintf("%s-%s.pid", serverType, svrAlias)
} else {
fileName = serverType + ".pid"
}
var err error
var fd *os.File
if fd, err = os.OpenFile(path.Join(runtimeDir, fileName), os.O_RDONLY, 0664); err != nil {
@ -133,8 +138,8 @@ func main() {
serverType := os.Args[2]
flags := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
var svrAliase string
flags.StringVar(&svrAliase, "alias", "", "set aliase")
var svrAlias string
flags.StringVar(&svrAlias, "alias", "", "set aliase")
if err := flags.Parse(os.Args[3:]); err != nil {
os.Exit(-1)
@ -152,11 +157,11 @@ func main() {
switch command {
case "run":
if err := run(serverType, runtimeDir, svrAliase); err != nil {
if err := run(serverType, runtimeDir, svrAlias); err != nil {
panic(err)
}
case "stop":
if err := stop(serverType, runtimeDir); err != nil {
if err := stop(serverType, runtimeDir, svrAlias); err != nil {
panic(err)
}
default: