daily pastebin goal
5%
SHARE
TWEET

Untitled

a guest Jul 19th, 2018 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. begin
  2.   require 'sys/proctable'
  3. rescue LoadError
  4.   Chef::Log.warn("Missing gem 'sys-proctable'")
  5. end
  6.  
  7. require 'timeout'
  8.  
  9. module Rackspace
  10.   def self.getProcPid(name)
  11.     Sys::ProcTable.ps do |p|
  12.       if /#{name}/ =~ p.cmdline
  13.         return p.pid
  14.       end
  15.     end
  16.   end
  17.  
  18.   def self.wait_on_proc(name, timeout_sec = 60)
  19.     begin
  20.       Timeout::timeout(params[:timeout_sec]) do
  21.         while getProcPid(name)
  22.           sleep(5)
  23.         end
  24.       end
  25.     rescue
  26.       Chef::Log.warn("Process #{name} is taking too long, move along!")
  27.       #Chef::Application.fatal!("Process #{params[:name]} is taking too long, I quit!", -8008)
  28.     end
  29.   end
  30.  
  31.   def self.is_proc(name, timeout_sec = 60)
  32.     if getProcPid(name)
  33.       Chef::Log.info("libcloud deployment script running.")
  34.       Chef::Log.info("Sleeping for up to #{timeout_sec} seconds...")
  35.       wait_on_proc(name,timeout_sec)
  36.     end
  37.   end
  38. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top