首页 > 解决方案 > How to break or stop ruby_block running in loop cause of "subscribes"

问题描述

Hi have a recipe where I am trying to check if a service is running and accessible.

So I have a "ruby_block" which checks if service is running if not it "notifies" to "execute" block to start it, once execute block starts the service I need to again check if it running by calling "ruby_block" using "subscribes" But when service fails to start "ruby_block" goes in unstoppable loop.

Below is recipe which describes the workflow

ruby_block 'check_if_Service_running' do

  block do
    # ...some logic to check service

    # generates a return code 301 if successful or any other value if fails and 
    # assign it to an attribute check eg. value = return_code   
  end

  notifies :run, 'execute['start_service']', :immediately
  subscribes :run,'execute[Start_Service]', :immediately
end

execute 'Start_Service' do
  #...code to start the service

  
  action :nothing

  not_if { value == 301 }
end

So in this case when Services fails to start even after execute block, ruby_block keeps on running and notify "execute" block and so on

note: when service starts successfully it does show expected behavior

But some times when service does not start it goes in loop

Please help me here to stop "ruby_block" being going in loop cause of subscribes for more than 2 times and stop everything (loop) if service felt to start

Any help will be appreciated!

标签: rubychef-infra

解决方案


相反,创建一个自定义资源,您希望对事物进行比 DSL 提供的更明确的控制。


推荐阅读