Compare commits
2 Commits
52491aff17
...
b2aae5a38e
| Author | SHA1 | Date | |
|---|---|---|---|
| b2aae5a38e | |||
| 01b4782e78 |
@ -274,15 +274,22 @@ func NewClient() (HoustonClient, error) {
|
|||||||
var newprocs []*procmeta
|
var newprocs []*procmeta
|
||||||
for _, proc := range hc.childProcs {
|
for _, proc := range hc.childProcs {
|
||||||
if proc.cmd == exited {
|
if proc.cmd == exited {
|
||||||
if proc.state == protos.ProcessState_Running {
|
if proc.state == protos.ProcessState_Running || proc.state == protos.ProcessState_Restart {
|
||||||
go func(cmd *exec.Cmd) {
|
go func(proc *procmeta) {
|
||||||
if err := cmd.Process.Signal(syscall.SIGTERM); err != nil {
|
if err := proc.cmd.Process.Signal(syscall.SIGTERM); err != nil {
|
||||||
cmd.Process.Signal(os.Kill)
|
proc.cmd.Process.Signal(os.Kill)
|
||||||
}
|
}
|
||||||
cmd.Wait()
|
proc.cmd.Wait()
|
||||||
cmd.Process.Release()
|
proc.cmd.Process.Release()
|
||||||
logger.Println("abnormal termination of process :", cmd.Args)
|
|
||||||
}(proc.cmd)
|
if proc.state == protos.ProcessState_Restart {
|
||||||
|
hc.startChildProcess(&shared.StartProcessRequest{
|
||||||
|
Version: proc.version,
|
||||||
|
Name: proc.name,
|
||||||
|
Args: proc.cmd.Args,
|
||||||
|
}, op)
|
||||||
|
}
|
||||||
|
}(proc)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
newprocs = append(newprocs, proc)
|
newprocs = append(newprocs, proc)
|
||||||
|
|||||||
@ -12,7 +12,6 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
@ -165,33 +164,17 @@ func zipLogFiles(storageRoot string, req *shared.UploadRequest, start, except st
|
|||||||
}
|
}
|
||||||
|
|
||||||
func prepareProcessLaunch(storageRoot string, req *shared.StartProcessRequest) *procmeta {
|
func prepareProcessLaunch(storageRoot string, req *shared.StartProcessRequest) *procmeta {
|
||||||
re := regexp.MustCompile(`[^\s"']+|"([^"]*)"|'([^']*)`)
|
if len(req.Args) == 0 {
|
||||||
argsTemp := re.FindAllString(req.Args, -1)
|
|
||||||
var args []string
|
|
||||||
for _, arg := range argsTemp {
|
|
||||||
if strings.HasPrefix(arg, `"`) && len(args) > 0 {
|
|
||||||
lastarg := args[len(args)-1]
|
|
||||||
if strings.HasSuffix(lastarg, "=") {
|
|
||||||
args[len(args)-1] = lastarg + arg
|
|
||||||
} else {
|
|
||||||
args = append(args, arg)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
args = append(args, arg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(args) == 0 {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
verpath := path.Join(storageRoot, req.Name, req.Version)
|
verpath := path.Join(storageRoot, req.Name, req.Version)
|
||||||
fi, err := os.Stat(verpath)
|
fi, err := os.Stat(verpath)
|
||||||
|
|
||||||
if err == nil && fi.IsDir() {
|
if err == nil && fi.IsDir() {
|
||||||
args[0] = "./" + path.Clean(strings.TrimPrefix(args[0], "/"))
|
req.Args[0] = "./" + path.Clean(strings.TrimPrefix(req.Args[0], "/"))
|
||||||
os.Chmod(path.Join(verpath, args[0]), 0777)
|
os.Chmod(path.Join(verpath, req.Args[0]), 0777)
|
||||||
|
|
||||||
cmd := exec.Command(args[0], args[1:]...)
|
cmd := exec.Command(req.Args[0], req.Args[1:]...)
|
||||||
cmd.Dir = verpath
|
cmd.Dir = verpath
|
||||||
stdin, _ := cmd.StdinPipe()
|
stdin, _ := cmd.StdinPipe()
|
||||||
|
|
||||||
@ -462,27 +445,17 @@ func (hc *houstonClient) restartChildProcess(req *shared.RestartProcessRequest,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proc.state = protos.ProcessState_Restart
|
||||||
|
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
||||||
|
|
||||||
if err := proc.cmd.Process.Signal(syscall.SIGTERM); err != nil {
|
if err := proc.cmd.Process.Signal(syscall.SIGTERM); err != nil {
|
||||||
proc.cmd.Process.Signal(os.Kill)
|
proc.cmd.Process.Signal(os.Kill)
|
||||||
}
|
}
|
||||||
proc.state = protos.ProcessState_Stopping
|
|
||||||
proc.cmd.Wait()
|
|
||||||
proc.cmd.Process.Release()
|
|
||||||
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
|
||||||
|
|
||||||
proc.state = protos.ProcessState_Stopped
|
|
||||||
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
|
||||||
|
|
||||||
if err := hc.launch(proc); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -27,7 +27,8 @@ enum ProcessState {
|
|||||||
Stopped = 0;
|
Stopped = 0;
|
||||||
Stopping = 1;
|
Stopping = 1;
|
||||||
Running = 2;
|
Running = 2;
|
||||||
Error = 3;
|
Restart = 3;
|
||||||
|
Error = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ProcessDescription {
|
message ProcessDescription {
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -294,7 +295,7 @@ func (h *houstonHandler) StartProcess(w http.ResponseWriter, r *http.Request) {
|
|||||||
// </form>
|
// </form>
|
||||||
name := r.FormValue("name")
|
name := r.FormValue("name")
|
||||||
version := r.FormValue("version")
|
version := r.FormValue("version")
|
||||||
args := r.FormValue("args")
|
argsline := r.FormValue("args")
|
||||||
traws := r.FormValue("targets")
|
traws := r.FormValue("targets")
|
||||||
|
|
||||||
var targets []string
|
var targets []string
|
||||||
@ -311,6 +312,27 @@ func (h *houstonHandler) StartProcess(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
re := regexp.MustCompile(`[^\s"']+|"([^"]*)"|'([^']*)`)
|
||||||
|
argsTemp := re.FindAllString(argsline, -1)
|
||||||
|
var args []string
|
||||||
|
for _, arg := range argsTemp {
|
||||||
|
if strings.HasPrefix(arg, `"`) && len(args) > 0 {
|
||||||
|
lastarg := args[len(args)-1]
|
||||||
|
if strings.HasSuffix(lastarg, "=") {
|
||||||
|
args[len(args)-1] = lastarg + arg
|
||||||
|
} else {
|
||||||
|
args = append(args, arg)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
args = append(args, arg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(args) == 0 {
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
h.Operation().StartProcess(MakeStartProcessRequest(shared.StartProcessRequest{
|
h.Operation().StartProcess(MakeStartProcessRequest(shared.StartProcessRequest{
|
||||||
Name: name,
|
Name: name,
|
||||||
Version: version,
|
Version: version,
|
||||||
|
|||||||
@ -157,10 +157,10 @@ func (h *houstonHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
var operation string
|
var operation string
|
||||||
if r.Method == "POST" {
|
if r.Method == "POST" {
|
||||||
operation = r.FormValue("operation")
|
operation = r.FormValue("operation")
|
||||||
logger.Println("api called :", userinfo, r.Form)
|
logger.Println("api called :", userinfo["email"], r.Form)
|
||||||
} else {
|
} else {
|
||||||
operation = r.URL.Query().Get("operation")
|
operation = r.URL.Query().Get("operation")
|
||||||
logger.Println("api called :", userinfo, r.URL.Query())
|
logger.Println("api called :", userinfo["email"], r.URL.Query())
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(operation) == 0 {
|
if len(operation) == 0 {
|
||||||
|
|||||||
@ -35,7 +35,7 @@ type WithdrawRequest struct {
|
|||||||
type StartProcessRequest struct {
|
type StartProcessRequest struct {
|
||||||
Name string
|
Name string
|
||||||
Version string
|
Version string
|
||||||
Args string
|
Args []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type StopProcessRequest struct {
|
type StopProcessRequest struct {
|
||||||
|
|||||||
@ -26,7 +26,8 @@ const (
|
|||||||
ProcessState_Stopped ProcessState = 0
|
ProcessState_Stopped ProcessState = 0
|
||||||
ProcessState_Stopping ProcessState = 1
|
ProcessState_Stopping ProcessState = 1
|
||||||
ProcessState_Running ProcessState = 2
|
ProcessState_Running ProcessState = 2
|
||||||
ProcessState_Error ProcessState = 3
|
ProcessState_Restart ProcessState = 3
|
||||||
|
ProcessState_Error ProcessState = 4
|
||||||
)
|
)
|
||||||
|
|
||||||
// Enum value maps for ProcessState.
|
// Enum value maps for ProcessState.
|
||||||
@ -35,13 +36,15 @@ var (
|
|||||||
0: "Stopped",
|
0: "Stopped",
|
||||||
1: "Stopping",
|
1: "Stopping",
|
||||||
2: "Running",
|
2: "Running",
|
||||||
3: "Error",
|
3: "Restart",
|
||||||
|
4: "Error",
|
||||||
}
|
}
|
||||||
ProcessState_value = map[string]int32{
|
ProcessState_value = map[string]int32{
|
||||||
"Stopped": 0,
|
"Stopped": 0,
|
||||||
"Stopping": 1,
|
"Stopping": 1,
|
||||||
"Running": 2,
|
"Running": 2,
|
||||||
"Error": 3,
|
"Restart": 3,
|
||||||
|
"Error": 4,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -422,20 +425,21 @@ var file_protos_operation_proto_rawDesc = []byte{
|
|||||||
0x37, 0x0a, 0x09, 0x41, 0x72, 0x67, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03,
|
0x37, 0x0a, 0x09, 0x41, 0x72, 0x67, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03,
|
||||||
0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14,
|
0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14,
|
||||||
0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76,
|
0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76,
|
||||||
0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x2a, 0x41, 0x0a, 0x0c, 0x50, 0x72, 0x6f, 0x63,
|
0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x2a, 0x4e, 0x0a, 0x0c, 0x50, 0x72, 0x6f, 0x63,
|
||||||
0x65, 0x73, 0x73, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x53, 0x74, 0x6f, 0x70,
|
0x65, 0x73, 0x73, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x53, 0x74, 0x6f, 0x70,
|
||||||
0x70, 0x65, 0x64, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x53, 0x74, 0x6f, 0x70, 0x70, 0x69, 0x6e,
|
0x70, 0x65, 0x64, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x53, 0x74, 0x6f, 0x70, 0x70, 0x69, 0x6e,
|
||||||
0x67, 0x10, 0x01, 0x12, 0x0b, 0x0a, 0x07, 0x52, 0x75, 0x6e, 0x6e, 0x69, 0x6e, 0x67, 0x10, 0x02,
|
0x67, 0x10, 0x01, 0x12, 0x0b, 0x0a, 0x07, 0x52, 0x75, 0x6e, 0x6e, 0x69, 0x6e, 0x67, 0x10, 0x02,
|
||||||
0x12, 0x09, 0x0a, 0x05, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x03, 0x32, 0x78, 0x0a, 0x09, 0x4f,
|
0x12, 0x0b, 0x0a, 0x07, 0x52, 0x65, 0x73, 0x74, 0x61, 0x72, 0x74, 0x10, 0x03, 0x12, 0x09, 0x0a,
|
||||||
0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x3e, 0x0a, 0x05, 0x51, 0x75, 0x65, 0x72,
|
0x05, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x04, 0x32, 0x78, 0x0a, 0x09, 0x4f, 0x70, 0x65, 0x72,
|
||||||
0x79, 0x12, 0x16, 0x2e, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x51, 0x75, 0x65,
|
0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x3e, 0x0a, 0x05, 0x51, 0x75, 0x65, 0x72, 0x79, 0x12, 0x16,
|
||||||
0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x4f, 0x70, 0x65, 0x72,
|
0x2e, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52,
|
||||||
0x61, 0x74, 0x69, 0x6f, 0x6e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
|
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69,
|
||||||
0x73, 0x65, 0x22, 0x00, 0x28, 0x01, 0x30, 0x01, 0x12, 0x2b, 0x0a, 0x07, 0x52, 0x65, 0x66, 0x72,
|
0x6f, 0x6e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22,
|
||||||
0x65, 0x73, 0x68, 0x12, 0x16, 0x2e, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x51,
|
0x00, 0x28, 0x01, 0x30, 0x01, 0x12, 0x2b, 0x0a, 0x07, 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68,
|
||||||
0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x06, 0x2e, 0x45, 0x6d,
|
0x12, 0x16, 0x2e, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x51, 0x75, 0x65, 0x72,
|
||||||
0x70, 0x74, 0x79, 0x22, 0x00, 0x42, 0x0f, 0x5a, 0x0d, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f,
|
0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x06, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79,
|
||||||
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
0x22, 0x00, 0x42, 0x0f, 0x5a, 0x0d, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x70, 0x72, 0x6f,
|
||||||
|
0x74, 0x6f, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
Reference in New Issue
Block a user