Chef deploy start service and restart service in sequence

chefchef-solo

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?

Best Answer

Stumbled on this by mistake but it looks like a similar issue I had with rundeck... is your service starting but not started?

Try testing this

service "jboss" do
    start_command 'service jboss start && sleep 30'
    action :start
end

For rundeck it was the restart I had issues with and used curl to probe it until it was up.

service 'rundeckd' do
  restart_command 'service rundeckd restart && RETRIES=0 && until curl localhost:4440 || [ $RETRIES -eq 30 ]; do (( RETRIES++ )); sleep 5; done'
  action :start
end

```