From 3cff6418ad5b94122627ce75a1bd4ae040afd872 Mon Sep 17 00:00:00 2001 From: "jw_wonny.cha" Date: Tue, 26 Mar 2019 14:34:26 +0900 Subject: [PATCH] Add Delete implements in service_agent --- src/servicemgr/service_agent.go | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/src/servicemgr/service_agent.go b/src/servicemgr/service_agent.go index 9fd95df..d4a9966 100644 --- a/src/servicemgr/service_agent.go +++ b/src/servicemgr/service_agent.go @@ -2,9 +2,9 @@ package servicemgr import ( "encoding/json" + "fmt" "log" "os/exec" - "strings" "time" ) @@ -14,8 +14,8 @@ func makeTime() string { } // Create function -func Create(serviceParam ServiceParam) []byte { - instanceCount := serviceParam.Count +func Create(serviceParam map[string]interface{}) []byte { + instanceCount := int(serviceParam["Count"].(float64)) ret := ServiceCreationResponse{} ret.Status = ConstServiceFound @@ -24,7 +24,7 @@ func Create(serviceParam ServiceParam) []byte { for index := 0; index < instanceCount; index++ { var cmd *exec.Cmd - id, _, _ := CreateServiceMap(cmd, serviceParam.ServiceBinPath+serviceParam.ServiceName, serviceParam.AppName) + id, _, _ := CreateServiceMap(cmd, serviceParam["ServiceBinPath"].(string)+serviceParam["ServiceName"].(string), serviceParam["AppName"].(string)) serviceInfo := ServiceCreationResponseItem{id, makeTime()} ret.ServiceList[index] = serviceInfo @@ -35,22 +35,41 @@ func Create(serviceParam ServiceParam) []byte { } // Run is for executing service -func Run(distService DistService, serviceID uint64) { +func Run(distService map[string]interface{}, serviceID uint64) { serviceName, err := GetServiceName(serviceID) if err != nil { log.Println(err.Error()) return } - var args []string - for _, userParam := range distService.UserArgs { - args = append(args, userParam) + userArgs := distService["UserArgs"].([]interface{}) + args := make([]string, len(userArgs)) + + for _, userParam := range userArgs { + args = append(args, fmt.Sprint(userParam)) } args = append(args, "--remote") - notificationTargetURL := strings.Join(distService.SystemArgs, ":") + notificationTargetURL := distService["NotificationTargetURL"].(string) service := Service{serviceID, serviceName, args, notificationTargetURL} service.execute() } + +// Delete is for removing service +func Delete(serviceID uint64) (err error) { + cmd, err := GetCmd(serviceID) + if err != nil { + return + } + + if cmd.ProcessState.Exited() == false { + err = cmd.Process.Kill() + if err != nil { + log.Println(err.Error()) + } + } + + return +} -- 2.7.4