~ubuntu-branches/ubuntu/natty/mcollective/natty-201103250207

« back to all changes in this revision

Viewing changes to ext/ec2demo/start-mcollective-demo.rb

  • Committer: Dustin Kirkland
  • Date: 2011-02-17 19:07:47 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: kirkland@ubuntu.com-20110217190747-yym2bspvdu2nd8hg
Tags: 1.0.1-0ubuntu1
* Merge new upstream release
* debian/mcollective.install: drop unneeded /etc/init.d (we use upstart)
* debian/copyright: use Apache 2.0 header and point to common-license
  file, per Lintian

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env ruby
 
2
 
 
3
require 'rubygems'
 
4
require 'facter'
 
5
require 'passmakr'
 
6
 
 
7
Facter.reset
 
8
@facts = Facter.to_hash
 
9
 
 
10
def configure_mcollective(server, mcollective_password, psk=nil)
 
11
        unless psk
 
12
                pw = Passmakr.new(:phonemic, 8)
 
13
                psk = pw.password[:string]
 
14
        end
 
15
 
 
16
 
 
17
        ["server", "client"].each do |cfgfile|
 
18
                templ = File.readlines("/etc/mcollective/#{cfgfile}.cfg.templ")
 
19
 
 
20
                File.open("/etc/mcollective/#{cfgfile}.cfg", "w") do |f|
 
21
                        templ.each do |l|
 
22
                                l.gsub!("@@hostname@@", @facts["hostname"])
 
23
                                l.gsub!("@@server@@", server)
 
24
                                l.gsub!("@@psk@@", psk)
 
25
                                l.gsub!("@@mcollective_password@@", mcollective_password)
 
26
 
 
27
                                f.puts l
 
28
                        end
 
29
                end
 
30
        end
 
31
 
 
32
        puts("mcollective_psk=#{psk}") if @facts["mcollective"] == "server"
 
33
end
 
34
 
 
35
def configure_activemq(mcollective_password)
 
36
        templ = File.readlines("/etc/activemq/activemq.xml.templ")
 
37
 
 
38
        File.open("/etc/activemq/activemq.xml", "w") do |f|
 
39
                templ.each do |l|
 
40
                        l.gsub!("@@mcollective_password@@", mcollective_password)
 
41
 
 
42
                        f.puts l
 
43
                end
 
44
        end
 
45
end
 
46
 
 
47
if @facts.include?("mcollective")
 
48
        mcollective_type = @facts["mcollective"]
 
49
 
 
50
        if mcollective_type == "server"
 
51
                puts("Configuring MCollective as a server...")
 
52
 
 
53
                pw = Passmakr.new(:phonemic, 8)
 
54
                mcollective_password = pw.password[:string]
 
55
 
 
56
                puts("\n\n======= User Data for nodes ======")
 
57
                puts("mcollective=#{@facts['ipaddress']}")
 
58
                puts("mcollective_password=#{mcollective_password}")
 
59
 
 
60
                configure_mcollective("localhost", mcollective_password)
 
61
                configure_activemq(mcollective_password)
 
62
                puts("==================================")
 
63
 
 
64
                puts;puts
 
65
 
 
66
                system("/etc/init.d/activemq restart")
 
67
 
 
68
                puts("\nSleeping 10 seconds...")
 
69
                sleep 10
 
70
 
 
71
                system("cp /root/mcollective-plugins-read-only/agent/registration-monitor/registration.rb /usr/libexec/mcollective/mcollective/agent/")
 
72
 
 
73
                puts("Starting MCollective....")
 
74
                system("/etc/init.d/mcollective restart")
 
75
        elsif mcollective_type =~ /\d+\.\d+\.\d+\.\d+/
 
76
                unless @facts.include?("mcollective_password") && @facts.include?("mcollective_psk")
 
77
                        STDERR.puts("mcollective_password and mcollective_psk user data was not set")
 
78
                        exit 1
 
79
                end
 
80
 
 
81
                puts("Configuring MCollective as a node with server @ #{mcollective_type}...")
 
82
 
 
83
                mcollective_password = @facts["mcollective_password"]
 
84
                mcollective_psk = @facts["mcollective_psk"]
 
85
 
 
86
                configure_mcollective(mcollective_type, mcollective_password, mcollective_psk)
 
87
                system("/etc/init.d/mcollective restart")
 
88
 
 
89
                system("cp /usr/local/etc/mcollective-node.motd /etc/motd")
 
90
        end
 
91
else
 
92
        STDERR.puts("Please set mcollective=server|1.2.3.4 user data")
 
93
        exit 1
 
94
end