forked from angular/angularjs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
propagateClusterUpdate.js
70 lines (58 loc) · 1.89 KB
/
propagateClusterUpdate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var exec = require('child_process').exec,
http = require('http'),
TARGET_POOL = 'ng-sites',
REGION = 'us-central1',
PROJECT = '435162472401',
PORT = '8000';
console.log('Beginning propagation to other instances');
exec('gcutil gettargetpool '+ TARGET_POOL +' --project='+ PROJECT +' --region='+ REGION +' --format=json', function (err, result, code) {
var executed = 0,
instances;
if (err) {
throw new Error(err);
}
try {
targetPool = JSON.parse(result);
instances = targetPool.instances;
}
catch (e) {
console.log('Could not parse target pool');
return process.exit(1);
}
instances.forEach(function (instance) {
var name = /^.*\/([a-zA-Z\-0-9]*)$/.exec(instance)[1];
exec('gcutil getinstance '+ name +' --format=json --project='+ PROJECT, function (err, result, code) {
var instance, reqUrl, exitCode = 0;
if (err) {
console.log(err);
return process.exit(code);
}
try {
instance = JSON.parse(result);
instance.networkInterfaces.forEach(function (netInt) {
if (reqUrl) return;
if (netInt.networkIP) reqUrl = 'http://'+ netInt.networkIP +':'+ PORT +'/gitFetchSite.php?doNotPropagate=true';
});
}
catch (e) {
console.log(e);
return process.exit(1);
}
if (!reqUrl) {
return console.log('Could not find any URL for instance', instance);
}
console.log('Updating remote instance: ', reqUrl);
http.get(reqUrl, function (res) {
console.log('Finished executing', reqUrl);
executed++;
executed === instances.length && process.exit(exitCode);
}).on('error', function (err) {
console.log('Failed to update', reqUrl);
console.log(err);
executed++;
exitCode = 1;
executed === instances.length && process.exit(exitCode);
});
});
});
});