Execute bash command

Hi all,

I’ve written my first custom resource to remove an omd site, I’m
trying to include an echo in my execute statement as the application
requires user input. My provider looks like this:

#----------
action :remove do
execute “remove-site” do
command “echo -e ‘yes’ | /usr/bin/omd rm #{new_resource.site_name}“
only_if { ::File.directory?(”/opt/omd/sites/#{new_resource.site_name}”) }
end
end
#----------

Then my recipe:

#----------
omd_site ‘test’ do
action :remove
end
#----------

The chef-client shows the following and succeeds, but the site is
never removed.

  • execute echo -e ‘yes’ | /usr/bin/omd rm test

If I run the command manually everything works as expected. Below is
the output.


PLEASE NOTE: This action removes all configuration files
and variable data of the site.

In detail the following steps will be done:

  • Stop all processes of the site
  • Unmount tmpfs of the site
  • Remove tmpfs of the site from fstab
  • Remove the system user
  • Remove the system group
  • Remove the site home directory
  • Restart the system wide apache daemon
    (yes/NO): Removing Crontab…
    no crontab for test
    Stopping dedicated Apache for site test…(not running)…OK
    Stopping nagios…not running…OK
    npcd was not running… could not stop
    Stopping rrdcached…not running.
    Unmounting temporary filesystem…OK
    Removing /omd/sites/test/tmp from /etc/fstab…OK
    Deleting user and group test…OK
    Restarting Apache…[Mon Nov 24 11:26:25.553556 2014]
    [proxy_html:notice] [pid 25995:tid 140261059786624] AH01425: I18n
    support in mod_proxy_html requires mod_xml2enc. Without it, non-ASCII
    characters in proxied pages are likely to display incorrectly.
    AH00558: apache2: Could not reliably determine the server’s fully
    qualified domain name, using 127.0.1.1. Set the ‘ServerName’ directive
    globally to suppress this message
    OK

I assume the problem is with the echo statement. Any ideas?

Regards,
Gareth

Hey Gareth - can you try not using a custom resource and instead just plugging the execute “remove-site” code you have in place of the omd_site? If that still has issues, then yes, I think it is a problem with the echo or the only_if. What does your log show when you do this?

This is just a troubleshooting step to make sure there is not a bug with the custom resource.

-T

On Nov 24, 2014, at 1:29 AM, Gareth Allen gallen@openworld.co.za wrote:

Hi all,

I've written my first custom resource to remove an omd site, I'm
trying to include an echo in my execute statement as the application
requires user input. My provider looks like this:

#----------
action :remove do
execute "remove-site" do
command "echo -e 'yes' | /usr/bin/omd rm #{new_resource.site_name}"
only_if { ::File.directory?("/opt/omd/sites/#{new_resource.site_name}") }
end
end
#----------

Then my recipe:

#----------
omd_site 'test' do
action :remove
end
#----------

The chef-client shows the following and succeeds, but the site is
never removed.

  • execute echo -e 'yes' | /usr/bin/omd rm test

If I run the command manually everything works as expected. Below is
the output.


PLEASE NOTE: This action removes all configuration files
and variable data of the site.

In detail the following steps will be done:

  • Stop all processes of the site
  • Unmount tmpfs of the site
  • Remove tmpfs of the site from fstab
  • Remove the system user
  • Remove the system group
  • Remove the site home directory
  • Restart the system wide apache daemon
    (yes/NO): Removing Crontab...
    no crontab for test
    Stopping dedicated Apache for site test...(not running)...OK
    Stopping nagios...not running...OK
    npcd was not running... could not stop
    Stopping rrdcached...not running.
    Unmounting temporary filesystem...OK
    Removing /omd/sites/test/tmp from /etc/fstab...OK
    Deleting user and group test...OK
    Restarting Apache...[Mon Nov 24 11:26:25.553556 2014]
    [proxy_html:notice] [pid 25995:tid 140261059786624] AH01425: I18n
    support in mod_proxy_html requires mod_xml2enc. Without it, non-ASCII
    characters in proxied pages are likely to display incorrectly.
    AH00558: apache2: Could not reliably determine the server's fully
    qualified domain name, using 127.0.1.1. Set the 'ServerName' directive
    globally to suppress this message
    OK

I assume the problem is with the echo statement. Any ideas?

Regards,
Gareth

On Monday, November 24, 2014 at 1:29 AM, Gareth Allen wrote:

Hi all,

I've written my first custom resource to remove an omd site, I'm
trying to include an echo in my execute statement as the application
requires user input. My provider looks like this:

#----------
action :remove do
execute "remove-site" do
command "echo -e 'yes' | /usr/bin/omd rm #{new_resource.site_name}"
only_if { ::File.directory?("/opt/omd/sites/#{new_resource.site_name}") }
end
end
#----------

Then my recipe:

#----------
omd_site 'test' do
action :remove
end
#----------

The chef-client shows the following and succeeds, but the site is
never removed.

  • execute echo -e 'yes' | /usr/bin/omd rm test

If I run the command manually everything works as expected. Below is
the output.


PLEASE NOTE: This action removes all configuration files
and variable data of the site.

In detail the following steps will be done:

  • Stop all processes of the site
  • Unmount tmpfs of the site
  • Remove tmpfs of the site from fstab
  • Remove the system user
  • Remove the system group
  • Remove the site home directory
  • Restart the system wide apache daemon
    (yes/NO): Removing Crontab...
    no crontab for test
    Stopping dedicated Apache for site test...(not running)...OK
    Stopping nagios...not running...OK
    npcd was not running... could not stop
    Stopping rrdcached...not running.
    Unmounting temporary filesystem...OK
    Removing /omd/sites/test/tmp from /etc/fstab...OK
    Deleting user and group test...OK
    Restarting Apache...[Mon Nov 24 11:26:25.553556 2014]
    [proxy_html:notice] [pid 25995:tid 140261059786624] AH01425: I18n
    support in mod_proxy_html requires mod_xml2enc. Without it, non-ASCII
    characters in proxied pages are likely to display incorrectly.
    AH00558: apache2: Could not reliably determine the server's fully
    qualified domain name, using 127.0.1.1. Set the 'ServerName' directive
    globally to suppress this message
    OK

Is this the output you expect? Is there anything different that you see when you run it by hand?

I assume the problem is with the echo statement. Any ideas?
Could it be something as simple as code in another recipe re-creating the site?

If it is a problem with giving data to the command’s stdin, you could try using mixlib-shellout’s input feature instead of echoing to a pipe. We were missing API documentation for this feature, but I added some just now: Document input and live stream options to `new` by danielsdeleo · Pull Request #75 · chef/mixlib-shellout · GitHub

Regards,
Gareth

HTH,
Dan DeLeo