Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.83 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. #
  3. # $Id$
  4.  
  5. require 'mcollective'
  6.  
  7. include MCollective::RPC
  8.  
  9. options = rpcoptions do |parser, options|
  10.     parser.define_head "Manage remote backend webservers"
  11.     parser.banner = "Usage: bounce-backends"
  12.  
  13.     parser.separator ""
  14.     parser.separator "Run Options"
  15. end
  16.  
  17. mc = rpcclient("service", :options => options)
  18.  
  19. def log(msg)
  20.     puts("#{Time.now}> #{msg}")
  21. end
  22.  
  23. mc.class_filter /backend/
  24.  
  25. mc.progress = false
  26.  
  27. mc.discover(:verbose => true).each_with_index do |host,i|
  28.     sleep 10 if i > 0
  29.     result = mc.custom_request("restart", { :service => "httpd" }, host, { "identity" => host })
  30.     if result.is_a?(Array)
  31.         log("#{host} restart status: #{result[0][:statusmsg]}")
  32.     else
  33.         log("#{host} unknown output: #{result.pretty_inspect}")
  34.     end
  35. end
  36.  
  37. # vi:tabstop=4:expandtab:ai
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement