yaws 1.73 compatibility
[fuzed.git] / bin / fuzed
blobeebcd47d8670a94661b3ef9a6c03a50749cbbe97
1 #!/usr/bin/env ruby
3 # require 'fuzed'
4 require File.join(File.dirname(__FILE__), *%w[.. lib fuzed])
6 require 'optparse'
7 require 'pp'
9 options = {}
10 OptionParser.new do |opts|
11 opts.banner = <<-EOF
12 Usage:
13 fuzed local [-r RAILS_ROOT] [-P PID_FILE] [-d]
14 fuzed start -c CONFIG -n NAME [-P PID_FILE] [-d]
15 fuzed join -n NAME -m MASTER -r RAILS_ROOT [-P PID_FILE] [-o NUMNODES] [-d]
16 fuzed cycle -n NAME -k NODE
17 fuzed cycle_all -n NAME -s DELAY
18 EOF
20 opts.on("-c CONFIG", "--config CONFIG", "Path to Yaws config file") do |n|
21 options[:config] = n
22 end
24 opts.on("-n NAME", "--name NAME", "Node name") do |n|
25 options[:name] = n
26 end
28 opts.on("-m NAME", "--master NAME", "Master node name") do |n|
29 options[:master_name] = n
30 end
32 opts.on("-o NUMNODES", "--num_nodes NUMNODES", "Number of nodes to run") do |n|
33 options[:num_nodes] = n
34 end
36 opts.on("-r RAILS_ROOT", "--rails RAILS_ROOT", "Path to Rails root") do |a|
37 options[:rails] = a
38 end
40 opts.on("-d", "--daemon", "Run daemonized") do
41 options[:detached] = true
42 end
44 opts.on("-k NAME", "--killee NAME", "Node on which to cycle Rails instances") do |a|
45 options[:killee] = a
46 end
48 opts.on("-s DELAY", "--delay DELAY", "Number of seconds to delay between node cycling") do |a|
49 options[:delay] = a
50 end
52 opts.on("-P PID_FILE", "--pid-file PID_FILE", "Where to write the pid file") do |a|
53 options[:pid] = a
54 end
55 end.parse!
57 command = ARGV[0]
59 case command
60 when 'start'
61 config = options[:config]
62 nodename = options[:name]
63 detached = options[:detached] ? '--daemon' : ''
64 pidfile = options[:pid] ? %Q{-run fuzed_util write_pid "#{options[:pid]}"} : ''
66 puts "Starting yaws server with name: #{nodename}"
67 cmd = %Q{yaws --conf #{config} \
68 #{detached} \
69 --pa #{Fuzed.relative 'ebin'} \
70 --name "#{nodename}" \
71 --runmod fuzed \
72 --erlarg '#{pidfile} +Bc +K true -smp auto'}.squeeze(' ')
73 puts cmd
74 exec(cmd)
75 when 'join'
76 nodename = options[:name]
77 master = options[:master_name]
78 num_nodes = options[:num_nodes]
79 rails = options[:rails]
80 detached = options[:detached] ? '-detached' : ''
81 pidfile = options[:pid] ? %Q{-run fuzed_util write_pid "#{options[:pid]}"} : ''
83 puts "Starting a client named #{nodename} offering service to #{master}"
84 puts "Each node will run: 'fuzed-adapter #{rails}'"
85 Dir.chdir(Fuzed.root)
86 cmd = %Q{erl -boot start_sasl \
87 #{detached} \
88 +Bc +K true -smp auto \
89 -name "#{nodename}" \
90 -pa #{Fuzed.relative 'ebin'} \
91 -fuzed_node master "'#{master}'" \
92 -fuzed_node command '"fuzed-adapter #{rails}"' \
93 -fuzed_node num_nodes #{num_nodes || 2} \
94 #{pidfile} \
95 -run fuzed_node start}.squeeze(' ')
96 puts cmd
97 exec(cmd)
98 when 'cycle'
99 nodename = options[:name]
100 killee = options[:killee]
102 cmd = %Q{erl -smp auto \
103 -name "#{nodename}" \
104 -pa #{Fuzed.relative 'ebin'} \
105 -run fuzed_util cycle "#{killee}" \
106 -run erlang halt}.squeeze(' ')
107 puts(cmd)
108 exec(cmd)
109 when 'cycle_all'
110 nodename = options[:name]
111 master = options[:master_name]
112 delay = options[:delay] || 0
114 cmd = %Q{erl -smp auto \
115 -name "#{nodename}" \
116 -pa #{Fuzed.relative 'ebin'} \
117 -run fuzed_util cycle_all "#{master}" #{delay} \
118 -run erlang halt}.squeeze(' ')
119 puts(cmd)
120 exec(cmd)
121 when 'local'
122 num_nodes = options[:num_nodes]
123 rails = options[:rails] || File.expand_path('.')
124 config = "/tmp/fuzed-local.conf"
125 detached = options[:detached] ? '--daemon' : ''
126 pidfile = options[:pid] ? %Q{-run fuzed_util write_pid "#{options[:pid]}"} : ''
128 puts "Starting yaws server with name: #{nodename}"
130 File.open(config, 'w') do |f|
131 f.write `fuzed-conf #{rails} 3000`
134 cmd = %Q{yaws --conf #{config} \
135 #{detached} \
136 --pa #{Fuzed.relative 'ebin'} \
137 --runmod stack \
138 --erlarg '#{pidfile} +Bc +K true -smp auto \
139 -fuzed_node command "\\\"fuzed-adapter #{rails}\\\"" \
140 -fuzed_node num_nodes #{num_nodes || 1}'}.squeeze(' ')
141 puts(cmd)
142 exec(cmd)
143 else
144 puts 'Invalid command'
147 __END__
149 ruby-prof -p graph_html -f graph.html