Skip to content

Instantly share code, notes, and snippets.

@schisamo
Forked from gondoi/library_proctable.rb
Created January 4, 2011 23:11
Show Gist options
  • Save schisamo/765633 to your computer and use it in GitHub Desktop.
Save schisamo/765633 to your computer and use it in GitHub Desktop.
i = gem_package "sys-proctable" do
action :nothing
end
i.run_action(:install)
require 'rubygems'
Gem.clear_paths
require 'sys/proctable'
Rackspace.is_proc("deployment.*sh", 300)
[Tue, 04 Jan 2011 22:13:10 +0000] ERROR: Re-raising exception: NameError - uninitialized constant Sys
/tmp/chef-solo/cookbooks/rackspace/libraries/proctable.rb:27:in `getProcPid'
/tmp/chef-solo/cookbooks/rackspace/libraries/proctable.rb:48:in `is_proc'
/tmp/chef-solo/cookbooks/rackspace/recipes/mckick.rb:16:in `from_file'
/opt/ruby/lib/ruby/gems/chef-0.9.8/lib/chef/mixin/from_file.rb:30:in `instance_eval'
/opt/ruby/lib/ruby/gems/chef-0.9.8/lib/chef/mixin/from_file.rb:30:in `from_file'
/opt/ruby/lib/ruby/gems/chef-0.9.8/lib/chef/cookbook_version.rb:337:in `load_recipe'
/opt/ruby/lib/ruby/gems/chef-0.9.8/lib/chef/mixin/language_include_recipe.rb:40:in `block in include_recipe'
/opt/ruby/lib/ruby/gems/chef-0.9.8/lib/chef/mixin/language_include_recipe.rb:27:in `each'
/opt/ruby/lib/ruby/gems/chef-0.9.8/lib/chef/mixin/language_include_recipe.rb:27:in `include_recipe'
/opt/ruby/lib/ruby/gems/chef-0.9.8/lib/chef/run_context.rb:94:in `block in load'
/opt/ruby/lib/ruby/gems/chef-0.9.8/lib/chef/run_context.rb:91:in `each'
/opt/ruby/lib/ruby/gems/chef-0.9.8/lib/chef/run_context.rb:91:in `load'
/opt/ruby/lib/ruby/gems/chef-0.9.8/lib/chef/run_context.rb:55:in `initialize'
/opt/ruby/lib/ruby/gems/chef-0.9.8/lib/chef/client.rb:84:in `new'
/opt/ruby/lib/ruby/gems/chef-0.9.8/lib/chef/client.rb:84:in `run'
/opt/ruby/lib/ruby/gems/chef-0.9.8/lib/chef/application/solo.rb:191:in `block in run_application'
/opt/ruby/lib/ruby/gems/chef-0.9.8/lib/chef/application/solo.rb:181:in `loop'
/opt/ruby/lib/ruby/gems/chef-0.9.8/lib/chef/application/solo.rb:181:in `run_application'
/opt/ruby/lib/ruby/gems/chef-0.9.8/lib/chef/application.rb:62:in `run'
/opt/ruby/lib/ruby/gems/chef-0.9.8/bin/chef-solo:25:in `<top (required)>'
/opt/ruby/lib/ruby/bin/chef-solo:19:in `load'
/opt/ruby/lib/ruby/bin/chef-solo:19:in `<main>'
begin
require 'sys/proctable'
rescue LoadError
Chef::Log.warn("Missing gem 'sys-proctable'")
end
require 'timeout'
module Rackspace
def self.getProcPid(name)
Sys::ProcTable.ps do |p|
if /#{name}/ =~ p.cmdline
return p.pid
end
end
end
def self.wait_on_proc(name, timeout_sec = 60)
begin
Timeout::timeout(params[:timeout_sec]) do
while getProcPid(name)
sleep(5)
end
end
rescue
Chef::Log.warn("Process #{name} is taking too long, move along!")
#Chef::Application.fatal!("Process #{params[:name]} is taking too long, I quit!", -8008)
end
end
def self.is_proc(name, timeout_sec = 60)
if getProcPid(name)
Chef::Log.info("libcloud deployment script running.")
Chef::Log.info("Sleeping for up to #{timeout_sec} seconds...")
wait_on_proc(name,timeout_sec)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment