-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js.old
More file actions
114 lines (110 loc) · 2.69 KB
/
main.js.old
File metadata and controls
114 lines (110 loc) · 2.69 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
var os = require('os');
var _ = require('underscore');
var sys = require('sys')
var exec = require('child_process').exec;
var dateFormat = require('dateformat');
var stack = require('./lib.stack').stack;
var fs = require('fs')
function processArgs() {
var i;
var args = process.argv.slice(2);
var output = {};
for (i=0;i<args.length;i++) {
var l1 = args[i].substr(0,1);
if (l1 == "-") {
output[args[i].substr(1)] = args[i+1];
i++;
}
}
return output;
};
var args = processArgs();
for (i in args) {
console.log("-> ",i,": ",args[i]);
}
function Reboot() {
this.stack = new stack();
this.today = dateFormat(new Date(), "mmmm-dS-yyyy");
this.scripts = {
Datastore: {
path: "/home/gitbuffer/datastore/",
script: "main.js"
},
Agora: {
path: "/home/gitbuffer/Agora/",
script: "main.js"
},
Daemons: {
path: "/home/gitbuffer/Daemons/",
script: "main.js"
},
Mailstack: {
path: "/home/gitbuffer/Mailstack/",
script: "main.js"
},
};
}
Reboot.prototype.reboot = function() {
var scope = this;
var name;
// Kill all node process
//this.execKill();
for (name in this.scripts) {
this.execUpdate(this.scripts[name].path);
this.execNode(this.scripts[name].path+this.scripts[name].script);
}
this.stack.process(function() {
console.log("> REBOOT DONE.");
});
}
Reboot.prototype.execKill = function() {
var scope = this;
this.stack.add(function(params, onFinish) {
console.log("> KILLING ALL NODE PROCESS.");
var child = exec("killall node", function (error, stdout, stderr) {
//sys.print('stdout: ' + stdout);
//sys.print('stderr: ' + stderr);
if (error !== null) {
//console.log('exec error: ' + error);
}
onFinish();
});
}, {});
}
Reboot.prototype.execNode = function(script) {
var scope = this;
this.stack.add(function(params, onFinish) {
console.log("> STARTING "+script+".");
var child = exec("node "+script+"", function (error, stdout, stderr) {
console.log(">> stdout",stdout);
console.log(">> stderr",stderr);
if (error !== null) {
console.log('>> error',error);
}
onFinish();
});
}, {});
}
Reboot.prototype.execUpdate = function(path) {
var scope = this;
this.stack.add(function(params, onFinish) {
console.log("> UPDATING "+path+".");
var child = exec("cd "+path+" && git pull", function (error, stdout, stderr) {
//sys.print('stdout: ' + stdout);
//sys.print('stderr: ' + stderr);
if (error !== null) {
//console.log('exec error: ' + error);
}
onFinish();
});
}, {});
}
Reboot.prototype.appendToFile = function(filename, data, callback) {
fs.appendFile(filename, data, function (err) {
if (callback) {
callback();
}
});
}
var reboot = new Reboot();
reboot.reboot();