代码拉取完成,页面将自动刷新
package startup
import (
"flag"
"gitee.com/kelvins-io/kelvins/internal/logging"
"io/ioutil"
"os"
"strconv"
)
type startUpType string
const (
startUpStart startUpType = "start"
startUpReStart startUpType = "restart"
startUpStop startUpType = "stop"
)
var (
control = flag.String("s", string(startUpStart), "control cmd eg: start,stop,restart")
)
func ParseCliCommand(pidFile string) (next bool, err error) {
flag.Parse()
cmd := startUpType(*control)
switch cmd {
case startUpStart:
next = true
return
case startUpReStart:
case startUpStop:
default:
next = false
logging.Info("unsupported command!!!")
return
}
pid, err := parsePidFile(pidFile)
if err != nil {
return
}
return execProcessCmd(pid, cmd)
}
func parsePidFile(pidFile string) (pid int, err error) {
_, err = os.Stat(pidFile)
if err != nil {
return
}
var f *os.File
f, err = os.OpenFile(pidFile, os.O_RDWR, 0666)
if err != nil {
return
}
content, err := ioutil.ReadAll(f)
if err != nil {
return
}
pid, err = strconv.Atoi(string(content))
return
}
func processControl(pid int, signal os.Signal) error {
p, err := os.FindProcess(pid)
if err != nil {
return err
}
return p.Signal(signal)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。