Pm2: watch not working in ecosystem.config.js

Created on 30 Mar 2018  ยท  8Comments  ยท  Source: Unitech/pm2

What's going wrong?

Simply cannot get watch to watch anything when configured in ecosystem.config.js. It works if I use --watch but that watches too many files. It says watch and restart are enabled but never restarts anything and logs don't make any mention of watching. Have tried watching a file and an array of files too. User is not root.

How could we reproduce this issue?

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.4 LTS
$ cat ecosystem.config.js
module.exports = {
  apps : [
    {
      name: 'feeder',
      script: 'feeder/app.js',
      watch: true,
    }
  ]
};
$ ls *
ecosystem.config.js

feeder:
app.js  node_modules  package.json  package-lock.json
$ pm2 start ecosystem.config.js
[PM2] Applying action restartProcessId on app [feeder](ids: 0)
[PM2] [feeder](0) โœ“
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ App name โ”‚ id โ”‚ mode โ”‚ pid   โ”‚ status โ”‚ restart โ”‚ uptime โ”‚ cpu โ”‚ mem      โ”‚ user โ”‚ watching โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ feeder   โ”‚ 0  โ”‚ fork โ”‚ 10562 โ”‚ online โ”‚ 22      โ”‚ 0s     โ”‚ 0%  โ”‚ 4.0 KB   โ”‚ bub  โ”‚ enabled  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
 Use `pm2 show <id|name>` to get more details about an app
bubo@bubo:~$ touch feeder/app.js
bubo@bubo:~$ pm2 ls feeder
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ App name โ”‚ id โ”‚ mode โ”‚ pid   โ”‚ status โ”‚ restart โ”‚ uptime โ”‚ cpu โ”‚ mem       โ”‚ user โ”‚ watching โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ feeder   โ”‚ 0  โ”‚ fork โ”‚ 10562 โ”‚ online โ”‚ 22      โ”‚ 44s    โ”‚ 0%  โ”‚ 38.1 MB   โ”‚ bub  โ”‚ enabled  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Supporting information

$ pm2 report
===============================================================================
--- PM2 REPORT (Fri Mar 30 2018 17:58:20 GMT+0100 (BST)) ----------------------
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 2.10.1
node version         : 8.10.0
node path            : undefined
argv                 : /usr/bin/node,/usr/lib/node_modules/pm2/lib/Daemon.js
argv0                : node
user                 : bub
uid                  : 1002
gid                  : 1002
uptime               : 476min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 2.10.1
node version         : 8.10.0
node path            : /usr/bin/pm2
argv                 : /usr/bin/node,/usr/bin/pm2,report
argv0                : node
user                 : bub
uid                  : 1002
gid                  : 1002
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : linux
type                 : Linux
cpus                 : Intel(R) Core(TM) i7-4910MQ CPU @ 2.90GHz
cpus nb              : 1
freemem              : 181456896
totalmem             : 1040437248
home                 : /home/bub
===============================================================================
--- PM2 list -----------------------------------------------
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ App name โ”‚ id โ”‚ mode โ”‚ pid  โ”‚ status โ”‚ restart โ”‚ uptime โ”‚ cpu โ”‚ mem       โ”‚ user โ”‚ watching โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ feeder   โ”‚ 0  โ”‚ fork โ”‚ 6552 โ”‚ online โ”‚ 21      โ”‚ 2s     โ”‚ 4%  โ”‚ 37.7 MB   โ”‚ bub โ”‚ enabled  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
===============================================================================
--- Daemon logs --------------------------------------------
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ App name โ”‚ id โ”‚ mode โ”‚ pid  โ”‚ status โ”‚ restart โ”‚ uptime โ”‚ cpu โ”‚ mem       โ”‚ user โ”‚ watching โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ feeder   โ”‚ 0  โ”‚ fork โ”‚ 6552 โ”‚ online โ”‚ 21      โ”‚ 2s     โ”‚ 0%  โ”‚ 37.7 MB   โ”‚ bub โ”‚ enabled  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Most helpful comment

@vtolenti89 assuming ALL your apps are defined in your ecosystem file try:

$ pm2 delete all
$ pm2 start ecosystem.config.js

That's essentially what got it working for me and when I understood this it worked every time.

All 8 comments

I have same issue. ignore_watch does not work in ecosystem file either

Did you ever get this to work?

Working on a new project, had the same problem, found this issue from ages ago but found a solution - might be the same might be different.

What I did this time is delete the app completely before starting it via ecosystem file - turns out watch settings weren't updating properly and the 'watching/enabled' bit may be misleading. I had created the app first and then switched to 'ecosystem'... A little more diagnostic output in logs etc around watching and watched might have helped.

Closing this issue as 'user error'-ish.

I would disagree that it's user error as it's not clear how to use it. If it's indeed user error and deleting app would help, would be beneficial to update docs for that.

I also disagree. I have the same issue for ages. Whatever paths I use in the watch property, if I add one, or in the script name, it doesn't work. Spent two days on it.

It doesn't work.

Changes to test1.js doesn't trigger a restart.
If I start test3.js manually with pm2 start bots/test3.js --watch, changes to test1.js will trigger a restart. process.cwd() returns /home/chris.

chris@localhost:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.1 LTS
Release:        18.04
Codename:       bionic
chris@localhost:~$ cat bots/bots.json
[
        {
                "name": "test1",
                "script": "./bots/test1.js",
                "watch": "./bots/test1.js"
        },
        {
                "name": "test2",
                "script": "./bots/test2.js",
                "cwd": "./bots",
                "watch": true,
                "ignore_watch": [
                        "db",
                        "/db"
                ],
                "watch_options": {
                        "followSymlinks": false
                }
        },
...

chris@localhost:~$ pm2 report

--- PM2 REPORT (Wed Feb 05 2020 15:13:47 GMT+0000 (Coordinated Universal Time))

--- Daemon -------------------------------------------------
pm2d version         : 3.0.3
node version         : 12.12.0
node path            : /usr/bin/pm2
argv                 : /home/chris/.nvm/versions/node/v12.12.0/bin/node,/usr/lib/node_modules/pm2/lib/Daemon.js
argv0                : node
user                 : chris
uid                  : 1000
gid                  : 1000
uptime               : 42min

--- CLI ----------------------------------------------------
local pm2            : 3.0.3
node version         : 12.12.0
node path            : /usr/bin/pm2
argv                 : /home/chris/.nvm/versions/node/v12.12.0/bin/node,/usr/bin/pm2,report
argv0                : node
user                 : chris
uid                  : 1000
gid                  : 1000

--- System info --------------------------------------------
arch                 : x64
platform             : linux
type                 : Linux
cpus                 : AMD EPYC 7601 32-Core Processor
cpus nb              : 1
freemem              : 743907328
totalmem             : 2090225664
home                 : /home/chris

--- PM2 list -----------------------------------------------
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ App name           โ”‚ id โ”‚ mode โ”‚ pid   โ”‚ status โ”‚ restart โ”‚ uptime โ”‚ cpu  โ”‚ mem       โ”‚ user โ”‚ watching โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ test1        โ”‚ 1  โ”‚ fork โ”‚ 14937 โ”‚ online โ”‚ 31      โ”‚ 5m     โ”‚ 0.1% โ”‚ 38.2 MB   โ”‚ chris โ”‚ enabled  โ”‚
โ”‚ test2           โ”‚ 0  โ”‚ fork โ”‚ 14930 โ”‚ online โ”‚ 31      โ”‚ 5m     โ”‚ 0%   โ”‚ 38.2 MB   โ”‚ chris โ”‚ enabled  โ”‚


I am also struggling with the same problem.

@vtolenti89 assuming ALL your apps are defined in your ecosystem file try:

$ pm2 delete all
$ pm2 start ecosystem.config.js

That's essentially what got it working for me and when I understood this it worked every time.

@vtolenti89 assuming ALL your apps are defined in your ecosystem file try:

$ pm2 delete all
$ pm2 start ecosystem.config.js

That's essentially what got it working for me and when I understood this it worked every time.

This worked for me

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chaos-git picture chaos-git  ยท  3Comments

waygee picture waygee  ยท  4Comments

morfies picture morfies  ยท  3Comments

mario-mui picture mario-mui  ยท  3Comments

xzycn picture xzycn  ยท  3Comments