19 Star 123 Fork 0

kelvins-io/kelvins

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
startup.go 1.19 KB
一键复制 编辑 原始数据 按行查看 历史
雨化田 提交于 2021-09-03 22:25 . 启动流程优化
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)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/kelvins-io/kelvins.git
git@gitee.com:kelvins-io/kelvins.git
kelvins-io
kelvins
kelvins
v1.5.6

搜索帮助