Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #97 from nodejitsu/ssh-poll

[refactor] Poll SSH instead of fixed timeout while bootstrapping
  • Loading branch information...
commit fe0e7a1d926e098893a5fda2b9df5aef38678a9d 2 parents 80e6f24 + a4b48d9
@AvianFlu AvianFlu authored
Showing with 46 additions and 2 deletions.
  1. +46 −2 lib/pkgcloud/core/compute/bootstrapper.js
View
48 lib/pkgcloud/core/compute/bootstrapper.js
@@ -211,13 +211,17 @@ Bootstrapper.prototype.createServer = function (options) {
//
// Grace period for IP propagation
//
- setTimeout(function () {
+ self._sshPoll(options, function (err) {
+ if (err) {
+ return onError(err);
+ }
+
self.bootstrapServer(options)
.on('error', onError)
.on('complete', function () {
emitter.emit('complete', server);
});
- }, 60 * 1000);
+ });
}
return options.afterCreate
@@ -762,3 +766,43 @@ Bootstrapper.prototype._exec = function (command, options) {
return emitter;
};
+
+//
+// ### @private function _sshPoll (options)
+// #### @options {Object} Options to use when polling the server.
+// #### @callback {function} Continuation to respond to.
+// Polls server over ssh, trying to determine when server is actually up and
+// active, ready to accept commands.
+//
+Bootstrapper.prototype._sshPoll = function (options, callback) {
+ // TODO (mmalecki): make maxTries and interval configurable
+ var self = this,
+ maxTries = 10,
+ interval = 30 * 1000,
+ tries = 0;
+
+ function poll() {
+ var child = self.ssh({
+ keys: options.keys,
+ server: options.server,
+ tunnel: options.tunnel,
+ remoteUser: options.remoteUser,
+ commands: ['true']
+ });
+
+ child.on('error', function () {
+ ++tries;
+ if (tries === maxTries) {
+ return callback(new Error('Server didn\'t become active in timely fashion'));
+ }
+
+ setTimeout(poll, interval);
+ });
+
+ child.on('complete', function () {
+ return callback();
+ });
+ }
+
+ poll();
+};
Please sign in to comment.
Something went wrong with that request. Please try again.