Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 36 additions & 11 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,35 @@ function proceed_app(app, force) {
}
}

function get_log_paths(app) {
var paths = [];

if (app.pm2_env.pm_out_log_path) {
paths.push(app.pm2_env.pm_out_log_path);
}
if (app.pm2_env.pm_err_log_path && app.pm2_env.pm_err_log_path !== app.pm2_env.pm_out_log_path) {
paths.push(app.pm2_env.pm_err_log_path);
}
if (app.pm2_env.pm_log_path && app.pm2_env.pm_log_path !== app.pm2_env.pm_out_log_path && app.pm2_env.pm_log_path !== app.pm2_env.pm_err_log_path) {
paths.push(app.pm2_env.pm_log_path);
}

return paths;
}

function mark_new_paths(paths, map) {
var hasNew = false;

paths.forEach(function(p) {
if (!map[p]) {
map[p] = true;
hasNew = true;
}
});

return hasNew;
}

// Connect to local PM2
pm2.connect(function(err) {
if (err) return console.error(err.stack || err);
Expand All @@ -205,17 +234,15 @@ pm2.connect(function(err) {
pm2.list(function(err, apps) {
if (err) return console.error(err.stack || err);

var appMap = {};
var logMap = {};
// rotate log that are bigger than the limit
apps.forEach(function(app) {
// if its a module and the rotate of module is disabled, ignore
if (typeof(app.pm2_env.axm_options.isModule) !== 'undefined' && !ROTATE_MODULE) return ;

// if apps instances are multi and one of the instances has rotated, ignore
if(app.pm2_env.instances > 1 && appMap[app.name]) return;

appMap[app.name] = app;

var paths = get_log_paths(app);
if (paths.length && !mark_new_paths(paths, logMap)) return;

proceed_app(app, false);
});
});
Expand All @@ -231,16 +258,14 @@ pm2.connect(function(err) {
pm2.list(function(err, apps) {
if (err) return console.error(err.stack || err);

var appMap = {};
var logMap = {};
// force rotate for each app
apps.forEach(function(app) {
// if its a module and the rotate of module is disabled, ignore
if (typeof(app.pm2_env.axm_options.isModule) !== 'undefined' && !ROTATE_MODULE) return ;

// if apps instances are multi and one of the instances has rotated, ignore
if(app.pm2_env.instances > 1 && appMap[app.name]) return;

appMap[app.name] = app;
var paths = get_log_paths(app);
if (paths.length && !mark_new_paths(paths, logMap)) return;

proceed_app(app, true);
});
Expand Down