Running
pm2 status
May output something like
id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │ 16 │ test-frontend │ default │ 0.35.3 │ fork │ 0 │ 0 │ 16 │ errored │ 0% │ 0b │ bel… │ disabled
Let's find out why the process errored!
cd ~/.pm2/logs
If you have many logs in here already and no need for them, you could delete them all. Alternatively you can just delete the log for this process
sudo rm *.log // for deleting all .log files in that directory sudo rm test-frontend.log // for deleting just the log for this process
Now, restart the PM2 process:
pm2 restart test-frontend // or pm2 restart 16
Check if the error still persists:
pm2 status
If yet, stop it:
pm2 stop test-frontend // or pm2 stop 16
And check the logs.
cat test-frontend-error.log
In my case the output was:
Unknown or unexpected option: --no-autorestart
I remember that I just added the flag "--no-autorestart" to the pm2 start command a few days ago. It seems like I placed it wrong. So I fixed the command and ran the bash script which fires the pm2 start command again to be:
pm2 start npm --name test-frontend --no-autorestart -- start -- -p 3001
It is a Next.js frontend, started on the local port 3001 and "--no-autorestart" is a command for PM2 to no restart the process, if it fails.