[chef] Re: best way to run something only once?


Chronological Thread 
  • From: Ameir Abdeldayem < >
  • To:
  • Subject: [chef] Re: best way to run something only once?
  • Date: Wed, 18 Jun 2014 19:39:35 -0400

Hi Tomasz,

Another thing you can do is touch a file in your bash code block, and in your bash resource, use 'creates'.  If the file is found, the code block will be skipped.


execute "upgrade script" do
  command "php upgrade-application.php && touch /var/application/.upgraded"
  creates "/var/application/.upgraded"
  action :run
end

More info:

Thanks,
Ameir


On Wed, Jun 18, 2014 at 6:34 PM, Tomasz Chmielewski < " target="_blank"> > wrote:
Does chef have some built-in way to run some recipes (or parts of it)
once only?

Say, I have the following (here, bash snippet, but could be anything):

bash 'adjust-supervisor' do
  code <<-EOF
     ...some_code...
  EOF
end


How would you approach to make sure it only runs once?

I figured I could use something like this in the recipe:

   not_if { ::File.exists?("/etc/chef/stamps/some-description.stamp") }

followed by:

file "/etc/chef/stamps/some-description.stamp" do
  owner "root"
  group "root"
  mode "0644"
  action :create
end


It allows me to easily re-run by removing the stamp file, if needed.


But not sure it's the optimal way to make sure we run a given thing
once.

How do you approach this?




--
Tomasz Chmielewski
http://www.sslrack.com




Archive powered by MHonArc 2.6.16.

§