Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Param: ignore_watch doesn't work on .git folder #1288

Closed
crico opened this issue May 20, 2015 · 13 comments
Closed

Param: ignore_watch doesn't work on .git folder #1288

crico opened this issue May 20, 2015 · 13 comments
Assignees

Comments

@crico
Copy link

crico commented May 20, 2015

I have the below start-script (processes.json):

{
    "apps" : [{
        "name" : "myapp",
        "script" : "bin/www",
        "watch" : true,
      "ignore_watch" : ["[\\/\\\\]\\./", "node_modules"],
        "watch_options": {
              "followSymlinks": false
        },
        "log_date_format" : "YYYY-MM-DD HH:mm Z",
        "merge_logs" : true
    }]
}

when I start the app with the command: pm2 start processes.json, I see that the app is restarted every time that file: ".git/FETCH_HEAD" is updated.

I test with:
"ignore_watch" : [".git", "node_modules"]
or
"ignore_watch" : [".git/FETCH_HEAD", "node_modules"]
with the same result.

Versions:
pm2 0.12.15
node v0.12.3
npm 2.9.1

What could be the problem?

Regards!

@soyuka
Copy link
Collaborator

soyuka commented May 20, 2015

Hi,

Just tested on osx and same nodejs/pm2 versions.

Played with .git and it just works with the default pm2 settings (/[\/\\]\.|node_modules/). It's also working when I use --ignore-watch .git.

Could you provide a sample of your ~/.pm2/pm2.log after retrying? What's your os?

@crico
Copy link
Author

crico commented May 21, 2015

Hi,
I'm testing on Debian Squeeze.
Sample of pm2.log:

2015-05-20 11:08:15: Change detected for app name: myapp - restarting
2015-05-20 11:08:15: Stopping app:myapp id:1
2015-05-20 11:08:15: App name:myapp id:1 exited with code SIGTERM
2015-05-20 11:08:15: Process with pid 13640 killed
2015-05-20 11:08:15: Starting execution sequence in -fork mode- for app name:myapp id:1
2015-05-20 11:08:15: App name:myapp id:1 online

The line "Change detected..." is printed when .git/FETCH_HEAD is updated.

I have found a workarround: I have moved the source code to another directory and sync with the app directory when there are new commits.

@soyuka
Copy link
Collaborator

soyuka commented May 21, 2015

I played with .git/FETCH_HEAD too. Just tried on my debian Wheezy with no issues. I have no Squeeze anymore :/.

Could you give me the debug output by doing:

export DEBUG="pm2:*" #revert with export DEBUG=
pm2 start your.json

What I'm interested in are those lines:

pm2:monit Before processing +7ms { script: 'test.js',
  node_args: undefined,
  ...
  watch: true,
  ignore_watch: undefined,
  watch_options: undefined,
  ...
  name: 'test' }
  pm2:monit After processing +2ms { errors: [],
  config:
   { script: 'test.js',
     name: 'test',
     vizion: true,
     autorestart: true,
     watch: true,
     exec_mode: 'fork_mode',
     exec_interpreter: 'node' } }
  pm2:monit { script: 'test.js', name: 'test', vizion: true, autorestart: true, watch: true, exec_mode: 'fork_mode', exec_interpreter: 'node' } +1ms

@crico
Copy link
Author

crico commented May 22, 2015

Hi,
this is my debug output:

pm2:constants PM2_ROOT_PATH: /root/.pm2 +0ms
  pm2:satan [PING PM2] Trying to connect to server +105ms
  pm2:satan Daemon alive +9ms
  pm2:satan Launching RPC client on port /root/.pm2/rpc.sock undefined +0ms
  pm2:satan Connected to Daemon +2ms
  pm2:cli Got message from Satan as succesfully connected to PM2, now parsing arguments +5ms
  pm2:satan Calling daemon method pm2:getVersion +0ms
  pm2:monit Before processing +7ms { name: 'myapp',
  script: 'bin/www',
  watch: true,
  ignore_watch: [ '[\\/\\\\]\\./', '.git/FETCH_HEAD', 'node_modules'],
  watch_options: { followSymlinks: false },
  log_date_format: 'YYYY-MM-DD HH:mm Z',
  merge_logs: true,
  exec_mode: 'fork_mode',
  exec_interpreter: 'none' }
  pm2:monit After processing +5ms { errors: [],
  config:
   { script: 'bin/www',
     name: 'myapp',
     merge_logs: true,
     watch: true,
     ignore_watch: [ '[\\/\\\\]\\./', '.git/FETCH_HEAD', 'node_modules'],
     watch_options: { followSymlinks: false },
     log_date_format: 'YYYY-MM-DD HH:mm Z',
     exec_mode: 'fork_mode',
     exec_interpreter: 'none' } }
  pm2:satan Calling daemon method pm2:prepare +4ms
[PM2] Process launched
  pm2:monit Getting interaction info +35ms
  pm2:interface:daemon [PING INTERACTOR] Trying to connect to Interactor daemon +0ms
  pm2:interface:daemon Interactor Daemon not launched +104ms
  pm2:satan Calling daemon method pm2:getMonitorData +0ms

I've been testing, and it seems that if I modify a file (manually), App isn't reload, it is as if the watch wasn't working (except for FETCH_HEAD git, just what I don't want ...)

@soyuka
Copy link
Collaborator

soyuka commented May 22, 2015

Thanks, everything seems to be fine :|.
Could you try with the default ignore_watch option? Just remove the key/value from your json.

@crico
Copy link
Author

crico commented May 25, 2015

Ouh! forget the last comment, it was my mistake; but I still get the same problem with ".git/FETCH_HEAD" :/

I found a workarround: I'm using a directory for build and other for deploy (without .git), and I manage when deploy dir must be sync.

Thanks for your time.

@crico
Copy link
Author

crico commented May 26, 2015

Other related question.

If I start pm2 with the 'processes.json' above, which is the scope of pm2-watch?
For example, in my local machine (osx), I modified app.js (express server file), but pm2 isn't reloaded (I tested with and without ignore_watch.

@soyuka
Copy link
Collaborator

soyuka commented May 26, 2015

I haven't understand your question, by scope are you talking about the working directory?
You may want to specify a full path to your app root:

{
    "apps" : [{
        "name" : "myapp",
        "script" : "bin/www",
        "cwd": "/Users/me/Sites/myapp",
        "watch" : true,
        "log_date_format" : "YYYY-MM-DD HH:mm Z",
        "merge_logs" : true
    }]
}

@crico
Copy link
Author

crico commented May 26, 2015

Yes, I'm talking about the app directory. I've specified a "cwd" but it doesn't work.
If a file (for example, my express-routes) into app directory is modified and saved, the pm2 doesn't reload the app :(, I don't understand which is the problem, because I understand that if any express file is changed, the app must be reloaded by pm2, right?

@soyuka
Copy link
Collaborator

soyuka commented May 26, 2015

Could you paste your processes.json again? Is your cwd an absolute path?

What is your osx version? On osx you'll be using FSEvents, so you could try to disable them:

watch_options: { useFsEvents: false }

See https://github.com/paulmillr/chokidar#performance.

@crico
Copy link
Author

crico commented May 26, 2015

My version is 10.10.3

{
    "apps" : [{
        "name" : "myapp",
        "script" : "bin/www",
        "cwd" : "/Users/crico/Workspaces/myapp",
        "watch" : true,
      "ignore_watch" : ["[\\/\\\\]\\./", "node_modules"],
        "watch_options": {
              "followSymlinks": false,
              "useFsEvents": false
        },
        "log_date_format" : "YYYY-MM-DD HH:mm Z",
        "merge_logs" : true
    }]
}

@crico
Copy link
Author

crico commented Jun 1, 2015

Finally, I discovered that my problem is in the "script" parameter. If I use the param:

  "script" : "bin/www",

watch doesn't work, but instead I use:

  "script" : "app.js",

watch works rightly. In both cases, I've launched pm2 from the root directory of my app:
+-- app.js
+-- Gruntfile.js
+-- node_modules
+-- processes.js
+-- ...

@crico crico closed this as completed Jun 4, 2015
@davidwhthomas
Copy link

davidwhthomas commented Jun 8, 2016

I'm using the "script" : "bin/www", startup script and found I needed to add this to the process.json file for the env setting

"env": { "args": ["--ignore-watch=\.git|node_modules"] }

The arg value is a regex string.

After that, watch would successfully ignore changes to the .git folder, avoiding such restart errors as:

"Change detected on path .git/index.lock for app [app_name] - restarting"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants