diff --git a/client/client.go b/client/client.go index 8ae8962..373eaa7 100644 --- a/client/client.go +++ b/client/client.go @@ -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, diff --git a/client/operation.go b/client/operation.go index 489cbb7..c8cd90e 100644 --- a/client/operation.go +++ b/client/operation.go @@ -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")