# Guard and Guard Interpreter for ruby\_block

**URL:** <https://discourse.chef.io/t/guard-and-guard-interpreter-for-ruby-block/7536>\
**Category:** Chef Infra (archive)\
**Created:** [December 31, 2015, 2:17am UTC](https://discourse.chef.io/t/guard-and-guard-interpreter-for-ruby-block/7536 "2015-12-31T02:17:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![aravind](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/aravind/32/1199_2.png) [@aravind](https://discourse.chef.io/u/aravind)\
**Post date:** [December 31, 2015, 2:17am UTC](https://discourse.chef.io/t/guard-and-guard-interpreter-for-ruby-block/7536/1 "2015-12-31T02:17:05Z")

</div>

Hi,

[https://docs.chef.io/resource\_ruby\_block.html](https://docs.chef.io/resource_ruby_block.html)

Is it just me or am I correct in assuming that ruby\_block does NOT support guard/guard interpreter?

I am trying to execute 2 resources (one a execute resource and another a ruby\_block) and i want both these resources to NOT RUN if the PID is already up and running…

```
execute 'Start Weblogic Node Manager' do
  guard_interpreter :bash
  user node['weblogic']['user']
  group node['weblogic']['group']
  cwd node['weblogic']['user_project_bin']

  #This PID runs in the foreground by default, so need to use nohup & to run as a background process
  command "nohup ./startNodeManager.sh > chef_start_nodemanager.log 2>&1 &"

  # grep exits with 1 when no match is found. This resource is executed when not_if returns false i.e exit code is != 0 from bash script
  # So, this resource is run if grep doesn't find a match
  not_if 'ps -ef | grep weblogic.NodeManager | grep -v grep'
end

#Only run the below block if the SAME guard as above is false.....can that be done??   
ruby_block "Wait until Node Manager has started" do
  block do
     until File.readlines("#{node['weblogic']['domainhome']}/bin/chef_start_nodemanager.log").grep(/Plain socket listener started on port 5556, host localhost/).size > 0
         Chef::Log.info('sleeping 3 seconds until grep condition true')
         sleep 3
     end
  end
end

```

However, looking at the [ruby\_block documentation](https://docs.chef.io/resource_ruby_block.html), there is no mention of a guard\_interpreter/guard, so just checking if its supported.

Cheers

---

<div class="post-metadata">

**Author:** ![martinb3](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/martinb3/32/34_2.png) [@martinb3](https://discourse.chef.io/u/martinb3)\
**Post date:** [December 31, 2015, 2:46am UTC](https://discourse.chef.io/t/guard-and-guard-interpreter-for-ruby-block/7536/2 "2015-12-31T02:46:10Z")

</div>

Hi there – the guard functionality should included in all built-in resources. Are you actually seeing a problem? It should _just work_.

---

<div class="post-metadata">

**Author:** ![yoshiwaan](https://avatars.discourse-cdn.com/v4/letter/y/ba9def/32.png) [@yoshiwaan](https://discourse.chef.io/u/yoshiwaan)\
**Post date:** [December 31, 2015, 4:11am UTC](https://discourse.chef.io/t/guard-and-guard-interpreter-for-ruby-block/7536/3 "2015-12-31T04:11:07Z")

</div>

FYI [https://docs.chef.io/resource.html#common-functionality](https://docs.chef.io/resource.html#common-functionality)

---

<div class="post-metadata">

**Author:** ![aravind](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/aravind/32/1199_2.png) [@aravind](https://discourse.chef.io/u/aravind)\
**Post date:** [December 31, 2015, 4:24am UTC](https://discourse.chef.io/t/guard-and-guard-interpreter-for-ruby-block/7536/4 "2015-12-31T04:24:56Z")

</div>

Thank you. I think I got confused because I was expecting a Guards section within [https://docs.chef.io/resource\_ruby\_block.html](https://docs.chef.io/resource_ruby_block.html) similar to how [https://docs.chef.io/resource\_ruby.html](https://docs.chef.io/resource_ruby.html) does.

---

<div class="post-metadata">

**Author:** ![Tensibai](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/tensibai/32/29_2.png) [@Tensibai](https://discourse.chef.io/u/Tensibai)\
**Post date:** [December 31, 2015, 8:36am UTC](https://discourse.chef.io/t/guard-and-guard-interpreter-for-ruby-block/7536/5 "2015-12-31T08:36:49Z")

</div>

> [@aravind](#):
>
> `not_if 'ps -ef | grep weblogic.NodeManager | grep -v grep'`

A little off topic, but worth noting the `| grep -v grep` is easy to avoid.  
Try with `not_if 'ps -ef | grep "[w]eblogic.NodeManager"'`  
Using the brackets tell grep to match the same as you did but its own command line won't match as there will be brackets inside it.

---

<div class="post-metadata">

**Author:** ![coderanger](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/coderanger/32/5_2.png) [@coderanger](https://discourse.chef.io/u/coderanger)\
**Post date:** [December 31, 2015, 8:46am UTC](https://discourse.chef.io/t/guard-and-guard-interpreter-for-ruby-block/7536/6 "2015-12-31T08:46:19Z")

</div>

Please don’t start services like this. Check out [poise-service](https://github.com/poise/poise-service) for an easy way to convert this into a real service management system.
