0

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?

GrindCode
  • 141
  • 4
  • run `type pm2` to get the full path to the `pm2` command and use `sudo /full/path/to/pm2 start server` accordingly – Bodo Apr 22 '21 at 18:09
  • `debian@vps:~$ type pm2 pm2 is hashed (/home/debian/.nvm/versions/node/v15.12.0/bin/pm2)` And I have : `/usr/bin/env: ‘node’: No such file or directory` – GrindCode Apr 22 '21 at 18:19
  • If you want to do it for testing only, then check what your `PATH` is for the normal user, use `sudo -s` to start a `root` shell, change `PATH` to the same value as for the normal user, then run `pm2 start server`. If you want to do this as a permanent solution, you might want to install the `.nvm` stuff and `node` in a system directory instead of in a user home directory. Please find out why your NodeJS server might require to be run as `root`. Maybe there is a better solution. Running programs as root` should be avoided. – Bodo Apr 22 '21 at 18:47

0 Answers0