khinester
unread,Apr 13, 2012, 7:56:51 AM4/13/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to nodejs
hello, i have this code:
var http = require('http')
, url = require('url')
, util = require('util')
, exec = require('child_process').exec;
var site = http.createClient(80, "www.domain.tld", false);
var req = site.request("GET", "/");
req.end();
req.on('response', function(res){
if(res.statusCode !== 200){
// launch a new instance
var ec2 = require("ec2")
, fs = require("fs");
// Read in the configuration above.
var configuration =
JSON.parse(fs.readFileSync("configuration.json", "utf8"));
// Create an ec2 function that uses your configuration.
ec2 = ec2(configuration)
// Run an instance and wait for it to become ready.
ec2("RunInstances", {
ImageId: "ami-XXXXXX"
, KeyName: "micros-ie"
, InstanceType: "t1.micro"
, MinCount: 1
, MaxCount: 1
}, function (error, response) {
if (error) {
throw error
}
ready();
});
} else {
res.on('data', function(chunk){
function puts(error, stdout, stderr) { util.puts(stdout) }
exec("my command", puts);
});
}
});
basically, i would like to launch a new EC2 instance if the status
code is not equal to 200. this works ok, but my problem is that when
the code goes into the 'else' loop, i would like to check if the
'site' still returns a 200 status code.
any advice much appreciated