/
execution_engine.go
59 lines (46 loc) · 1.45 KB
/
execution_engine.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package agent
import (
"fmt"
"os/exec"
)
type ExecuteApp struct {
}
func runExec(service string, operation string) error {
// Preparing the call to the executor app.
cmd := exec.Command(Configuration.ExecutorPath, service, operation)
cmd.Dir = Configuration.ExecutorPath
_, err := cmd.CombinedOutput()
if err != nil {
LoggingClient.Error(fmt.Sprintf("an error occurred in calling executor on service %s where requested operation was %s: %v ", service, operation, err.Error()))
} else {
LoggingClient.Info("invocation of executor succeeded")
}
return err
}
func (ec *ExecuteApp) Start(service string) error {
err := runExec(service, "start")
if err != nil {
LoggingClient.Error(fmt.Sprintf("error in starting service %s: %v", service, err.Error()))
} else {
LoggingClient.Debug(fmt.Sprintf("starting service %s succeeded", service))
}
return err
}
func (ec *ExecuteApp) Stop(service string) error {
err := runExec(service, "stop")
if err != nil {
LoggingClient.Error(fmt.Sprintf("error in stopping service %s: %v", service, err.Error()))
} else {
LoggingClient.Debug(fmt.Sprintf("stopping service %s succeeded", service))
}
return err
}
func (ec *ExecuteApp) Restart(service string) error {
err := runExec(service, "restart")
if err != nil {
LoggingClient.Error(fmt.Sprintf("error in restarting service %s: %v", service, err.Error()))
} else {
LoggingClient.Debug(fmt.Sprintf("restarting service %s succeeded", service))
}
return err
}