구성
배포
cd /usr/share/ruby/vendor_ruby/mcollective/application
wget https://raw.githubusercontent.com/arnobroekhof/mcollective-plugin-power/master/application/power.rb
과
cd /usr/libexec/mcollective/mcollective/agent
wget https://raw.githubusercontent.com/arnobroekhof/mcollective-plugin-power/master/agent/power.ddl
wget https://raw.githubusercontent.com/arnobroekhof/mcollective-plugin-power/master/agent/power.rb
두 호스트 모두, 즉 test-server1
및 test-server2
.
서비스
두 서비스 모두에서 mcollective를 다시 시작하십시오.
[vagrant@test-server1 ~]# sudo service mcollective restart
과
[vagrant@test-server2 ~]# sudo service mcollective restart
명령
mcollective 서버 노드에서 다음 명령을 실행하십시오.
호스트 test-server2
가 듣고 있습니다 :
[vagrant@test-server1 ~]$ mco ping
test-server2 time=25.32 ms
test-server1 time=62.51 ms
---- ping statistics ----
2 replies max: 62.51 min: 25.32 avg: 43.91
test-server2
:를 재부팅
[vagrant@test-server1 ~]$ mco power reboot -I test-server2
* [ ============================================================> ] 1 / 1
test-server2 Reboot initiated
Finished processing 1 / 1 hosts in 123.94 ms
는 test-server2
재부팅입니다 :
[vagrant@test-server1 ~]$ mco ping
test-server1 time=13.87 ms
---- ping statistics ----
1 replies max: 13.87 min: 13.87 avg: 13.87
그리고 재부팅되었습니다 :
[vagrant@test-server1 ~]$ mco ping
test-server1 time=22.88 ms
test-server2 time=54.27 ms
---- ping statistics ----
2 replies max: 54.27 min: 22.88 avg: 38.57
호스트도 종료 할 수 있습니다.
[vagrant@test-server1 ~]$ mco power shutdown -I test-server2
* [ ============================================================> ] 1 / 1
test-server2 Shutdown initiated
Finished processing 1 / 1 hosts in 213.18 ms
원본 코드
/usr/libexec/mcollective/mcollective/agent/power.rb
module MCollective
module Agent
class Power<RPC::Agent
action "shutdown" do
out = ""
run("/sbin/shutdown -h now", :stdout => out, :chomp => true )
reply[:output] = "Shutdown initiated"
end
action "reboot" do
out = ""
run("/sbin/shutdown -r now", :stdout => out, :chomp => true )
reply[:output] = "Reboot initiated"
end
end
end
end
# vi:tabstop=2:expandtab:ai:filetype=ruby
/usr/libexec/mcollective/mcollective/agent/power.ddl
metadata :name => "power",
:description => "An agent that can shutdown or reboot them system",
:author => "A.Broekhof",
:license => "Apache 2",
:version => "2.1",
:url => "http://github.com/arnobroekhof/mcollective-plugins/wiki",
:timeout => 5
action "reboot", :description => "Reboots the system" do
display :always
output :output,
:description => "Reboot the system",
:display_as => "Power"
end
action "shutdown", :description => "Shutdown the system" do
display :always
output :output,
:description => "Shutdown the system",
:display_as => "Power"
end
/usr/share/ruby/vendor_ruby/mcollective/application/power.rb
class MCollective::Application::Power<MCollective::Application
description "Linux Power broker"
usage "power [reboot|shutdown]"
def post_option_parser(configuration)
if ARGV.size == 1
configuration[:command] = ARGV.shift
end
end
def validate_configuration(configuration)
raise "Command should be one of reboot or shutdown" unless configuration[:command] =~ /^shutdown|reboot$/
end
def main
mc = rpcclient("power")
mc.discover :verbose => true
mc.send(configuration[:command]).each do |node|
case configuration[:command]
when "reboot"
printf("%-40s %s\n", node[:sender], node[:data][:output])
when "shutdown"
printf("%-40s %s\n", node[:sender], node[:data][:output])
end
end
printrpcstats
mc.disconnect
end
end
# vi:tabstop=2:expandtab:ai
수정 된 코드
/usr/libexec/mcollective/mcollective/agent/power.ddl
metadata :name => "power",
:description => "An agent that can shutdown or reboot them system",
:author => "A.Broekhof",
:license => "Apache 2",
:version => "2.1",
:url => "http://github.com/arnobroekhof/mcollective-plugins/wiki",
:timeout => 5
action "update-and-reboot", :description => "Reboots the system" do
display :always
output :output,
:description => "Reboot the system",
:display_as => "Power"
end
/usr/libexec/mcollective/mcollective/agent/power.rb
module MCollective
module Agent
class Power<RPC::Agent
action "update-and-reboot" do
out = ""
run("yum update -y && /sbin/shutdown -r now", :stdout => out, :chomp => true )
reply[:output] = "Reboot initiated"
end
end
end
end
# vi:tabstop=2:expandtab:ai:filetype=ruby
명령
[vagrant@test-server1 ~]$ mco power update-and-reboot -I test-server2
* [ ============================================================> ] 1 / 1
Finished processing 1 / 1 hosts in 1001.22 ms