-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1854 from budde377/feature-stop-karma-server
Add possibility to stop a karma server
- Loading branch information
Showing
16 changed files
with
307 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
var fs = require('fs') | ||
|
||
var Server = require('./server') | ||
var configurationFile = process.argv[2] | ||
var fileContents = fs.readFileSync(configurationFile, 'utf-8') | ||
fs.unlink(configurationFile, function () {}) | ||
var data = JSON.parse(fileContents) | ||
var server = new Server(data) | ||
server.start(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Stopper middleware is responsible for communicating with `karma stop`. | ||
*/ | ||
|
||
var log = require('../logger').create('middleware:stopper') | ||
|
||
var createStopperMiddleware = function (urlRoot) { | ||
return function (request, response, next) { | ||
if (request.url !== urlRoot + 'stop') return next() | ||
response.writeHead(200) | ||
log.info('Stopping server') | ||
response.end('OK') | ||
process.kill(process.pid, 'SIGINT') | ||
} | ||
} | ||
|
||
createStopperMiddleware.$inject = ['config.urlRoot'] | ||
exports.create = createStopperMiddleware |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
var http = require('http') | ||
|
||
var cfg = require('./config') | ||
var logger = require('./logger') | ||
var helper = require('./helper') | ||
|
||
exports.stop = function (config, done) { | ||
config = config || {} | ||
logger.setupFromConfig(config) | ||
done = helper.isFunction(done) ? done : process.exit | ||
var log = logger.create('stopper') | ||
config = cfg.parseConfig(config.configFile, config) | ||
|
||
var options = { | ||
hostname: config.hostname, | ||
path: config.urlRoot + 'stop', | ||
port: config.port, | ||
method: 'GET' | ||
} | ||
|
||
var request = http.request(options) | ||
|
||
request.on('response', function (response) { | ||
if (response.statusCode !== 200) { | ||
log.error('Server returned status code: ' + response.statusCode) | ||
done(1) | ||
return | ||
} | ||
|
||
log.info('Server stopped.') | ||
done(0) | ||
}) | ||
|
||
request.on('error', function (e) { | ||
if (e.code === 'ECONNREFUSED') { | ||
log.error('There is no server listening on port %d', options.port) | ||
done(1, e.code) | ||
} else { | ||
throw e | ||
} | ||
}) | ||
request.end() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.