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