I am in a situation where Chef might start a service (postgres) but it might subsequently be stopped out-of-band. I want a subsequent Chef run to cause the service to be running. I have tried this:
service "postgresql" do
action :start
end
But it has no effect, saying (up to date)
presumably because Chef knows it has been started and isn't able to tell that it has stopped. (Possibly due to how service ... status
behaves for this service?) If I write this:
# anti-pattern warning!
execute "force-start-postgresql" do
command "service postgresql start || /etc/init.d/postgresql start"
action :run
end
I get the desired behaviour. Also an action :restart
makes it running. However these seem like anti-patterns due to portability (and potentially stopping it before starting it again in the latter case).
So, how can I tell Chef to forcibly start the service, even if it thinks it is already running?
This is using Chef 11.6, hosted by OpsCode, and the default postgresql recipe. (Note this is similar but I think not quite the same as How to force actions on "up to date" resources in Chef? .)
--- EDIT (clarification following jtimberland post) ---
The -l debug
here shows:
DEBUG: service[postgresql] supports status, running
DEBUG: service[postgresql] is running
Even when it is NOT running. So that sounds like one bug, and I'm interested in that. However I'm primarily interested in whether there is a way to tell Chef "always invoke the service start command, skipping the status check". That's the question here.
(I'm no expert but I think the most portable way to ensure a service is running is to start the service and that's nearly always idempotent. OTOH checking whether a service is running is less consistent and I don't see why we should care!)