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?
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
According to issue 663 closed in February 2012, a watch on /path/*
should watch recursively.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With