I have a PM2 process for my NodeJS server and it crash after few minutes. I read somewhere I need to run PM2 as root to not crash.
So I do :
debian@vps:~$ pm2 start server
[PM2] Applying action restartProcessId on app [server](ids: [ 1 ])
[PM2] [server](1) ✓
[PM2] Process successfully started
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name │ mode │ ↺ │ status │ cpu │ memory │
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 1 │ server │ fork │ 991 │ online │ 0% │ 13.8mb │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘
Current process list running is not in sync with saved list. App app differs. Type 'pm2 save' to synchronize.
debian@vps:~$ pm2 stop server
[PM2] Applying action stopProcessId on app [server](ids: [ 1 ])
[PM2] [server](1) ✓
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name │ mode │ ↺ │ status │ cpu │ memory │
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 1 │ server │ fork │ 991 │ stopped │ 0% │ 0b │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘
Current process list running is not in sync with saved list. App app differs. Type 'pm2 save' to synchronize.
debian@vps:~$ sudo pm2 start server
sudo: pm2: command not found
So I can't run it as root?
type pm2to get the full path to thepm2command and usesudo /full/path/to/pm2 start serveraccordingly – Bodo Apr 22 '21 at 18:09debian@vps:~$ type pm2 pm2 is hashed (/home/debian/.nvm/versions/node/v15.12.0/bin/pm2)And I have :
– GrindCode Apr 22 '21 at 18:19/usr/bin/env: ‘node’: No such file or directoryPATHis for the normal user, usesudo -sto start arootshell, changePATHto the same value as for the normal user, then runpm2 start server. If you want to do this as a permanent solution, you might want to install the.nvmstuff andnodein a system directory instead of in a user home directory. Please find out why your NodeJS server might require to be run asroot. Maybe there is a better solution. Running programs as root` should be avoided. – Bodo Apr 22 '21 at 18:47