Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PM2 error occurred => exited with code [1] via signal [SIGINT]

Nodejs was running on PM2 for a long time. And there is a corn which clears PM2 logs everyday

0 0 * * * find /home/user/.pm2/logs* -mtime +2 -exec rm -rf {} \;

Below error occurred for 1000 times and then pm2 stopped working and then when I reloaded the instance it was working fine as usual.

What could be the reason for this error?

/home/user/.nvm/versions/node/v12.16.1/lib/node_modules/pm2/lib/ProcessContainer.js:167
      throw err;
      ^

[Error: ENOENT: no such file or directory, open '/home/user/.pm2/logs/out.log'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/home/user/.pm2/logs/out.log'
}
2020-09-09T00:55:33: PM2 log: App name:app id:1 disconnected
2020-09-09T00:55:33: PM2 log: App exited with code [1] via signal [SIGINT]
2020-09-09T00:55:33: PM2 log: App  starting in -cluster mode-
2020-09-09T00:55:33: PM2 log: App online
/home/user/.nvm/versions/node/v12.16.1/lib/node_modules/pm2/lib/ProcessContainer.js:167
      throw err;
      ^

[Error: ENOENT: no such file or directory, open '/home/user/.pm2/logs/out.log'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/home/user/.pm2/logs/out.log'
}
2020-09-09T00:55:33: PM2 log: App name:app id:1 disconnected
2020-09-09T00:55:33: PM2 log: App exited with code [1] via signal [SIGINT]
2020-09-09T00:55:33: PM2 log: App starting in -cluster mode-
2020-09-09T00:55:33: PM2 log: App online
/home/user/.nvm/versions/node/v12.16.1/lib/node_modules/pm2/lib/ProcessContainer.js:167
      throw err;
      ^

[Error: ENOENT: no such file or directory, open '/home/user/.pm2/logs/out.log'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/home/user/.pm2/logs/out.log'
}


like image 467
aRvi Avatar asked Oct 18 '25 15:10

aRvi


2 Answers

Can you try the below two steps and check this if it works.

pm2 start bin/www -i 0 // this will start a cluster and the main app

pm2 stop 0 // this will allow the cluster to keep running
like image 134
Vijay122 Avatar answered Oct 21 '25 07:10

Vijay122


You're trying to clean up logfiles by just using rm . You Can't Do That™. On Linux and other UNIX-derived OSs, the program writing the log file holds it open even when you rm it from a directory. The file doesn't actually disappear until the program writing it closes it (or terminates). This is true for all sorts of software, not just pm2.

If all you want is to clear out the log files and start over, the command pm2 flush is for you.

If you want to save old logs for a limited period of time, you should investigate pm2's log rotation addon.

Commands like this may do the trick for you

# install the pm2 addon ... notice it says pm2 install, not npm install
pm2 install pm2-logrotate
# rotate when a logfile fills to ten megabytes
pm2 set pm2-logrotate:max_size 10M
# gzip compress the rotated logs to save space
pm2 set pm2-logrotate:compress true
# force rotation at 00:00 each day even if logfile is not full 
pm2 set pm2-logrotate:rotateInterval '0 0 * * *'

You can say pm2 config pm2-logrotate to get it to show you its current settings.

like image 43
O. Jones Avatar answered Oct 21 '25 07:10

O. Jones



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!