运行终止 go 应用程序的 shell 脚本

问题描述 投票:0回答:1

我需要在 debian 上重新启动一个 go 应用程序进程,这需要运行以下 bash 文件:

systemctl stop go_service && other_command && systemctl start go_service

我尝试使用以下代码:

cmd := exec.Command("bash", scriptPath)
// Start the command asynchronously
if err := cmd.Start(); err != nil {
    eError("Error starting command: %v\n", err)
    return
}

但是第一个 bash 命令终止了该进程,并且它永远不会完成应该再次启动它的下一个命令

知道如何运行整个 bash 文件吗?

linux bash go debian
1个回答
0
投票

我通过使用以下方法解决了这个问题: systemctl 重新启动 go_service

© www.soinside.com 2019 - 2024. All rights reserved.