public
Description: A new revision of Fuzed, the Erlang-based frontend for web apps. Check out the mailing list at http://groups.google.com/group/fuzed
Clone URL: git://github.com/KirinDave/fuzed.git
mojombo (author)
Sun May 11 18:28:32 -0700 2008
commit  6f4be433ed215bc983b5e4ac346b377c27c21b29
tree    fa3eaeca916dba29a8e4ccfcbb6e3c96d3447874
parent  e9db1600a675c78c970ecde8da2fc3ec8f83f3e2
fuzed / rlibs / cli / rails.rb
100644 114 lines (92 sloc) 3.683 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
def create_spec_list(options)
  spec_list = []
  result = "ruby "
  result.concat("-I#{FUZED_ROOT + "/rlibs "}")
  raise "You must specify a fuzed file to join the fuzed cluster!" unless options[:fuzedfile]
  result.concat(options[:fuzedfile] + " ")
  result.concat(%{--tags="#{options[:tags]}" }) if options[:tags]
  roles = []
  roles << "production" if options[:production]
  roles << options[:roles] if options[:roles]
  result.concat(%{--roles="#{roles.join(",")}"}) unless roles.empty?
  result.concat(%{ -- }) # Separates required arguments from optionals
  spec_list = if options[:spec]
    specs = options[:spec].split(/\|\|/)
    specs.map {|x| result + x}
  else
    [result]
  end
  spec_list.map {|x| x.gsub(%r|\\|,'\\\\\\').gsub(%r|([\"\'])|, '\\\\\1')} # Make sure to escape things properly.
end
 
options = {:fuzedfile => rel("rlibs/rails_node.rb")}
 
OptionParser.new do |opts|
  opts.banner = "Usage: fuzed command [options]"
  
  opts.on("-z HOSTNAME", "--magic HOSTNAME", "Set smart details based off of a hostname") do |n|
    options[:master_name] = "master@#{n}"
  end
  
  opts.on("-n NAME", "--name NAME", "Node name") do |n|
    options[:name] = n
  end
  
  opts.on("-m NAME", "--master NAME", "Master node name") do |n|
    options[:master_name] = n
  end
  
  opts.on("--rails-root RAILS_ROOT", "Location of the Rails root") do |n|
    options[:spec] = "--rails-root=#{n}"
  end
  
  opts.on("-c NUMNODES", "--clone NUMTIMES", "Number of clones of your spec to make") do |n|
    options[:num_nodes] = n
  end
  
  opts.on("-t", "--tags TAGSTRING", "Comma-separated list of tags to apply to any nodes started") do |n|
    options[:tags] = n
  end
  
  opts.on("-d", "--detached", "Run as a daemon") do
    options[:detached] = true
  end
  
  opts.on("-p", "--production", "Classify these nodes as production") do
    options[:production] = true
  end
  
  opts.on("-r", "--roles ROLES", "Extra roles (use -p for production role)") do |v|
    options[:roles] = v
  end
  
  opts.on("-i", "--inet", "Load code over internet via master code server") do
    options[:inet] = true
  end
 
  opts.on("-h", "--heartbeat", "Start with a heartbeat.") do
    $stderr.puts "WARNING! Heartbeats not supported with this build!"
  end
end.parse!
  
command = ARGV[0]
 
detached = options[:detached] ? '-detached' : ''
master = options[:master_name] || DEFAULT_MASTER_NODE
nodename = options[:name] || DEFAULT_NODE_NAME
 
if master !~ /@/
  abort "Please specify fully qualified master node name e.g. -m master@fuzed.tools.powerset.com"
end
 
spec = %{[} + create_spec_list(options).map {|x| %{"#{x}"}}.join(",") + %{]}
num_nodes = options[:num_nodes] || 1
 
inet =
if options[:inet]
  # Ruby has an awesome bug that makes me have to shell out to it, I'm not insane, I swear
  ip = `ruby -e "require 'resolv'; puts Resolv.getaddress('#{master.split('@').last}') rescue ''"`.chomp
  ip = `ruby -e "require 'resolv'; puts Resolv.getaddress('#{master.split('@').last.split('.').first}') rescue ''"`.chomp if ip == ''
  
  abort("Could not resolve #{master.split('@').last} to an IP address") unless ip
  
  " -loader inet -hosts '#{ip}'"
else
  ""
end
 
cmd = %Q{erl -boot start_sasl \
#{detached} \
+Bc \
+K true \
-smp enable \
#{code_paths}
-name '#{nodename}' \
-setcookie #{cookie_hash(master)} \
-fuzed_node master "'#{master}'" \
-fuzed_node spec '#{spec}' \
-fuzed_node num_nodes #{num_nodes} \
#{inet} \
-config '#{FUZED_ROOT}/conf/fuzed_base' \
-run fuzed_node start}.squeeze(' ')
puts cmd
exec(cmd)