Pergunta

I was reading https://serverfault.com/questions/378520/chef-stop-and-start-service-in-sequence and would like to ask different procedure.

Step 1: framework bootstrap to jboss service

bash "bootstrap application" do
    code <<-EOF
    ant bootstrap
    EOF
end

Step 2: then start jboss

service "jboss" do
    action :start
end

Step 3: install application

bash "install application" do
    code <<-EOF
    ant install
    EOF
end

in between step 2 and 3, ant install returns error because jboss is not started yet. But successful on the 2nd run. Obviously step 3 doesnt know if the jboss already started.

How to do this on chef?

Foi útil?

Solução

ok i have done this from ruby_block

# for managing service
# jboss block until operational
ruby_block "block_until_operational" do
  block do
    until IO.popen("netstat -lnt").entries.select { |entry|
        entry.split[3] =~ /:#{node[:jboss][:default_port]}$/
      }.size == 1   
      Chef::Log.debug "service[jboss] not listening on port #{node[:jboss][:default_port]}"
      sleep 1
    end
  end
  action :nothing
end

i created this ruby block that would listen to port 8080 until it returns 1 (started) and called this via

service "jboss" do
    action :start
    notifies :create, 'ruby_block[block_until_operational]', :immediate
end
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top