autorun 추가

This commit is contained in:
2024-06-05 13:40:10 +09:00
parent 62494fb052
commit bad563dce7
3 changed files with 99 additions and 17 deletions

View File

@ -23,6 +23,7 @@ import (
"unsafe"
"repositories.action2quare.com/ayo/gocommon"
"repositories.action2quare.com/ayo/gocommon/flagx"
"repositories.action2quare.com/ayo/gocommon/logger"
"repositories.action2quare.com/ayo/houston/shared"
"repositories.action2quare.com/ayo/houston/shared/protos"
@ -31,14 +32,23 @@ import (
"google.golang.org/grpc/credentials/insecure"
)
type clientConfig struct {
GrpcAddress string `json:"grpc_server_address"`
HttpAddress string `json:"http_server_address"`
StorageRoot string `json:"storage_path"`
MetricNamespace string `json:"metric_namespace"`
ConstLabels map[string]string `json:"metric_const_labels"`
type runcommand struct {
Exec string `json:"exec"`
Args []string `json:"args"`
Version string `json:"version"`
}
type clientConfig struct {
GrpcAddress string `json:"grpc_server_address"`
HttpAddress string `json:"http_server_address"`
StorageRoot string `json:"storage_path"`
MetricNamespace string `json:"metric_namespace"`
ConstLabels map[string]string `json:"metric_const_labels"`
Autorun map[string]runcommand `json:"autorun"`
}
var autorun = flagx.String("autorun", "", "")
func loadClientConfig() (clientConfig, error) {
configFile, err := os.Open("config.json")
if err != nil {
@ -295,6 +305,7 @@ func NewClient(standalone bool) (HoustonClient, error) {
operationChan := make(chan *protos.OperationQueryResponse, 10)
hc.wg.Add(1)
// autorun 처리
go func() {
defer hc.wg.Done()
@ -316,6 +327,32 @@ func NewClient(standalone bool) (HoustonClient, error) {
case newClient := <-hc.clientChan:
op = protos.NewOperationClient(newClient)
if autorun != nil && len(*autorun) > 0 {
hascount := strings.Split(*autorun, "/")
var service string
count := 1
if len(hascount) > 1 {
service = hascount[0]
count, _ = strconv.Atoi(hascount[1])
} else {
service = *autorun
}
if cmd, ok := hc.config.Autorun[service]; ok {
// service 서비스
for i := 0; i < count; i++ {
sr := shared.StartProcessRequest{
Name: service,
Version: cmd.Version,
Args: append([]string{cmd.Exec}, cmd.Args...),
}
if err := hc.startChildProcess(&sr, op); err != nil {
logger.Println("startChildProcess failed by autorun :", err)
}
}
}
}
case exited := <-exitChan:
var newprocs []*procmeta