shutdown.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const http = require("http");
  4. const minimist = require("minimist");
  5. const cli_1 = require("../cli");
  6. const Opt = require("./");
  7. const opts_1 = require("./opts");
  8. let logger = new cli_1.Logger('shutdown');
  9. let prog = new cli_1.Program()
  10. .command('shutdown', 'shut down the selenium server')
  11. .action(shutdown)
  12. .addOption(opts_1.Opts[Opt.SELENIUM_PORT])
  13. .addOption(opts_1.Opts[Opt.ALREADY_OFF_ERROR]);
  14. exports.program = prog;
  15. // stand alone runner
  16. let argv = minimist(process.argv.slice(2), prog.getMinimistOptions());
  17. if (argv._[0] === 'shutdown-run') {
  18. prog.run(JSON.parse(JSON.stringify(argv)));
  19. }
  20. else if (argv._[0] === 'shutdown-help') {
  21. prog.printHelp();
  22. }
  23. /**
  24. * Parses the options and starts the selenium standalone server.
  25. * @param options
  26. */
  27. function shutdown(options) {
  28. logger.info('Attempting to shut down selenium nicely');
  29. http.get('http://localhost:' + options[Opt.SELENIUM_PORT].getString() +
  30. '/selenium-server/driver/?cmd=shutDownSeleniumServer')
  31. .on('error', (e) => {
  32. if ((e.code == 'ECONNREFUSED') && (e.syscall == 'connect')) {
  33. if (!options[Opt.ALREADY_OFF_ERROR].getBoolean()) {
  34. logger.warn('Server does not appear to be on');
  35. }
  36. else {
  37. logger.error('Server unreachable, probably not running');
  38. throw e;
  39. }
  40. }
  41. else {
  42. throw e;
  43. }
  44. });
  45. }
  46. //# sourceMappingURL=shutdown.js.map