Skip to content

Commit

Permalink
feat(shutdown): do not error if you try to shutdown a server which is…
Browse files Browse the repository at this point in the history
… already off (#162)

When scripting, you might want to defensively run a `shutdown` command.  If the shutdown fails because the server is already off, you don't care.  If it fails for another reason, you do care.
So I made trying to shutdown a server which is already off just a warning.  I added a flag in case you want the old behavior though.
  • Loading branch information
sjelin authored and heathkit committed Nov 28, 2016
1 parent 7a08b8a commit c864c9a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lib/cmds/opts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
19 changes: 16 additions & 3 deletions lib/cmds/shutdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
});
}

0 comments on commit c864c9a

Please sign in to comment.