Module: AppDeploy::RackCluster
- Defined in:
- lib/app-deploy/rack_cluster.rb
Class Method Summary collapse
- .each(path) ⇒ Object
- .log_path(path, port) ⇒ Object
-
.path_with_number(path, number) ⇒ Object
extracted from thin Add the server port or number in the filename so each instance get its own file.
- .pid_path(path, port) ⇒ Object
- .start(config, ruby_opts, rack_opts) ⇒ Object
Class Method Details
.each(path) ⇒ Object
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 |
# File 'lib/app-deploy/rack_cluster.rb', line 6 def each path config_orig = {} rack_opts = AppDeploy.extract_config(path){ |opt, value| case opt when 'environment' "--env #{value}" when *%w[server host] config_orig[opt.to_sym] = value "--#{opt} #{value}" when *%w[user group chdir servers require rackup daemonize port pid log delay] config_orig[opt.to_sym] = value nil # rack doesn't have this option else "--#{opt} #{value}" end } config_orig = { :servers => 1, :port => 9292, :host => '0.0.0.0', :log => 'log/rack_cluster.log', :pid => 'tmp/pids/rack_cluster.pid', :server => 'mongrel', :rackup => 'config.ru' }.merge(config_orig) config_orig[:servers].times{ |n| config = config_orig.dup config[:port] += n config[:pid] = RackCluster.pid_path(config[:pid], config[:port]) config[:log] = RackCluster.log_path(config[:log], config[:port]) args = [:pid, :log, :user, :group, :chdir].map{ |kind| value = config.send(:[], kind) value ? "'#{value}'" : 'nil' }.join(', ') init_script = "AppDeploy::Daemon.daemonize(#{args})" ruby_opts = "-r rubygems -r app-deploy/daemon -e \"#{init_script}\"" yield( config, ruby_opts, rack_opts + " --port #{config[:port]}" ) } end |
.log_path(path, port) ⇒ Object
65 66 67 68 |
# File 'lib/app-deploy/rack_cluster.rb', line 65 def log_path path, port # log should expand path since daemons' working dir is different File.(RackCluster.path_with_number(path, port)) end |
.path_with_number(path, number) ⇒ Object
extracted from thin Add the server port or number in the filename so each instance get its own file
73 74 75 76 |
# File 'lib/app-deploy/rack_cluster.rb', line 73 def path_with_number path, number ext = File.extname(path) path.gsub(/#{ext}$/, ".#{number}#{ext}") end |
.pid_path(path, port) ⇒ Object
61 62 63 |
# File 'lib/app-deploy/rack_cluster.rb', line 61 def pid_path path, port RackCluster.path_with_number(path, port) end |
.start(config, ruby_opts, rack_opts) ⇒ Object
55 56 57 58 59 |
# File 'lib/app-deploy/rack_cluster.rb', line 55 def start config, ruby_opts, rack_opts puts "Starting #{config[:server]} on #{config[:host]}:#{config[:port]}..." sh "rackup #{ruby_opts} #{rack_opts} #{config[:rackup]}" puts end |