-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathindex.js
40 lines (39 loc) · 1.19 KB
/
index.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
exports.start = function(){
var exec = require('child_process').exec;
var fs = require('fs');
var child = "";
function error(data){
console.log(data);
var d = new Date();
var daylog = "logerr/log"+d.getUTCFullYear()+"_"+(d.getUTCMonth()+1)+"_"+d.getUTCDate()+".txt";
fs.appendFileSync(daylog, "\r\n ERROR:" + d + "\r\n"+ data);
if (data.substring(0, 14)=='_tls_common.js'){
console.log("SSL error");
fs.createReadStream('ssl/bkp/service.crt').pipe(fs.createWriteStream('ssl/service.crt'));
fs.createReadStream('ssl/bkp/service.key').pipe(fs.createWriteStream('ssl/service.key'));
};
};
function reset(){
start();
};
function start(){
var cfg = require('./js/config.js');
process.env.ismodule = true;
process.env.mpath="";
cfg.checkstruct();
cfg.checkssl(go);
function go(err){
child = exec('node kdman.js',{cwd:'node_modules/psql-api/',env:{ismodule:true,mpath:process.cwd()+'/'}});
child.stdout.on('data', function(data) {
console.log(data);
});
child.stderr.on('data', function(data) {
error(data);
});
child.on('close', function(code) {
if (code>0){reset()} else {console.log('closing code: ',code)};
});
};
};
start();
}