lib/golden_brindle/start.rb in golden_brindle-0.0.6 vs lib/golden_brindle/start.rb in golden_brindle-0.1
- old
+ new
@@ -5,10 +5,11 @@
include GoldenBrindle::Command::Base
def configure
options [
["-e", "--environment ENV", "Rails environment to run as", :@environment, ENV['RAILS_ENV'] || "development"],
+ ["-b", "--bundler", "Use bundler to start unicorn instances", :@bundler, false],
["-d", "--daemonize", "Run daemonized in the background", :@daemon, false],
['', "--preload", "Preload application", :@preload, false],
['-p', '--port PORT', "Which port to bind to (if set numbers of servers - start port number)", :@port, Unicorn::Const::DEFAULT_PORT],
['-a', '--address ADDR', "Address to bind to", :@address, Unicorn::Const::DEFAULT_HOST],
['-o', '--listen {HOST:PORT|PATH}',"listen on HOST:PORT or PATH, separeted by comma (default: #{Unicorn::Const::DEFAULT_LISTEN})", :@listen, Unicorn::Const::DEFAULT_LISTEN],
@@ -59,12 +60,10 @@
require ::File.expand_path('config/environment')
rescue LoadError => err
abort "#$0 must be run inside RAILS_ROOT: #{err.inspect}"
end
- require 'config/environment'
-
defined?(::Rails::VERSION::STRING) or
abort "Rails::VERSION::STRING not defined by config/{boot,environment}"
# it seems Rails >=2.2 support Rack, but only >=2.3 requires it
old_rails = case ::Rails::VERSION::MAJOR
when 0, 1 then true
@@ -113,10 +112,16 @@
if @config_script
valid_exists?(@config_script, "Unicorn-specific config file not there: #@config_script")
return false unless @valid
end
+
+ if @bundler
+ valid_exists?('Gemfile', "Cannot use Bundler - no Gemfile in your application root dir")
+ return false unless @valid
+ end
+
@cwd = File.expand_path(@cwd)
valid_dir? @cwd, "Invalid path to change to during daemon mode: #{@cwd}"
valid?(@prefix[0] == ?/ && @prefix[-1] != ?/, "Prefix must begin with / and not end in /") if @prefix
valid_dir? File.dirname(File.join(@cwd,@log_file)), "Path to log file not valid: #{@log_file}"
valid_dir? File.dirname(File.join(@cwd,@pid_file)), "Path to pid file not valid: #{@pid_file}"
@@ -126,9 +131,19 @@
end
def run
# Change there to start, then we'll have to come back after daemonize
Dir.chdir(@cwd)
+ if @bundler
+ puts "Using Bundler"
+ puts "reexec via bundle exec"
+ require 'pp'
+ cmd_for_exec = "bundle exec #{@opt.program_name}"
+ @original_args.each_slice(2) do |arg_key,value|
+ cmd_for_exec << " #{arg_key} #{value}" if arg_key != "-b"
+ end
+ exec(cmd_for_exec)
+ end
options = {
:listeners => [],
:pid => @pid_file,
:config_file => @config_script,
:worker_processes => @workers.to_i,