修复 cmd 调用外部程序失败

This commit is contained in:
liwei1dao 2022-09-21 15:17:17 +08:00
parent 870c8b7f43
commit 1b50ddaabd

View File

@ -184,21 +184,25 @@ func convertServiceSttings(config *comm.GameConfig, id int, sconfig *comm.Servic
func startService(sseting *core.ServiceSttings) (err error) { func startService(sseting *core.ServiceSttings) (err error) {
var ( var (
cmd *exec.Cmd cmd *exec.Cmd
command string
confpath string = fmt.Sprintf("./conf/%s.yaml", sseting.Id)
) )
switch sseting.Type { switch sseting.Type {
case comm.Service_Gateway: //网关服务 case comm.Service_Gateway: //网关服务
cmd = exec.Command("./stup.sh", "start", sseting.Id, "gateway", fmt.Sprintf("./conf/%s.yaml", sseting.Id)) command = fmt.Sprintf("./stup.sh start %s gateway %s", sseting.Id, confpath)
break break
case comm.Service_Worker: //业务服务 case comm.Service_Worker: //业务服务
cmd = exec.Command("./stup.sh", "start", sseting.Id, "worker", fmt.Sprintf("./conf/%s.yaml", sseting.Id)) command = fmt.Sprintf("./stup.sh start %s worker %s", sseting.Id, confpath)
break break
case comm.Service_Mainte: //维护服务 case comm.Service_Mainte: //维护服务
cmd = exec.Command("./stup.sh", "start", sseting.Id, "mainte", fmt.Sprintf("./conf/%s.yaml", sseting.Id)) command = fmt.Sprintf("./stup.sh start %s mainte %s", sseting.Id, confpath)
break break
default: default:
err = fmt.Errorf("服务类型异常 stype:%s", sseting.Type) err = fmt.Errorf("服务类型异常 stype:%s", sseting.Type)
return return
} }
log.Debug("启动外部命令", log.Field{Key: "cmd", Value: command})
cmd = exec.Command("/bin/bash", "-c", command)
err = cmd.Run() err = cmd.Run()
return return
} }