@@ -87,7 +87,7 @@ func distributeActionImpl(distributePayload func(clients []string, payloads []Pa
87
87
}
88
88
89
89
func SaltMinionRunRequestHandler (w http.ResponseWriter , req * http.Request ) {
90
- log .Printf ("[SaltMinionRunRequestHandler] execute salt run request" )
90
+ log .Printf ("[SaltMinionRunRequestHandler] execute salt-minion run request" )
91
91
92
92
decoder := json .NewDecoder (req .Body )
93
93
var saltMinion SaltMinion
@@ -97,6 +97,7 @@ func SaltMinionRunRequestHandler(w http.ResponseWriter, req *http.Request) {
97
97
model.Response {Status : err .Error ()}.WriteBadRequestHttp (w )
98
98
return
99
99
}
100
+ log .Printf ("[SaltMinionRunRequestHandler] received json: %s" , saltMinion .AsByteArray ())
100
101
101
102
grainConfig := GrainConfig {Roles : saltMinion .Roles , HostGroup : saltMinion .HostGroup }
102
103
grainYaml , err := yaml .Marshal (grainConfig )
@@ -130,12 +131,24 @@ func SaltMinionRunRequestHandler(w http.ResponseWriter, req *http.Request) {
130
131
resp .WriteHttp (w )
131
132
return
132
133
}
134
+ psOutput , err := ExecCmd ("ps" , "aux" )
135
+ alreadyRunning := strings .Contains (psOutput , "salt-minion" )
136
+
137
+ if alreadyRunning {
138
+ log .Printf ("[SaltMinionRunRequestHandler] salt-minion is already running %s" , psOutput )
139
+ resp = model.Response {StatusCode : http .StatusOK , Status : "salt-minion already running" }
140
+ resp .WriteHttp (w )
141
+ return
142
+ } else {
143
+ log .Printf ("[SaltMinionRunRequestHandler] salt-minion is not running and will be started" )
144
+ }
133
145
resp , _ = LaunchService ("salt-minion" )
146
+ log .Printf ("[SaltMinionRunRequestHandler] execute salt-minion run request" )
134
147
resp .WriteHttp (w )
135
148
}
136
149
137
150
func SaltMinionStopRequestHandler (w http.ResponseWriter , req * http.Request ) {
138
- log .Printf ("[SaltMinionStopRequestHandler] execute salt minion stop request" )
151
+ log .Printf ("[SaltMinionStopRequestHandler] execute salt- minion stop request" )
139
152
140
153
decoder := json .NewDecoder (req .Body )
141
154
var saltMinion SaltMinion
@@ -145,6 +158,7 @@ func SaltMinionStopRequestHandler(w http.ResponseWriter, req *http.Request) {
145
158
model.Response {Status : err .Error ()}.WriteBadRequestHttp (w )
146
159
return
147
160
}
161
+ log .Printf ("[SaltMinionRunRequestHandler] received json: %s" , saltMinion .AsByteArray ())
148
162
149
163
resp , _ := StopService ("salt-minion" )
150
164
resp .WriteHttp (w )
0 commit comments