Skip to content

Instantly share code, notes, and snippets.

@schisamo
Forked from gondoi/proc.rb
Created January 4, 2011 01:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schisamo/764267 to your computer and use it in GitHub Desktop.
Save schisamo/764267 to your computer and use it in GitHub Desktop.
require 'timeout'
include Rackspace::Proc
define :wait_on_proc, :timeout_sec => 60 do
include_recipe "rackspace"
begin
Timeout::timeout(params[:timeout_sec]) do
while getProcPid(params[:name])
sleep(5)
end
end
rescue
Chef::Log.warn("Process #{params[:name]} is taking too long, move along!")
#Chef::Application.fatal!("Process #{params[:name]} is taking too long, I quit!", -8008)
end
end
define :is_proc, :timeout_sec => 60 do
include_recipe "rackspace"
if getProcPid(params[:name])
Chef::Log.info("libcloud deployment script running.")
Chef::Log.info("Sleeping for up to #{params[:timeout_sec]} seconds...")
wait_on_proc params[:name] do
timeout_sec params[:timeout_sec]
end
end
end
begin
require 'sys/proctable'
rescue LoadError
Chef::Log.warn("Missing gem 'sys-proctable'")
end
module Rackspace
module Proc
def getProcPid(name)
Sys::ProcTable.ps{ |p|
if /#{name}/ =~ p.cmdline
return p.pid
end
}
end
end
end
# force the gem to be installed during the compile phase
# of the chef run
r = gem_package "sys-proctable" do
action :nothing
end
r.run_action(:install)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment