salt: service does not restart after watched config
os: opensuse service_provider: rh_service salt-call --versions-report Salt: 2014.1.5 Python: 2.7.2 (default, Aug 19 2011, 20:41:43) [GCC] Jinja2: 2.6 M2Crypto: 0.21.1 msgpack-python: 0.2.4 msgpack-pure: Not Installed pycrypto: 2.3 PyYAML: 3.10 PyZMQ: 13.0.0 ZMQ: 3.2.2
scenario:
- on opensuse install postgresql-server package,
- start service so it’s generate default configs in /var/lib/pgsql
- edit pg_hba with file.replace
- expect service restart, but it just check if postgresql running and returns true
if we edit pg_hba so file.replace runs again then service restarts ok, but not for the first run. I think it’s somehow related to postgres_first_run starting service, but can’t find anything relevant in the logs
example states from debug output:
postgresql:
pkg:
- installed
- name: postgresql-server
service:
- running
- enable: True
- watch:
- file: /var/lib/pgsql/data/pg_hba.conf
/var/lib/pgsql/data/pg_hba.conf:
file.replace:
- pattern: (^host.*127\.0\.0\.1/32\s*).*$
- repl: \1md5
- watch:
- pkg: postgresql
postgres_first_run:
cmd.wait:
- name: /etc/init.d/postgresql start >/dev/null 2>&1; sleep 5; echo -e '\nchanged=yes\n'
- stateful: True
- watch:
- pkg: postgresql
- watch_in:
- file: /var/lib/pgsql/data/pg_hba.conf
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Reactions: 1
- Comments: 66 (42 by maintainers)
Commits related to this issue
- Allow automatic plugins installation service restart in jenkins/plugins.sls doesn't work at the moment (see https://github.com/saltstack/salt/issues/14183) — committed to dlax/jenkins-formula by deleted user 9 years ago
- Allow automatic plugins installation service restart in jenkins/plugins.sls doesn't work at the moment (see https://github.com/saltstack/salt/issues/14183) — committed to dlax/jenkins-formula by deleted user 9 years ago
@cmclaughlin Okay, so I discovered that you are definitely finding some unexpected behavior! It took a while for me to nail down exactly what’s happening - I’m not sure if it’s just a bug in our documentation, or if it’s an actual bug.
What’s happening here is kind of crazy.
If you remove the
enable: True
, or split it intoEverything works 🎉
The question you might have then is, “Buy why??”
Which is a darn good question 🤣
Turns out that the answer is pretty simple though - the only thing that’s going wrong here is that by starting (but not enabling) a service, when Salt looks at the service it says, “Ah, yeah, running is good. Oh, but let me enable this service. Cool, I’ve made some changes to it. What, you have a watch? No, I don’t need to do anything, I’ve already changed this service!”
Oops :trollface:
I definitely agree that it seems strange, or perhaps even unintuitive, but it is at least consistent, and now I understand exactly why 🙂
Just a had a quick conversation, and this is definitely intended behavior - I’m going to see about adding some information to our docs that calls it out, and perhaps gives some better explanation.
This is a 4 year old bug and it still exists in the latest version 2018.3.2. Any idea when or whether this will get a fix? @basepi @rallytime
Here is an extract of my state file:
in apache/install.sls:
in apache/site.sls:
I cannot see what is wrong with it.
As a temporary by-pass I put in apache/install.sls this extra state (on changes is just there to ensure it is not launched if nothing is changed):
and in apache/site.sls:
And it works fine.
I cannot figure out what is wrong in my first version.
@waynew I finally had time to come up with a streamlined setup of what we are doing here when the problem occurs. I’m attaching a tarball that makes it 100% reproducible with the help of terraform and aws (only free tier resources are used). Running the
exhibit.sh
script will do the trick and it should be fairly easy to follow.In short, it spins up an ubuntu server, install the latest salt in master-less mode and copy the states files and pillar and apply the highstate. Then it will change a pillar value and re-apply the highstate at which time the bug will be triggered and the service not-restarted as expected.
In this case, it boils down to a bad interaction between
onchanges
andwatch
. Here is the sls for reference:After changing the pillar, the
salt-call
output is:As you can see, the
test_systemd_unit
is triggered and produces changes which is picked-up by theonchanges
onmodule.run
that does reload the systemd unit file but then thetest_running
state is not triggered, pretending thatnone of the onchanges reqs changed
. This is technically true as itsonchanges
points to thefile.managed
of/tmp/test/index.html
which didn’t change but it happily ignores thewatch
which does trigger it correctly if you remove theonchanges_in
of theindex.html
.Cheers,
Olivier
Thanks for your patience… I’m all over the place on this one. Maybe my internal code doesn’t match up with the tests we’ve come up with here. I’ll take a closer look at my internal Salt code and see if I can track down the problem.
Same here… Amazon Linux and Apache. My scenario is:
service.running
watch_in
on the serviceHowever, editing the config file or cert after the initial write to the filesystem and re-applying the state does restart the service. At least it my case, it seems
watch_in
only applies to changes to existing files.