Say I have a service on several servers, controled in a cluster way (heartbeat), disable (on startup) because I want it to run only on the active node:
haproxy:
service.disabled: []
I want to be able to update its configuration file:
/etc/haproxy/haproxy.cfg:
file.managed:
- source: salt://haproxy.cfg
- watch_in:
- service: haproxy
By specifying that this file is watched by the haproxy
service, it will trigger a service restart if this file is modified. That's what I would want, except that this service should be running only for the active server in the cluster.
So my question is: how can I achieve my goal to restart this service upon configuration modification, without starting it on all passive nodes?
The first question you have to answer is:
Then, instead of
watch_in
theservice
state, you can usecmd
state with anonlyif
condition, something like this:Not fully tested. Please let me know if it works for you.