Skip to content

Commit 99b2780

Browse files
Krisztian Horvathakanto
Krisztian Horvath
authored andcommitted
CLOUD-67912 check salt api and master as well when lauching the services
1 parent 1ac902d commit 99b2780

File tree

3 files changed

+33
-16
lines changed

3 files changed

+33
-16
lines changed

saltboot/salt.go

+19-15
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,9 @@ func SaltMinionRunRequestHandler(w http.ResponseWriter, req *http.Request) {
136136
resp.WriteHttp(w)
137137
return
138138
}
139-
psOutput, err := ExecCmd("ps", "aux")
140-
alreadyRunning := strings.Contains(psOutput, "salt-minion")
141139

142-
if alreadyRunning {
143-
log.Printf("[SaltMinionRunRequestHandler] salt-minion is already running %s", psOutput)
144-
resp = model.Response{StatusCode: http.StatusOK, Status: "salt-minion already running"}
145-
resp.WriteHttp(w)
146-
return
147-
} else {
148-
log.Printf("[SaltMinionRunRequestHandler] salt-minion is not running and will be started")
149-
}
150-
resp, _ = LaunchService("salt-minion")
151140
log.Printf("[SaltMinionRunRequestHandler] execute salt-minion run request")
141+
resp, _ = LaunchService("salt-minion")
152142
resp.WriteHttp(w)
153143
}
154144

@@ -186,21 +176,35 @@ func SaltServerRunRequestHandler(w http.ResponseWriter, req *http.Request) {
186176
log.Printf("[ERROR] while hostfile update: %s", err)
187177
}
188178

179+
var responses []model.Response
180+
189181
resp, err := CreateUser(saltMaster)
190-
resp.WriteHttp(w)
191182
if err != nil {
183+
resp.WriteHttp(w)
192184
return
193185
}
186+
responses = append(responses, resp)
194187

195188
resp, err = LaunchService("salt-master")
196-
resp.WriteHttp(w)
189+
if err != nil {
190+
resp.WriteHttp(w)
191+
return
192+
}
193+
responses = append(responses, resp)
197194

195+
resp, err = LaunchService("salt-api")
198196
if err != nil {
197+
resp.WriteHttp(w)
199198
return
200199
}
200+
responses = append(responses, resp)
201201

202-
resp, _ = LaunchService("salt-api")
203-
resp.WriteHttp(w)
202+
var message string
203+
for _, r := range responses {
204+
message += r.Status + "; "
205+
}
206+
finalResponse := model.Response{Status: message, StatusCode: http.StatusOK}
207+
finalResponse.WriteHttp(w)
204208
}
205209

206210
func SaltServerStopRequestHandler(w http.ResponseWriter, req *http.Request) {

saltboot/service.go

+13
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,22 @@ import (
44
"net/http"
55

66
"github.com/sequenceiq/salt-bootstrap/saltboot/model"
7+
"log"
8+
"strings"
79
)
810

911
func LaunchService(service string) (resp model.Response, err error) {
12+
log.Printf("[LaunchService] check if service: %s is running", service)
13+
psOutput, _ := ExecCmd("ps", "aux")
14+
alreadyRunning := strings.Contains(psOutput, service)
15+
16+
if alreadyRunning {
17+
log.Printf("[LaunchService] %s is already running %s", service, psOutput)
18+
return model.Response{StatusCode: http.StatusOK, Status: service + " is already running"}, nil
19+
} else {
20+
log.Printf("[LaunchService] %s is not running and will be started", service)
21+
}
22+
1023
return SetServiceState(service, true)
1124
}
1225

saltboot/user.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func randStringRunes(n int) string {
2727
func CreateUser(saltMaster SaltMaster) (resp model.Response, err error) {
2828
log.Printf("[CreateUser] execute salt run request")
2929

30-
result := "OK"
30+
result := "Create user: OK"
3131

3232
//saltUser, _ := user.Lookup(SALT_USER) //requires cgo
3333
_, err = ExecCmd("grep", SALT_USER, "/etc/passwd")

0 commit comments

Comments
 (0)