代码拉取完成,页面将自动刷新
//+build darwin linux
package shell_util
import (
"gitee.com/lwow2025/snake-go/common/util"
"path/filepath"
"os"
"gopkg.in/mgo.v2/bson"
"io/ioutil"
"os/exec"
"fmt"
"gitee.com/lwow2025/snake-go/common/log"
"bufio"
"bytes"
"strings"
)
func ExecCmdByTmpFile(cmd []byte, shFileArgs ...string) (rb []byte, err error) {
tmpPath := filepath.Join(util.HomeDir(), "tmp")
os.MkdirAll(tmpPath, 0755)
tmpShFile := filepath.Join(tmpPath, bson.NewObjectId().Hex() + ".sh")
ioutil.WriteFile(tmpShFile, cmd, 0755)
defer os.RemoveAll(tmpShFile)
args := append([]string{ tmpShFile }, shFileArgs...)
//log.L.Sugar().Debug(string(cmd), " ", args)
rb, err = exec.Command("/bin/bash", args...).Output()
return
}
func Alive(appStartCmd string) bool {
rb, err := ExecCmdByTmpFile([]byte(fmt.Sprintf(`ps aux|grep "%v"`, appStartCmd)))
if err != nil {
log.L.Sugar().Error("check app alive failed", " result=", string(rb), " err=", err)
return false
}
counter := 0
scanner := bufio.NewScanner(bytes.NewReader(rb))
for scanner.Scan() {
tmpText := scanner.Text()
if strings.Contains(tmpText, appStartCmd) {
counter++
}
}
if counter > 1 {
return true
}
return false
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。