0

I was recently trying to run a nodejs app I created using pm2 and this tutorial: https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-18-04 However, for some reason it throws this error and is unable to start:

root@ip-XXXXXXXXXX:/home/ubuntu# systemctl status pm2-ubuntu.service
● pm2-ubuntu.service - PM2 process manager
   Loaded: loaded (/etc/systemd/system/pm2-ubuntu.service; enabled; vendor preset: enabled)
   Active: failed (Result: protocol) since Wed 2019-01-16 17:15:25 UTC; 5s ago
     Docs: https://pm2.keymetrics.io/
  Process: 1686 ExecStart=/usr/lib/node_modules/pm2/bin/pm2 resurrect (code=exited, status=0/SUCCESS)

Jan 16 17:15:25 ip-XXXXXXXXXX pm2[1686]: [PM2] Restoring processes located in /home/ubuntu/.pm2/dump.pm2
Jan 16 17:15:25 ip-XXXXXXXXXX pm2[1686]: ┌──────────┬────┬─────────┬──────┬──────┬────────┬─────────┬────────┬─────┬───────────┬──────┬──────────┐
Jan 16 17:15:25 ip-XXXXXXXXXX pm2[1686]: │ App name │ id │ version │ mode │ pid  │ status │ restart │ uptime │ cpu │ mem       │ user │ watching │
Jan 16 17:15:25 ip-XXXXXXXXXX pm2[1686]: ├──────────┼────┼─────────┼──────┼──────┼────────┼─────────┼────────┼─────┼───────────┼──────┼──────────┤
Jan 16 17:15:25 ip-XXXXXXXXXX pm2[1686]: │ index    │ 0  │ 1.0.0   │ fork │ 1394 │ online │ 0       │ 113s   │ 0%  │ 41.1 MB   │ root │ disabled │
Jan 16 17:15:25 ip-XXXXXXXXXX pm2[1686]: └──────────┴────┴─────────┴──────┴──────┴────────┴─────────┴────────┴─────┴───────────┴──────┴──────────┘

I tried editing the pm2.pid file with nano, but it does not exist. Is there something wrong with my install? What do I do?

PM2 logfile:

2019-01-16T16:51:39: PM2 log: ===============================================================================
2019-01-16T16:51:39: PM2 log: --- New PM2 Daemon started ----------------------------------------------------
2019-01-16T16:51:39: PM2 log: Time                 : Wed Jan 16 2019 16:51:39 GMT+0000 (Coordinated Universal Time)
2019-01-16T16:51:39: PM2 log: PM2 version          : 3.2.8
2019-01-16T16:51:39: PM2 log: Node.js version      : 10.15.0
2019-01-16T16:51:39: PM2 log: Current arch         : x64
2019-01-16T16:51:39: PM2 log: PM2 home             : /home/ubuntu/.pm2
2019-01-16T16:51:39: PM2 log: PM2 PID file         : /home/ubuntu/.pm2/pm2.pid
2019-01-16T16:51:39: PM2 log: RPC socket file      : /home/ubuntu/.pm2/rpc.sock
2019-01-16T16:51:39: PM2 log: BUS socket file      : /home/ubuntu/.pm2/pub.sock
2019-01-16T16:51:39: PM2 log: Application log path : /home/ubuntu/.pm2/logs
2019-01-16T16:51:39: PM2 log: Process dump file    : /home/ubuntu/.pm2/dump.pm2
2019-01-16T16:51:39: PM2 log: Concurrent actions   : 2
2019-01-16T16:51:39: PM2 log: SIGTERM timeout      : 1600
2019-01-16T16:51:39: PM2 log: ===============================================================================
2019-01-16T16:51:39: PM2 log: App [index:0] starting in -fork mode-
2019-01-16T16:51:39: PM2 log: App [index:0] online
2019-01-16T16:56:59: PM2 log: pm2 has been killed by signal, dumping process list before exit...
2019-01-16T16:56:59: PM2 log: Deleting process 0
2019-01-16T16:56:59: PM2 log: Stopping app:index id:0
2019-01-16T16:56:59: PM2 log: App [index:0] exited with code [0] via signal [SIGHUP]
2019-01-16T16:56:59: PM2 log: pid=10369 msg=process killed
2019-01-16T16:56:59: PM2 log: Exited peacefully
2019-01-16T16:57:41: PM2 log: ===============================================================================

any and all help is appreciated

5
  • 2
    PM2 is unnecessary here (and this tutorial goes on the list of bad Internet tutorials). You can just start your Node app directly from a systemd unit. Commented Jan 16, 2019 at 18:38
  • 1
    Thanks for sparing me, I dreaded having to use PM2
    – Jake t
    Commented Jan 16, 2019 at 18:59
  • @MichaelHampton While I do think that systemd mostly replaced existing process managers, I think pm2 is likely an exception, particularly for it's "cluster mode".
    – jordanm
    Commented Jan 16, 2019 at 21:08
  • @MichaelHampton It worked! However, I now get an error that says "cannot get /" after configuring a reverse proxy with the following code location /iwl { proxy_pass http://localhost:6060; } You can see this in action at jakesandbox.com/iwl
    – Jake t
    Commented Jan 16, 2019 at 21:27
  • so what was the solution? What is it even that worked now, pm2 or systemd? While @MichaelHampton gives a good hint, there are valid reasons to use pm2 and the question here remains unanswered...
    – N4ppeL
    Commented Aug 13, 2019 at 9:34

1 Answer 1

0

It could be a

  • SElinux issue (as pid file or files are by default created under /home directory and not under /run/ and because of non-standard location SElinux blocks it)
  • Related to pid file -specific configuration (e.g. setting PM2_PID_FILE_PATH and/or PIDFile to /run/pm2/pm2.pid or /run/pm2.pid)
  • PM2 needs to be reinstalled/updated

Please see the discussion in (possibly) similar question https://stackoverflow.com/questions/62814539/pm2-keeps-getting-killed-every-90-seconds-on-centos-8/, and configuration-related details (referring to https://unix.stackexchange.com/questions/604679/selinux-how-to-grant-read-access/607750 ) in https://github.com/Unitech/pm2/issues/4813

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .