2

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?

Ryan
  • 21
  • 3

2 Answers2

1

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

```

KCD
  • 958
  • 3
  • 12
  • 24
0

Use resource subscription to maintain execution order.

Use retries to make sure application installation works, and you can run resource bash[install application] at the end of chef runs via subscribes :run, "service[jboss]", :delayed

bash "install application" do
  code <<-EOF
  ant install
  EOF
  action :nothing
  retries 3
  subscribes :run, "service[jboss]", :delayed 
end
shawnzhu
  • 653
  • 4
  • 10
  • checking this one.. got two versions, 1st using ruby_block and this one. will keep you posted thanks – Ryan Oct 21 '13 at 09:52
  • hmm.. that didnt do it. jboss didnt start. – Ryan Oct 22 '13 at 07:12
  • what about the resource "bash[bootstrap application]"? you can't start jboss if bootstrap fails. – shawnzhu Oct 22 '13 at 13:45
  • This is the official way to do things, using `notifies` or `subscribes`, but the trouble with many Java (and other) services is their wrapper returns "SUCCESS" immediately, even though the actual initialization of the process takes another minute (or few). The hard sleep of another answer is one way to test, though the curl/wget probe of the expected open port can be a better and more surefire way to ensure any web/network services are fully started before moving on. – dragon788 Oct 08 '18 at 15:21