"log"
"os"
"os/exec"
+ "strconv"
+ "strings"
)
// Service for service that execute by self
}
log.Println("Just ran subprocess ", pid)
- p.registerService()
-
executeCh := make(chan error)
go func() {
p.notifyServiceStatus(status)
- DeleteServiceMap(p.serviceID)
- p.removeService()
-
return nil
}
func (p Service) setService() (cmd *exec.Cmd, pid int, err error) {
- binary, err := exec.LookPath(p.serviceName)
- if err != nil {
- return
- }
-
- cmd, _ = GetCmd(p.serviceID)
-
if len(p.paramStr) == 0 {
- cmd = exec.Command(binary)
+ cmd = exec.Command(p.serviceName)
} else {
- cmd = exec.Command(binary, p.paramStr...)
- }
-
- setErr := SetCmd(p.serviceID, cmd)
- if setErr != nil {
- log.Println(setErr.Error())
+ cmd = exec.Command(p.serviceName, p.paramStr...)
}
cmd.Stdout = os.Stdout
err = cmd.Start()
if err != nil {
+ log.Println(err.Error())
return
}
return
}
-func (p Service) registerService() {
- registerCh := make(chan error)
-
- appName, err := GetAppName(p.serviceID)
- if err != nil {
- log.Println("[Fail] GetAppName is Failed")
- }
-
- go RegisterService(appName, p.serviceID, p.serviceName, ConstServiceStatusStarted, registerCh)
- if err := <-registerCh; err == nil {
- log.Println("[Success] Service Register is Success")
- } else {
- log.Println("[Fail] " + err.Error())
- }
-}
-
-func (p Service) removeService() {
- err := RemoveService(p.serviceID)
- if err == nil {
- log.Println("[Success] Service Unregister is Success")
- } else {
- log.Println("[Fail] " + err.Error())
- }
-}
-
func (p Service) waitService(executeCh <-chan error) (status string) {
e := <-executeCh
- // ctlChan, _ := GetCtlChan(p.serviceID)
- // ctlChan <- true
-
status = ConstServiceStatusFinished
if e != nil {
}
func (p Service) notifyServiceStatus(status string) (err error) {
- var statusNotificationRequest map[string]interface{}
-
- statusNotificationRequest = make(map[string]interface{})
+ statusNotificationRequest := make(map[string]interface{})
statusNotificationRequest["ServiceID"] = p.serviceID
statusNotificationRequest["Status"] = status
reqbytes, _ := json.Marshal(statusNotificationRequest)
- // @TODO TargetURL needs to be declared
- // err =
- SendPostJSONMsg(p.notificationTargetURL, reqbytes)
- // if err != nil {
- // log.Println(err.Error())
- // }
+
+ if strings.Compare(p.notificationTargetURL, ConstLocalTarget) == 0 {
+
+ } else {
+ targetURL := p.notificationTargetURL + ConstServiceStatusNotiURI + strconv.FormatUint(p.serviceID, 10)
+ _, err = sendPostJSONMsg(targetURL, reqbytes)
+ if err != nil {
+ log.Println(err.Error())
+ }
+ }
return
}