mirror of
https://github.com/lzh-1625/go_process_manager.git
synced 2025-10-01 06:12:07 +08:00
optimal process state
This commit is contained in:
@@ -64,7 +64,7 @@ func (p *procApi) StartProcess(ctx *gin.Context, req struct {
|
||||
logic.ProcessCtlLogic.AddProcess(req.Uuid, proc)
|
||||
return nil
|
||||
}
|
||||
if prod.State.State == eum.ProcessStateStart {
|
||||
if prod.State.State == eum.ProcessStateStart || prod.State.State == eum.ProcessStateRunning {
|
||||
return errors.New("process is currently running")
|
||||
}
|
||||
prod.ResetRestartTimes()
|
||||
|
@@ -74,7 +74,7 @@ func (w *wsApi) WebsocketHandle(ctx *gin.Context, req model.WebsocketHandleReq)
|
||||
wsLock: sync.Mutex{},
|
||||
}
|
||||
proc.ReadCache(wci)
|
||||
if proc.State.State == eum.ProcessStateStart {
|
||||
if proc.State.State == eum.ProcessStateRunning {
|
||||
proc.SetTerminalSize(req.Cols, req.Rows)
|
||||
w.startWsConnect(wci, cancel, proc, hasOprPermission(ctx, req.Uuid, eum.OperationTerminalWrite))
|
||||
proc.AddConn(reqUser, wci)
|
||||
@@ -112,7 +112,7 @@ func (w *wsApi) WebsocketShareHandle(ctx *gin.Context, req model.WebsocketHandle
|
||||
if proc.HasWsConn(guestName) {
|
||||
return errors.New("connection already exists")
|
||||
}
|
||||
if proc.State.State != eum.ProcessStateStart {
|
||||
if proc.State.State != eum.ProcessStateRunning {
|
||||
return errors.New("process not is running")
|
||||
}
|
||||
if !proc.VerifyControl() {
|
||||
|
@@ -281,7 +281,7 @@ func (p *ProcessBase) monitorHanler() {
|
||||
ticker := time.NewTicker(time.Second * time.Duration(config.CF.PerformanceInfoInterval))
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
if p.State.State != eum.ProcessStateStart {
|
||||
if p.State.State != eum.ProcessStateRunning {
|
||||
log.Logger.Debugw("进程未在运行", "state", p.State.State)
|
||||
return
|
||||
}
|
||||
|
@@ -37,7 +37,7 @@ func (p *processCtlLogic) KillProcess(uuid int) error {
|
||||
if !ok {
|
||||
return errors.New("进程类型错误")
|
||||
}
|
||||
if result.State.State != eum.ProcessStateStart {
|
||||
if result.State.State != eum.ProcessStateRunning {
|
||||
return nil
|
||||
}
|
||||
result.State.manualStopFlag = true
|
||||
@@ -61,7 +61,7 @@ func (p *processCtlLogic) KillAllProcess() {
|
||||
wg := sync.WaitGroup{}
|
||||
p.processMap.Range(func(key, value any) bool {
|
||||
process := value.(*ProcessBase)
|
||||
if process.State.State != eum.ProcessStateStart {
|
||||
if process.State.State != eum.ProcessStateRunning {
|
||||
return true
|
||||
}
|
||||
wg.Add(1)
|
||||
|
@@ -2,6 +2,7 @@ package logic
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
@@ -37,7 +38,7 @@ func (p *ProcessPty) Start() (err error) {
|
||||
}
|
||||
}()
|
||||
if ok := p.SetState(eum.ProcessStateStart, func() bool {
|
||||
return p.State.State != 1
|
||||
return p.State.State != eum.ProcessStateRunning && p.State.State != eum.ProcessStateStart
|
||||
}); !ok {
|
||||
log.Logger.Warnw("进程已在运行,跳过启动")
|
||||
return nil
|
||||
@@ -66,6 +67,11 @@ func (p *ProcessPty) Start() (err error) {
|
||||
}
|
||||
log.Logger.Infow("进程启动成功", "进程名称", p.Name, "重启次数", p.State.restartTimes)
|
||||
p.pInit()
|
||||
if !p.SetState(eum.ProcessStateRunning, func() bool {
|
||||
return p.State.State == eum.ProcessStateStart
|
||||
}) {
|
||||
return errors.New("状态异常启动失败")
|
||||
}
|
||||
p.push("进程启动成功")
|
||||
return nil
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ package logic
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"io"
|
||||
"os/exec"
|
||||
|
||||
@@ -46,7 +47,7 @@ func (p *ProcessStd) Start() (err error) {
|
||||
}
|
||||
}()
|
||||
if ok := p.SetState(eum.ProcessStateStart, func() bool {
|
||||
return p.State.State != eum.ProcessStateStart
|
||||
return p.State.State != eum.ProcessStateRunning && p.State.State != eum.ProcessStateStart
|
||||
}); !ok {
|
||||
log.Logger.Warnw("进程已在运行,跳过启动")
|
||||
return nil
|
||||
@@ -73,6 +74,11 @@ func (p *ProcessStd) Start() (err error) {
|
||||
log.Logger.Infow("进程启动成功", "重启次数", p.State.restartTimes)
|
||||
p.op = cmd.Process
|
||||
p.pInit()
|
||||
if !p.SetState(eum.ProcessStateRunning, func() bool {
|
||||
return p.State.State == eum.ProcessStateStart
|
||||
}) {
|
||||
return errors.New("状态异常启动失败")
|
||||
}
|
||||
p.push("进程启动成功")
|
||||
return nil
|
||||
}
|
||||
|
@@ -13,10 +13,10 @@ type conditionFunc func(data *model.Task, proc *ProcessBase) bool
|
||||
|
||||
var conditionHandle = map[eum.Condition]conditionFunc{
|
||||
eum.TaskCondRunning: func(data *model.Task, proc *ProcessBase) bool {
|
||||
return proc.State.State == eum.ProcessStateStart
|
||||
return proc.State.State == eum.ProcessStateRunning
|
||||
},
|
||||
eum.TaskCondNotRunning: func(data *model.Task, proc *ProcessBase) bool {
|
||||
return proc.State.State != eum.ProcessStateStart
|
||||
return proc.State.State != eum.ProcessStateRunning && proc.State.State != eum.ProcessStateStart
|
||||
},
|
||||
eum.TaskCondException: func(data *model.Task, proc *ProcessBase) bool {
|
||||
return proc.State.State == eum.ProcessStateWarnning
|
||||
@@ -28,7 +28,7 @@ type operationFunc func(data *model.Task, proc *ProcessBase) bool
|
||||
|
||||
var OperationHandle = map[eum.TaskOperation]operationFunc{
|
||||
eum.TaskStart: func(data *model.Task, proc *ProcessBase) bool {
|
||||
if proc.State.State == eum.ProcessStateStart {
|
||||
if proc.State.State == eum.ProcessStateRunning || proc.State.State == eum.ProcessStateStart {
|
||||
log.Logger.Debugw("进程已在运行", "proc", proc.Name)
|
||||
return false
|
||||
}
|
||||
@@ -37,7 +37,7 @@ var OperationHandle = map[eum.TaskOperation]operationFunc{
|
||||
},
|
||||
|
||||
eum.TaskStartWaitDone: func(data *model.Task, proc *ProcessBase) bool {
|
||||
if proc.State.State == eum.ProcessStateStart {
|
||||
if proc.State.State == eum.ProcessStateRunning || proc.State.State == eum.ProcessStateStart {
|
||||
log.Logger.Debugw("进程已在运行", "proc", proc.Name)
|
||||
return false
|
||||
}
|
||||
@@ -56,7 +56,7 @@ var OperationHandle = map[eum.TaskOperation]operationFunc{
|
||||
},
|
||||
|
||||
eum.TaskStop: func(data *model.Task, proc *ProcessBase) bool {
|
||||
if proc.State.State != eum.ProcessStateStart {
|
||||
if proc.State.State != eum.ProcessStateRunning {
|
||||
log.Logger.Debugw("进程未在运行", "proc", proc.Name)
|
||||
return false
|
||||
}
|
||||
@@ -67,7 +67,7 @@ var OperationHandle = map[eum.TaskOperation]operationFunc{
|
||||
},
|
||||
|
||||
eum.TaskStopWaitDone: func(data *model.Task, proc *ProcessBase) bool {
|
||||
if proc.State.State != eum.ProcessStateStart {
|
||||
if proc.State.State != eum.ProcessStateRunning {
|
||||
log.Logger.Debugw("进程未在运行", "proc", proc.Name)
|
||||
return false
|
||||
}
|
||||
|
Reference in New Issue
Block a user