21

I would like the nginx service to restart whenever any file in the /etc/nginx/conf.d directory is created or modified.

There are a number of files in that directory, and rather than specifying particular files, I would like to watch for all changes.

I've tried this:

nginx:
  pkg.installed:
    - name: nginx
  service:
    - running
    - enable: True
    - restart: True
    - watch:
      - file: /etc/nginx/nginx.conf
      - file: /etc/nginx/conf.d
      - pkg: nginx

but the line - file: /etc/nginx/conf.d is not doing what I want.

This is the error:

      ID: nginx
Function: service.running
  Result: False
 Comment: The following requisites were not found:
                             watch:
                                 file: /etc/nginx/conf.d
 Changes: 

I've also tried a number of variations including a trailing slash, but none of them work.

What should - file: /etc/nginx/conf.d/ be changed to?

coffee-grinder
  • 26,940
  • 19
  • 56
  • 82

2 Answers2

26

I'm using a glob for matching:

file: /etc/nginx/conf.d/*

Here's the corrected snippet:

nginx:
  pkg.installed:
    - name: nginx
  service:
    - running
    - enable: True
    - restart: True
    - watch:
      - file: /etc/nginx/nginx.conf
      - file: /etc/nginx/conf.d/*
      - pkg: nginx

Also do note that salt can only watch other states that are already specified in your state file, so it will only watch files that are managed by salt itself.

If this doesn't work for you, then try to refer the following link for a different solution: http://intothesaltmine.org/blog/html/2012/12/18/using_watch_with_file_recurse.html

nmadhok
  • 1,704
  • 3
  • 16
  • 20
  • 1
    I'm in the same position as the OP, and for the same reason. And I'm using a solution just like the one you present. But it still isn't working right. In particular, `watch` only triggers a reload when a file in `conf.d` changes, not when the file is added to `conf.d`. I think. I'm still trying to debug this. – nomen Jul 24 '14 at 17:09
2

According to issue 663 closed in February 2012, a watch on /path/* should watch recursively.

Chris Martin
  • 30,334
  • 10
  • 78
  • 137