Merge branch 'master' into kd-live
This commit is contained in:
@ -452,52 +452,35 @@ func (hc *houstonClient) stopChildProcess(req *shared.StopProcessRequest, op pro
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (hc *houstonClient) restartChildProcess(req *shared.RestartProcessRequest, op protos.OperationClient) error {
|
func (hc *houstonClient) restartChildProcess(req *shared.RestartProcessRequest, op protos.OperationClient) error {
|
||||||
if req.Version == "latest" {
|
for _, proc := range hc.childProcs {
|
||||||
// 최신 버전을 찾음
|
if proc.cmd.Process.Pid == int(req.Pid) {
|
||||||
latest, err := shared.FindLastestVersion(hc.config.StorageRoot, req.Name)
|
if len(req.Config) > 0 {
|
||||||
if err != nil {
|
// config.json를 먼저 다운로드 시도
|
||||||
|
root := proc.cmd.Path
|
||||||
|
if _, err := download(root, hc.makeDownloadUrl(req.Config), ""); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
req.Version = latest
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var restarts []*procmeta
|
|
||||||
for _, proc := range hc.childProcs {
|
|
||||||
if proc.name == req.Name {
|
|
||||||
if len(req.Version) == 0 {
|
|
||||||
restarts = append(restarts, proc)
|
|
||||||
} else if req.Version == proc.version {
|
|
||||||
restarts = append(restarts, proc)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(restarts) == 0 {
|
|
||||||
return errNoRunningProcess
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, proc := range restarts {
|
|
||||||
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.state = protos.ProcessState_Stopping
|
||||||
}
|
|
||||||
|
|
||||||
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
|
||||||
|
|
||||||
for _, proc := range restarts {
|
|
||||||
proc.cmd.Wait()
|
proc.cmd.Wait()
|
||||||
proc.cmd.Process.Release()
|
proc.cmd.Process.Release()
|
||||||
proc.state = protos.ProcessState_Stopped
|
|
||||||
}
|
|
||||||
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
||||||
|
|
||||||
for _, proc := range restarts {
|
proc.state = protos.ProcessState_Stopped
|
||||||
|
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
||||||
|
|
||||||
if err := hc.launch(proc); err != nil {
|
if err := hc.launch(proc); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@ -2,7 +2,6 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
@ -10,6 +9,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||||
@ -140,6 +140,43 @@ func (h *houstonHandler) DeleteDeploySource(w http.ResponseWriter, r *http.Reque
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *houstonHandler) findLastestConfigFile(name string) (string, error) {
|
||||||
|
logger.Println("findLastestConfigFile :", name)
|
||||||
|
configFiles, err := os.ReadDir(path.Join(h.deployPath, name, "config"))
|
||||||
|
if err != nil {
|
||||||
|
logger.Println("findLastestConfigFile failed :", err)
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
var cf fs.FileInfo
|
||||||
|
for _, file := range configFiles {
|
||||||
|
if file.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(file.Name(), "config.") {
|
||||||
|
test, err := file.Info()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
if cf == nil {
|
||||||
|
cf = test
|
||||||
|
} else if test.ModTime().After(cf.ModTime()) {
|
||||||
|
cf = test
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if cf != nil {
|
||||||
|
logger.Println("findLastestConfigFile cf found :", cf.Name())
|
||||||
|
return path.Join(sub_folder_name_deploys, name, "config", cf.Name()), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Println("findLastestConfigFile cf NOT found")
|
||||||
|
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
func (h *houstonHandler) Deploy(w http.ResponseWriter, r *http.Request) {
|
func (h *houstonHandler) Deploy(w http.ResponseWriter, r *http.Request) {
|
||||||
// <form action="/houston" method="post" enctype="multipart/form-data">
|
// <form action="/houston" method="post" enctype="multipart/form-data">
|
||||||
// <input type="text" name="name">
|
// <input type="text" name="name">
|
||||||
@ -191,9 +228,11 @@ func (h *houstonHandler) Deploy(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
configPath := ""
|
configPath, err := h.findLastestConfigFile(name)
|
||||||
if _, err := os.Stat(path.Join(h.deployPath, name, "config", "config.json")); err == nil || errors.Is(err, fs.ErrExist) {
|
if err != nil {
|
||||||
configPath = path.Join(sub_folder_name_deploys, name, "config", "config.json")
|
logger.Println(err)
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
h.Operation().Deploy(MakeDeployRequest(
|
h.Operation().Deploy(MakeDeployRequest(
|
||||||
@ -310,6 +349,51 @@ func (h *houstonHandler) StopProcess(w http.ResponseWriter, r *http.Request) {
|
|||||||
}, targets))
|
}, targets))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *houstonHandler) RestartProcess(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// <form action="/houston" method="post" enctype="multipart/form-data">
|
||||||
|
// <input type="text" name="name">
|
||||||
|
// <input type="text" name="target">
|
||||||
|
// <input type="text" name="pid">
|
||||||
|
// <input type="text" name="config">
|
||||||
|
// </form>
|
||||||
|
pidstr := r.FormValue("pid")
|
||||||
|
target := r.FormValue("target")
|
||||||
|
name := r.FormValue("name")
|
||||||
|
if len(target) == 0 || len(pidstr) == 0 || len(name) == 0 {
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
deployConfig := false
|
||||||
|
configstr := r.FormValue("config")
|
||||||
|
if len(configstr) > 0 {
|
||||||
|
deployConfig, _ = strconv.ParseBool(configstr)
|
||||||
|
}
|
||||||
|
|
||||||
|
pid, err := strconv.ParseInt(pidstr, 10, 0)
|
||||||
|
if err != nil {
|
||||||
|
logger.Println(err)
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var configPath string
|
||||||
|
if deployConfig {
|
||||||
|
configPath, err = h.findLastestConfigFile(name)
|
||||||
|
if err != nil {
|
||||||
|
logger.Println(err)
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
h.Operation().RestartProcess(MakeRestartRequest(shared.RestartProcessRequest{
|
||||||
|
Name: name,
|
||||||
|
Pid: int32(pid),
|
||||||
|
Config: configPath,
|
||||||
|
}, []string{target}))
|
||||||
|
}
|
||||||
|
|
||||||
func (h *houstonHandler) UploadLogs(w http.ResponseWriter, r *http.Request) {
|
func (h *houstonHandler) UploadLogs(w http.ResponseWriter, r *http.Request) {
|
||||||
// <form action="/houston" method="post" enctype="multipart/form-data">
|
// <form action="/houston" method="post" enctype="multipart/form-data">
|
||||||
// <input type="text" name="name">
|
// <input type="text" name="name">
|
||||||
|
|||||||
@ -328,27 +328,19 @@ func (os *operationServer) RestartProcess(d RestartProcessRequest) {
|
|||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
|
|
||||||
if len(d.hostnames) > 0 {
|
if len(d.hostnames) != 1 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// hostname만 재시작
|
// hostname만 재시작
|
||||||
var final []*hostWithChan
|
|
||||||
conv := make(map[string]bool)
|
|
||||||
for _, hn := range d.hostnames {
|
|
||||||
conv[hn] = true
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, t := range targets {
|
|
||||||
if _, ok := conv[t.Hostname]; ok {
|
|
||||||
final = append(final, t)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
targets = final
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, t := range targets {
|
for _, t := range targets {
|
||||||
|
if t.Hostname == d.hostnames[0] {
|
||||||
t.opChan <- &opdef{
|
t.opChan <- &opdef{
|
||||||
operation: shared.Restart,
|
operation: shared.Restart,
|
||||||
args: d,
|
args: d,
|
||||||
}
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -46,7 +46,8 @@ type StopProcessRequest struct {
|
|||||||
|
|
||||||
type RestartProcessRequest struct {
|
type RestartProcessRequest struct {
|
||||||
Name string
|
Name string
|
||||||
Version string
|
Pid int32
|
||||||
|
Config string
|
||||||
}
|
}
|
||||||
|
|
||||||
type UploadRequest struct {
|
type UploadRequest struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user