Skip to content

Commit 931e913

Browse files
authored
Merge pull request #199 from Dahlgren/bugfix/delay-headless-clients-startup
Delay headless clients startup until server is started
2 parents cf5bfd4 + 30e7a8c commit 931e913

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

lib/logs.js

+4-12
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,6 @@ Logs.prototype.readLogFile = function (filename, callback) {
135135
fs.readFile(filename, callback)
136136
}
137137

138-
Logs.prototype.logServerProcesses = function (prefix, serverProcess, headlessClientProcesses) {
139-
var self = this
140-
this.logServerProcess(serverProcess, prefix, 'server')
141-
headlessClientProcesses.forEach(function (headlessClientProcess, idx) {
142-
self.logServerProcess(headlessClientProcess, prefix, 'hc_' + (idx + 1))
143-
})
144-
145-
if (this.config.type === 'linux') {
146-
this.cleanupOldLogFiles()
147-
}
148-
}
149-
150138
Logs.prototype.logServerProcess = function (serverProcess, prefix, suffix) {
151139
if (this.config.type !== 'linux') {
152140
return
@@ -183,6 +171,10 @@ Logs.prototype.logServerProcess = function (serverProcess, prefix, suffix) {
183171
}
184172

185173
Logs.prototype.cleanupOldLogFiles = function () {
174+
if (this.config.type !== 'linux') {
175+
return
176+
}
177+
186178
var self = this
187179

188180
self.logFiles(function (err, files) {

lib/server.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ Server.prototype.queryStatus = function () {
8989
self.state = null
9090
} else {
9191
self.state = state
92+
self.startHeadlessClientsIfNeeded()
9293
}
9394

9495
self.emit('state')
@@ -178,19 +179,25 @@ Server.prototype.start = function () {
178179

179180
this.pid = instance.pid
180181
this.instance = instance
182+
this.headlessClientInstances = []
181183
this.queryStatusInterval = setInterval(function () {
182184
self.queryStatus()
183185
}, queryInterval)
184186

185-
this.startHeadlessClients()
186-
187-
this.logs.logServerProcesses(this.id, this.instance, this.headlessClientInstances)
187+
this.logs.logServerProcess(this.instance, this.id, 'server')
188+
this.logs.cleanupOldLogFiles()
188189

189190
this.emit('state')
190191

191192
return this
192193
}
193194

195+
Server.prototype.startHeadlessClientsIfNeeded = function () {
196+
if (this.number_of_headless_clients > 0 && this.headlessClientInstances.length === 0) {
197+
this.startHeadlessClients()
198+
}
199+
}
200+
194201
Server.prototype.startHeadlessClients = function () {
195202
var parameters = this.getParameters()
196203
var self = this
@@ -207,6 +214,7 @@ Server.prototype.startHeadlessClients = function () {
207214
port: self.port
208215
})
209216
var headlessInstance = headless.start()
217+
self.logs.logServerProcess(headlessInstance, self.id, 'hc_' + (i + 1))
210218
return headlessInstance
211219
})
212220

@@ -245,6 +253,7 @@ Server.prototype.stopHeadlessClients = function () {
245253
this.headlessClientInstances.map(function (headlessClientInstance) {
246254
headlessClientInstance.kill()
247255
})
256+
this.headlessClientInstances = []
248257
}
249258

250259
Server.prototype.toJSON = function () {

0 commit comments

Comments
 (0)