Chef - start or restart the service as needed

With the chef, how can I start the service if it does not work or reboots if it is?

I am running Ubuntu 12.04, and the service I'm currently working with is PostgreSQL. Stopping and starting almost everything works, but the chef seems to be trying to start it before he stops completely and fails.

+7
source share
2 answers

Usually you use action :start when installing the service to make sure that it works after the chef starts, see Service Resource .

When changing a file that requires a service restart to make the changes active, you use the actions :reload or :restart (depending on what the init script suggests). Then it looks like this:

 template "/etc/postgresql/pg.conf" do source "pg.conf.erb" notifies :restart, "service[postgres]" end 

Learn more about Notifications .

+3
source

Here is the code diagram that I used to conditionally execute one of several (repeated) actions like launching for a docker container. It can be adapted to the situation when the service starts (re) in the case when the advice on always restarting @ giannis-nohj does not work for any reason.

 my_file = file ... my_image = docker_image 'my-image' do repo 'my-image' action :pull end ruby_block 'compute docker action' do block do action = if my_image.updated_by_last_action? :redeploy elsif my_file.updated_by_last_action? :restart else :run end resources('docker_container[my-container]').delayed_action(action) end end docker_container 'my-container' do repo 'my-image' action :nothing end 
0
source

All Articles