자동실행 추가
This commit is contained in:
@ -2,6 +2,7 @@ package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
@ -32,9 +33,25 @@ import (
|
||||
)
|
||||
|
||||
type runcommand struct {
|
||||
Exec string `json:"exec"`
|
||||
Args []string `json:"args"`
|
||||
Version string `json:"version"`
|
||||
Exec string `json:"exec"`
|
||||
Args []string `json:"args"`
|
||||
Version string `json:"version"`
|
||||
AutoRestart bool `json:"auto_restart"`
|
||||
}
|
||||
|
||||
type easyruncommand runcommand
|
||||
|
||||
func (t *runcommand) UnmarshalJSON(b []byte) error {
|
||||
easy := easyruncommand{
|
||||
Version: "latest",
|
||||
AutoRestart: true,
|
||||
}
|
||||
if err := json.Unmarshal(b, &easy); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*t = runcommand(easy)
|
||||
return nil
|
||||
}
|
||||
|
||||
type clientConfig struct {
|
||||
@ -79,6 +96,7 @@ type procmeta struct {
|
||||
args []string
|
||||
version string
|
||||
verpath string
|
||||
recover bool
|
||||
state int32
|
||||
stdin io.WriteCloser
|
||||
}
|
||||
@ -459,16 +477,40 @@ func NewClient(standalone bool) (HoustonClient, error) {
|
||||
id64, _ := strconv.ParseInt(idstr, 10, 0)
|
||||
id := int32(id64)
|
||||
|
||||
var found *procmeta
|
||||
hc.childProcs = gocommon.ShrinkSlice(hc.childProcs, func(e *procmeta) bool {
|
||||
if e.id == id {
|
||||
e.cmd.Wait()
|
||||
e.cmd.Process.Release()
|
||||
found = e
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
||||
if found != nil {
|
||||
found.cmd.Wait()
|
||||
found.cmd.Process.Release()
|
||||
|
||||
if found.recover {
|
||||
time.Sleep(time.Second)
|
||||
sr := shared.StartProcessRequest{
|
||||
Name: found.name,
|
||||
Version: found.version,
|
||||
Args: found.args,
|
||||
AutoRestart: found.recover,
|
||||
}
|
||||
|
||||
if err := hc.startChildProcess(&sr); err != nil {
|
||||
logger.Println("startChildProcess failed by autorun :", err)
|
||||
logger.ErrorWithCallStack(err)
|
||||
} else {
|
||||
logger.Println("recover success :", sr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if op != nil {
|
||||
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -541,9 +583,10 @@ func (hc *houstonClient) Start() {
|
||||
// service 서비스
|
||||
for i := 0; i < count; i++ {
|
||||
sr := shared.StartProcessRequest{
|
||||
Name: service,
|
||||
Version: cmd.Version,
|
||||
Args: append([]string{cmd.Exec}, cmd.Args...),
|
||||
Name: service,
|
||||
Version: cmd.Version,
|
||||
Args: append([]string{cmd.Exec}, cmd.Args...),
|
||||
AutoRestart: cmd.AutoRestart,
|
||||
}
|
||||
|
||||
if err := hc.startChildProcess(&sr); err != nil {
|
||||
|
||||
@ -216,6 +216,7 @@ func prepareProcessLaunch(storageRoot string, req *shared.StartProcessRequest) (
|
||||
name: req.Name,
|
||||
args: req.Args,
|
||||
version: req.Version,
|
||||
recover: req.AutoRestart,
|
||||
verpath: verpath,
|
||||
state: int32(protos.ProcessState_Stopped),
|
||||
stdin: stdin,
|
||||
|
||||
@ -27,9 +27,10 @@ type WithdrawRequest struct {
|
||||
}
|
||||
|
||||
type StartProcessRequest struct {
|
||||
Name string
|
||||
Version string
|
||||
Args []string
|
||||
Name string
|
||||
Version string
|
||||
Args []string
|
||||
AutoRestart bool
|
||||
}
|
||||
|
||||
type StopProcessRequest struct {
|
||||
|
||||
Reference in New Issue
Block a user