|
@ -87,6 +87,49 @@ shepherd.appConfig = { |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
shepherd.loadLocalConfig = function() { |
|
|
|
|
|
if (fs.existsSync(iguanaDir + '/config.json')) { |
|
|
|
|
|
var localAppConfig = fs.readFileSync(iguanaDir + '/config.json', 'utf8'); |
|
|
|
|
|
console.log('app config set from local file'); |
|
|
|
|
|
|
|
|
|
|
|
// find diff between local and hardcoded configs
|
|
|
|
|
|
// append diff to local config
|
|
|
|
|
|
var compareJSON = function(obj1, obj2) { |
|
|
|
|
|
var result = {}; |
|
|
|
|
|
|
|
|
|
|
|
for (var i in obj1) { |
|
|
|
|
|
if (!obj2.hasOwnProperty(i)) { |
|
|
|
|
|
result[i] = obj1[i]; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var compareConfigs = compareJSON(shepherd.appConfig, JSON.parse(localAppConfig)); |
|
|
|
|
|
if (Object.keys(compareConfigs).length) { |
|
|
|
|
|
var newConfig = Object.assign(JSON.parse(localAppConfig), compareConfigs); |
|
|
|
|
|
|
|
|
|
|
|
console.log('config diff is found, updating local config'); |
|
|
|
|
|
console.log('config diff:'); |
|
|
|
|
|
console.log(compareConfigs); |
|
|
|
|
|
|
|
|
|
|
|
shepherd.saveLocalAppConf(newConfig); |
|
|
|
|
|
return newConfig; |
|
|
|
|
|
} else { |
|
|
|
|
|
return JSON.parse(localAppConfig); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
console.log('local config file is not found!'); |
|
|
|
|
|
shepherd.saveLocalAppConf(shepherd.appConfig); |
|
|
|
|
|
|
|
|
|
|
|
return shepherd.appConfig; |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
shepherd.appConfig = shepherd.loadLocalConfig(); |
|
|
|
|
|
|
|
|
console.log('iguana dir: ' + iguanaDir); |
|
|
console.log('iguana dir: ' + iguanaDir); |
|
|
console.log('iguana bin: ' + iguanaBin); |
|
|
console.log('iguana bin: ' + iguanaBin); |
|
|
console.log('--------------------------') |
|
|
console.log('--------------------------') |
|
@ -465,47 +508,6 @@ shepherd.get('/kick', function(req, res, next) { |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
shepherd.loadLocalConfig = function() { |
|
|
|
|
|
if (fs.existsSync(iguanaDir + '/config.json')) { |
|
|
|
|
|
var localAppConfig = fs.readFileSync(iguanaDir + '/config.json', 'utf8'); |
|
|
|
|
|
console.log('app config set from local file'); |
|
|
|
|
|
|
|
|
|
|
|
// find diff between local and hardcoded configs
|
|
|
|
|
|
// append diff to local config
|
|
|
|
|
|
var compareJSON = function(obj1, obj2) { |
|
|
|
|
|
var result = {}; |
|
|
|
|
|
|
|
|
|
|
|
for (var i in obj1) { |
|
|
|
|
|
if (!obj2.hasOwnProperty(i)) { |
|
|
|
|
|
result[i] = obj1[i]; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var compareConfigs = compareJSON(shepherd.appConfig, JSON.parse(localAppConfig)); |
|
|
|
|
|
if (Object.keys(compareConfigs).length) { |
|
|
|
|
|
var newConfig = Object.assign(JSON.parse(localAppConfig), compareConfigs); |
|
|
|
|
|
|
|
|
|
|
|
console.log('config diff is found, updating local config'); |
|
|
|
|
|
console.log('config diff:'); |
|
|
|
|
|
console.log(compareConfigs); |
|
|
|
|
|
|
|
|
|
|
|
shepherd.saveLocalAppConf(newConfig); |
|
|
|
|
|
return newConfig; |
|
|
|
|
|
} else { |
|
|
|
|
|
return JSON.parse(localAppConfig); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
console.log('local config file is not found!'); |
|
|
|
|
|
shepherd.saveLocalAppConf(shepherd.appConfig); |
|
|
|
|
|
|
|
|
|
|
|
return shepherd.appConfig; |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
shepherd.readDebugLog = function(fileLocation, lastNLines) { |
|
|
shepherd.readDebugLog = function(fileLocation, lastNLines) { |
|
|
return new Promise( |
|
|
return new Promise( |
|
|
function(resolve, reject) { |
|
|
function(resolve, reject) { |
|
@ -609,10 +611,12 @@ function herder(flock, data) { |
|
|
process.exit(2); |
|
|
process.exit(2); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
console.log('iguana core port ' + shepherd.appConfig.iguanaCorePort); |
|
|
pm2.start({ |
|
|
pm2.start({ |
|
|
script: iguanaBin, // path to binary
|
|
|
script: iguanaBin, // path to binary
|
|
|
name: 'IGUANA', |
|
|
name: 'IGUANA', |
|
|
exec_mode : 'fork', |
|
|
exec_mode : 'fork', |
|
|
|
|
|
args: ['-port=' + shepherd.appConfig.iguanaCorePort], |
|
|
cwd: iguanaDir //set correct iguana directory
|
|
|
cwd: iguanaDir //set correct iguana directory
|
|
|
}, function(err, apps) { |
|
|
}, function(err, apps) { |
|
|
pm2.disconnect(); // Disconnect from PM2
|
|
|
pm2.disconnect(); // Disconnect from PM2
|
|
|