Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: pkgcloud/pkgcloud
...
head fork: pkgcloud/pkgcloud
  • 2 commits
  • 1 file changed
  • 0 commit comments
  • 2 contributors
Commits on Mar 11, 2013
@mmalecki mmalecki [refactor] Poll SSH instead of fixed timeout while bootstrapping
Various compute providers need different time to bring the VM up and
make it accessible under some IP. Previously we'd simply wait a minute
before trying to bootstrap the server.
This polls VM over SSH to determine when it's up and ready to accept
commands.
a4b48d9
@AvianFlu AvianFlu Merge pull request #97 from nodejitsu/ssh-poll
[refactor] Poll SSH instead of fixed timeout while bootstrapping
fe0e7a1
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();
+};

No commit comments for this range

Something went wrong with that request. Please try again.