Chef stop and start service in sequence

chefchef-solo

I have the following lines in my recipe

service "apache" do
  action :stop
end

# Do something..

service "apache" do
  action :start
end

I found that the 2nd block is not executed. Any reason?

Best Answer

The default for service starts and restarts is to save it all up to the end of the chef-client run. If you really want to have two service starts or restarts, then specify that they are to happen immediately:

service "apache" do 
  action :start, :immediately
end

It isn't usually a good idea to do this since multiple restarts can cause unnecessary service interruptions. That's why Chef tries to save up all the service restarts until the end of the run.

Related Topic