From 81f89378bb942bd2f9518ca2a2effbaa906ed1c7 Mon Sep 17 00:00:00 2001 From: Arthur Schreiber Date: Wed, 27 Aug 2014 17:42:49 +0200 Subject: [PATCH] Ensure open file handles are closed again. This fixes a "Error: EMFILE, too many open files" error we've been seeing. --- lib/CLI.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/CLI.js b/lib/CLI.js index 48447a74..2dfab6c1 100644 --- a/lib/CLI.js +++ b/lib/CLI.js @@ -457,12 +457,12 @@ CLI.startup = function(platform, opts, cb) { } else if (platform == 'centos' || platform == 'redhat' || platform == 'amazon') { cmd = 'chmod +x ' + INIT_SCRIPT + '; chkconfig --add ' + p.basename(INIT_SCRIPT); - fs.openSync('/var/lock/subsys/pm2-init.sh', 'w'); + fs.closeSync(fs.openSync('/var/lock/subsys/pm2-init.sh', 'w')); printOut('/var/lock/subsys/pm2-init.sh lockfile has been added'); } else if (platform == 'gentoo') { cmd = 'chmod +x ' + INIT_SCRIPT + '; rc-update add ' + p.basename(INIT_SCRIPT) + ' default'; - fs.openSync('/var/lock/subsys/pm2-init.sh', 'w'); + fs.closeSync(fs.openSync('/var/lock/subsys/pm2-init.sh', 'w')); printOut('/var/lock/subsys/pm2-init.sh lockfile has been added'); } else { @@ -1222,7 +1222,7 @@ CLI.jlist = function(debug) { */ CLI.flush = function(cb) { printOut(cst.PREFIX_MSG + 'Flushing ' + cst.PM2_LOG_FILE_PATH); - fs.openSync(cst.PM2_LOG_FILE_PATH, 'w'); + fs.closeSync(fs.openSync(cst.PM2_LOG_FILE_PATH, 'w')); Satan.executeRemote('getMonitorData', {}, function(err, list) { if (err) { @@ -1234,8 +1234,8 @@ CLI.flush = function(cb) { printOut(cst.PREFIX_MSG + l.pm2_env.pm_out_log_path); printOut(cst.PREFIX_MSG + l.pm2_env.pm_err_log_path); - fs.openSync(l.pm2_env.pm_out_log_path, 'w'); - fs.openSync(l.pm2_env.pm_err_log_path, 'w'); + fs.closeSync(fs.openSync(l.pm2_env.pm_out_log_path, 'w')); + fs.closeSync(fs.openSync(l.pm2_env.pm_err_log_path, 'w')); }); printOut(cst.PREFIX_MSG + 'Logs flushed'); return cb ? cb(null, list) : exitCli(cst.SUCCESS_EXIT);