Browse Source

added komodo debug.log truncate on herd start

all-modes
Petr Balashov 8 years ago
parent
commit
d437ff4d3d
  1. 27
      main.js
  2. 8
      routes/shepherd.js

27
main.js

@ -31,19 +31,18 @@ if (os.platform() === 'linux') {
// GUI APP settings and starting gui on address http://120.0.0.1:17777
var shepherd = require('./routes/shepherd'),
guiapp = express();
guiapp = express(),
appConfig = shepherd.loadLocalConfig(); // load app config
guiapp.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "http://127.0.0.1:17777");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.header("Access-Control-Allow-Credentials", "true");
res.header("Access-Control-Allow-Headers", "Content-Type");
res.header("Access-Control-Allow-Methods", "PUT, GET, POST, DELETE, OPTIONS");
res.header('Access-Control-Allow-Origin', 'http://127.0.0.1:' + appConfig.iguanaAppPort);
res.header('Access-Control-Allow-Headers', 'X-Requested-With');
res.header('Access-Control-Allow-Credentials', 'true');
res.header('Access-Control-Allow-Headers', 'Content-Type');
res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS'); // TODO: limit allowed methods
next();
});
var appConfig = shepherd.loadLocalConfig(); // load app config
// preload.js
const _setImmediate = setImmediate,
_clearImmediate = clearImmediate;
@ -69,7 +68,6 @@ guiapp.get('/', function (req, res) {
var guipath = path.join(__dirname, '/gui');
guiapp.use('/gui', express.static(guipath));
guiapp.use('/shepherd', shepherd);
/*if (cluster.isMaster && process.env.NODE_ENV !== "development") {
@ -84,18 +82,19 @@ console.log(cluster)
console.log('guiapp listening on port ' + appConfig.iguanaAppPort + '!');
});*/
var server = require('http').createServer(guiapp);
var io = require('socket.io').listen(server);
var server = require('http').createServer(guiapp),
io = require('socket.io').listen(server);
server.listen(appConfig.iguanaAppPort, function() {
console.log('guiapp and sockets.io are listening on port ' + appConfig.iguanaAppPort + '!');
});
io.set('origins', 'http://127.0.0.1:17777');
io.set('origins', 'http://127.0.0.1:17777'); // set origin
io.on('connection', function(client) {
console.log('EDEX GUI is connected...');
client.on('event', function(data) {
client.on('event', function(data) { // listen for client requests
console.log(data);
});
client.on('disconnect', function(data) {
@ -107,7 +106,7 @@ io.on('connection', function(client) {
});
});
shepherd.setIO(io);
shepherd.setIO(io); // pass sockets object to shepherd router
//io.emit('an event sent to all connected clients');

8
routes/shepherd.js

@ -1048,9 +1048,8 @@ shepherd.readDebugLog = function(fileLocation, lastNLines) {
_fs.readFile(fileLocation, 'utf-8', function(err, data) {
if (err) throw err;
// TODO: truncate komodod debug.log on app start
var lines = data.trim().split('\n');
var lastLine = lines.slice(lines.length - lastNLines, lines.length).join('\n');
var lines = data.trim().split('\n'),
lastLine = lines.slice(lines.length - lastNLines, lines.length).join('\n');
resolve(lastLine);
});
}
@ -1156,6 +1155,9 @@ function herder(flock, data) {
console.log('komodod flock selected...');
console.log('selected data: ' + data);
// truncate debug.log
fs.unlink(komodoDir + '/debug.log');
pm2.connect(true, function(err) { // start up pm2 god
if (err) {
console.error(err);

Loading…
Cancel
Save