Skip to content
This repository has been archived by the owner on Nov 9, 2018. It is now read-only.

Commit

Permalink
🐛 fixed repeat start
Browse files Browse the repository at this point in the history
  • Loading branch information
hellokaton committed Jun 10, 2018
1 parent d1b33ee commit 30f1031
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions cmds/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"os"
"strconv"
"strings"
"syscall"
)

const (
Expand All @@ -17,9 +16,26 @@ const (

// StartAction 启动 tale 博客
func StartAction() error {
dat, err := ioutil.ReadFile(pidFile)
if err == nil {
pid := strings.TrimSpace(string(dat))
if pid != "" {
pidInt, err := strconv.Atoi(strings.TrimSpace(string(dat)))
if err != nil {
return err
}
_, err = os.FindProcess(pidInt)
if err != nil {
return nil
}
log.Println("博客已经启动成功,请停止后重启.")
return nil
}
}

os.Remove(pidFile)
shell := "nohup java -Xms256m -Xmx256m -Dfile.encoding=UTF-8 -jar tale-letast.jar > /dev/null 2>&1 & echo $! > " + pidFile
_, _, _, err := StartCmd(shell)
_, _, _, err = StartCmd(shell)
if err != nil {
return err
}
Expand All @@ -40,12 +56,7 @@ func StopAction() error {
if err != nil {
return err
}
err = syscall.Kill(pid, syscall.Signal(2))
// _, err = KillPID(pid)
if err != nil {
log.Println("err", err)
return err
}
KillPID(pid)
err = os.Remove(pidFile)
if err != nil {
return err
Expand Down

0 comments on commit 30f1031

Please sign in to comment.