Skip to content

Commit e6c755c

Browse files
akantoKrisztian Horvath
authored and
Krisztian Horvath
committed
CLOUD-67234 Sysv scripts starts the salt minion twice
1 parent 38a1162 commit e6c755c

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BINARY=salt-bootstrap
22

3-
VERSION=0.9.2
3+
VERSION=0.10.0
44
BUILD_TIME=$(shell date +%FT%T)
55
LDFLAGS=-ldflags "-X github.com/hortonworks/salt-bootstrap/saltboot.Version=${VERSION} -X github.com/hortonworks/salt-bootstrap/saltboot.BuildTime=${BUILD_TIME}"
66
GOFILES = $(shell find . -type f -name '*.go')

saltboot/salt.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func distributeActionImpl(distributePayload func(clients []string, payloads []Pa
8787
}
8888

8989
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")
9191

9292
decoder := json.NewDecoder(req.Body)
9393
var saltMinion SaltMinion
@@ -97,6 +97,7 @@ func SaltMinionRunRequestHandler(w http.ResponseWriter, req *http.Request) {
9797
model.Response{Status: err.Error()}.WriteBadRequestHttp(w)
9898
return
9999
}
100+
log.Printf("[SaltMinionRunRequestHandler] received json: %s", saltMinion.AsByteArray())
100101

101102
grainConfig := GrainConfig{Roles: saltMinion.Roles, HostGroup: saltMinion.HostGroup}
102103
grainYaml, err := yaml.Marshal(grainConfig)
@@ -130,12 +131,24 @@ func SaltMinionRunRequestHandler(w http.ResponseWriter, req *http.Request) {
130131
resp.WriteHttp(w)
131132
return
132133
}
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+
}
133145
resp, _ = LaunchService("salt-minion")
146+
log.Printf("[SaltMinionRunRequestHandler] execute salt-minion run request")
134147
resp.WriteHttp(w)
135148
}
136149

137150
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")
139152

140153
decoder := json.NewDecoder(req.Body)
141154
var saltMinion SaltMinion
@@ -145,6 +158,7 @@ func SaltMinionStopRequestHandler(w http.ResponseWriter, req *http.Request) {
145158
model.Response{Status: err.Error()}.WriteBadRequestHttp(w)
146159
return
147160
}
161+
log.Printf("[SaltMinionRunRequestHandler] received json: %s", saltMinion.AsByteArray())
148162

149163
resp, _ := StopService("salt-minion")
150164
resp.WriteHttp(w)

saltboot/salt_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func TestSaltMinionRunRequestHandler(t *testing.T) {
102102
t.Errorf("couldn't unmarshall grain yaml: %s", err)
103103
}
104104

105-
if os.Getenv(EXECUTED_COMMANDS) != "/sbin/service salt-minion start:/sbin/chkconfig salt-minion on:" {
105+
if os.Getenv(EXECUTED_COMMANDS) != "ps aux:/sbin/service salt-minion start:/sbin/chkconfig salt-minion on:" {
106106
t.Errorf("wrong commands were executed: %s", os.Getenv(EXECUTED_COMMANDS))
107107
}
108108
}

0 commit comments

Comments
 (0)