diff --git a/lib/cmds/opts.ts b/lib/cmds/opts.ts index 8f3c328b..64aa594d 100644 --- a/lib/cmds/opts.ts +++ b/lib/cmds/opts.ts @@ -36,6 +36,7 @@ export const SIGNAL_VIA_IPC = 'signal-via-ipc'; export const DETACH = 'detach'; export const QUIET = 'quiet'; export const VERBOSE = 'verbose'; +export const ALREADY_OFF_ERROR = 'already-off-error'; /** * The options used by the commands. @@ -112,5 +113,9 @@ opts[DETACH] = new Option( 'boolean', false); opts[VERBOSE] = new Option(VERBOSE, 'Extra console output', 'boolean', false); opts[QUIET] = new Option(QUIET, 'Minimal console output', 'boolean', false); +opts[ALREADY_OFF_ERROR] = new Option( + ALREADY_OFF_ERROR, + 'Normally if you try to shut down a selenium which is not running, you will get a warning. This turns it into an error', + 'boolean', false); export var Opts = opts; diff --git a/lib/cmds/shutdown.ts b/lib/cmds/shutdown.ts index fb51e885..09965564 100644 --- a/lib/cmds/shutdown.ts +++ b/lib/cmds/shutdown.ts @@ -11,7 +11,8 @@ let logger = new Logger('shutdown'); let prog = new Program() .command('shutdown', 'shut down the selenium server') .action(shutdown) - .addOption(Opts[Opt.SELENIUM_PORT]); + .addOption(Opts[Opt.SELENIUM_PORT]) + .addOption(Opts[Opt.ALREADY_OFF_ERROR]); export var program = prog; @@ -30,6 +31,18 @@ if (argv._[0] === 'shutdown-run') { function shutdown(options: Options) { logger.info('Attempting to shut down selenium nicely'); http.get( - 'http://localhost:' + options[Opt.SELENIUM_PORT].getString() + - '/selenium-server/driver/?cmd=shutDownSeleniumServer'); + 'http://localhost:' + options[Opt.SELENIUM_PORT].getString() + + '/selenium-server/driver/?cmd=shutDownSeleniumServer') + .on('error', (e: NodeJS.ErrnoException) => { + if ((e.code == 'ECONNREFUSED') && (e.syscall == 'connect')) { + if (!options[Opt.ALREADY_OFF_ERROR].getBoolean()) { + logger.warn('Server does not appear to be on'); + } else { + logger.error('Server unreachable, probably not running'); + throw e; + } + } else { + throw e; + } + }); }