public
Fork of KirinDave/fuzed
Description: A new revision of Fuzed, the Erlang-based frontend for web apps.
Clone URL: git://github.com/mojombo/fuzed.git
Search Repo:
add rails cli to make railsy stuff easy
mojombo (author)
Sun May 11 18:28:32 -0700 2008
commit  6f4be433ed215bc983b5e4ac346b377c27c21b29
tree    fa3eaeca916dba29a8e4ccfcbb6e3c96d3447874
parent  e9db1600a675c78c970ecde8da2fc3ec8f83f3e2
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
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
0
@@ -1 +1,114 @@
0
+def create_spec_list(options)
0
+ spec_list = []
0
+ result = "ruby "
0
+ result.concat("-I#{FUZED_ROOT + "/rlibs "}")
0
+ raise "You must specify a fuzed file to join the fuzed cluster!" unless options[:fuzedfile]
0
+ result.concat(options[:fuzedfile] + " ")
0
+ result.concat(%{--tags="#{options[:tags]}" }) if options[:tags]
0
+ roles = []
0
+ roles << "production" if options[:production]
0
+ roles << options[:roles] if options[:roles]
0
+ result.concat(%{--roles="#{roles.join(",")}"}) unless roles.empty?
0
+ result.concat(%{ -- }) # Separates required arguments from optionals
0
+ spec_list = if options[:spec]
0
+ specs = options[:spec].split(/\|\|/)
0
+ specs.map {|x| result + x}
0
+ else
0
+ [result]
0
+ end
0
+ spec_list.map {|x| x.gsub(%r|\\|,'\\\\\\').gsub(%r|([\"\'])|, '\\\\\1')} # Make sure to escape things properly.
0
+end
0
+
0
+options = {:fuzedfile => rel("rlibs/rails_node.rb")}
0
+
0
+OptionParser.new do |opts|
0
+ opts.banner = "Usage: fuzed command [options]"
0
+
0
+ opts.on("-z HOSTNAME", "--magic HOSTNAME", "Set smart details based off of a hostname") do |n|
0
+ options[:master_name] = "master@#{n}"
0
+ end
0
+
0
+ opts.on("-n NAME", "--name NAME", "Node name") do |n|
0
+ options[:name] = n
0
+ end
0
+
0
+ opts.on("-m NAME", "--master NAME", "Master node name") do |n|
0
+ options[:master_name] = n
0
+ end
0
+
0
+ opts.on("--rails-root RAILS_ROOT", "Location of the Rails root") do |n|
0
+ options[:spec] = "--rails-root=#{n}"
0
+ end
0
+
0
+ opts.on("-c NUMNODES", "--clone NUMTIMES", "Number of clones of your spec to make") do |n|
0
+ options[:num_nodes] = n
0
+ end
0
+
0
+ opts.on("-t", "--tags TAGSTRING", "Comma-separated list of tags to apply to any nodes started") do |n|
0
+ options[:tags] = n
0
+ end
0
+
0
+ opts.on("-d", "--detached", "Run as a daemon") do
0
+ options[:detached] = true
0
+ end
0
+
0
+ opts.on("-p", "--production", "Classify these nodes as production") do
0
+ options[:production] = true
0
+ end
0
+
0
+ opts.on("-r", "--roles ROLES", "Extra roles (use -p for production role)") do |v|
0
+ options[:roles] = v
0
+ end
0
+
0
+ opts.on("-i", "--inet", "Load code over internet via master code server") do
0
+ options[:inet] = true
0
+ end
0
+
0
+ opts.on("-h", "--heartbeat", "Start with a heartbeat.") do
0
+ $stderr.puts "WARNING! Heartbeats not supported with this build!"
0
+ end
0
+end.parse!
0
+
0
+command = ARGV[0]
0
+
0
+detached = options[:detached] ? '-detached' : ''
0
+master = options[:master_name] || DEFAULT_MASTER_NODE
0
+nodename = options[:name] || DEFAULT_NODE_NAME
0
+
0
+if master !~ /@/
0
+ abort "Please specify fully qualified master node name e.g. -m master@fuzed.tools.powerset.com"
0
+end
0
+
0
+spec = %{[} + create_spec_list(options).map {|x| %{"#{x}"}}.join(",") + %{]}
0
+num_nodes = options[:num_nodes] || 1
0
+
0
+inet =
0
+if options[:inet]
0
+ # Ruby has an awesome bug that makes me have to shell out to it, I'm not insane, I swear
0
+ ip = `ruby -e "require 'resolv'; puts Resolv.getaddress('#{master.split('@').last}') rescue ''"`.chomp
0
+ ip = `ruby -e "require 'resolv'; puts Resolv.getaddress('#{master.split('@').last.split('.').first}') rescue ''"`.chomp if ip == ''
0
+
0
+ abort("Could not resolve #{master.split('@').last} to an IP address") unless ip
0
+
0
+ " -loader inet -hosts '#{ip}'"
0
+else
0
+ ""
0
+end
0
+
0
+cmd = %Q{erl -boot start_sasl \
0
+ #{detached} \
0
+ +Bc \
0
+ +K true \
0
+ -smp enable \
0
+ #{code_paths}
0
+ -name '#{nodename}' \
0
+ -setcookie #{cookie_hash(master)} \
0
+ -fuzed_node master "'#{master}'" \
0
+ -fuzed_node spec '#{spec}' \
0
+ -fuzed_node num_nodes #{num_nodes} \
0
+ #{inet} \
0
+ -config '#{FUZED_ROOT}/conf/fuzed_base' \
0
+ -run fuzed_node start}.squeeze(' ')
0
+puts cmd
0
+exec(cmd)
...
4
5
6
 
7
8
9
10
11
...
12
13
14
15
16
17
18
19
 
 
 
 
 
20
 
21
22
23
 
24
25
26
...
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
0
@@ -4,6 +4,7 @@
0
 # core
0
 require 'stringio'
0
 require 'logger'
0
+require 'optparse'
0
 
0
 # internal
0
 require 'chassis'
0
0
0
@@ -12,15 +13,16 @@
0
 # gems
0
 require 'rack'
0
 
0
-# get rails root dir
0
-if TESTMODE
0
- rails_root = File.join(File.dirname(__FILE__), *%w[.. test app])
0
-else
0
- rails_root = ARGV[0] || File.join(File.dirname(__FILE__), *%w[.. test app])
0
+# read command line options
0
+options = {:rails_root => File.join(File.dirname(__FILE__), *%w[.. test app])}
0
+opts = OptionParser.new
0
+opts.on("-r", "--rails-root RAILS_ROOT", String) do |x|
0
+ options[:rails_root] = File.join(File.dirname(__FILE__), *%w[.. test app]) unless TESTMODE
0
 end
0
+opts.parse(ARGV)
0
 
0
 # load Rails
0
-require File.join(rails_root, 'config/boot')
0
+require File.join(options[:rails_root], 'config/boot')
0
 require RAILS_ROOT + "/config/environment"
0
 
0
 # initialize logging info

Comments

    No one has commented yet.