Ensure server is started in Chef recipe

I am new to chef. I have a recipe where I need to start a server and then wait for the server to be successfully started. I have this so far;

service "myserver" do
  action :start
end

execute "ensure myserver startup" do
  command "curl http://#{node['myserver']['http']['host']}:#{node['myserver']['http']['port']}"
  retries 5
  retry_delay 15
end

This doesn't seem right to me and seems like a common thing for chef scripts to want to do. What is the idiomatically correct way to wait for a server to start up?

Answers


One other way is to use ruby block and use attributes to control the number of retries, sleep time between retries. This will also help in logging, raising errors. This is a sample code performing a similar problem. Here when the service comes up an entry is made in ZooKeeper as a znode and hence the ruby_block is checking for znode_exists?. You can replace it with curl.


Need Your Help