On Fri, Apr 13, 2012 at 04:56:51AM -0700, khinester wrote:
> 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 appreciatedPut that whole script into a function and use recursion.
pgpn7X7DtkwMY.pgp
Description: PGP signature
