This commit is contained in:
2024-09-27 17:34:30 +09:00
2 changed files with 29 additions and 22 deletions

View File

@ -91,16 +91,17 @@ type HoustonClient interface {
var seq = int32(1)
type procmeta struct {
id int32
cmd *exec.Cmd
name string
args []string
version string
verpath string
recover bool
state int32
stdin io.WriteCloser
logfile string
id int32
cmd *exec.Cmd
name string
args []string
version string
verpath string
recover bool
state int32
stdin io.WriteCloser
logfile string
keepLatest bool
}
func (pm *procmeta) isState(s protos.ProcessState) bool {
@ -362,6 +363,10 @@ func NewClient(standalone bool) (HoustonClient, error) {
proc.cmd.Process.Release()
if proc.isState(protos.ProcessState_Restart) {
if proc.keepLatest {
proc.version = "latest"
}
if err := hc.startChildProcess(&shared.StartProcessRequest{
Version: proc.version,
Name: proc.name,

View File

@ -150,6 +150,7 @@ func prepareProcessLaunch(storageRoot string, req *shared.StartProcessRequest) (
return nil, errors.New("args is empty")
}
foundVersion := req.Version
if req.Version == "latest" {
entries, err := os.ReadDir(path.Join(storageRoot, req.Name))
if err != nil {
@ -175,11 +176,11 @@ func prepareProcessLaunch(storageRoot string, req *shared.StartProcessRequest) (
}
if len(latestVersion) > 0 {
req.Version = latestVersion
foundVersion = latestVersion
}
}
verpath := path.Join(storageRoot, req.Name, req.Version)
verpath := path.Join(storageRoot, req.Name, foundVersion)
fi, err := os.Stat(verpath)
if err != nil {
return nil, err
@ -210,16 +211,17 @@ func prepareProcessLaunch(storageRoot string, req *shared.StartProcessRequest) (
seq++
return &procmeta{
id: seq,
cmd: cmd,
name: req.Name,
args: req.Args,
version: req.Version,
recover: req.AutoRestart,
verpath: verpath,
state: int32(protos.ProcessState_Stopped),
stdin: stdin,
logfile: req.OutputLogFile,
id: seq,
cmd: cmd,
name: req.Name,
args: req.Args,
version: foundVersion,
recover: req.AutoRestart,
verpath: verpath,
state: int32(protos.ProcessState_Stopped),
stdin: stdin,
logfile: req.OutputLogFile,
keepLatest: req.Version == "latest",
}, nil
}
return nil, errors.New("not found")