从上帝开始,独角兽不是捆绑的一部分

时间:2016-04-22 10:01:38

标签: ruby rubygems sinatra unicorn god

我有一个sinatra应用程序,当我使用bundle exec unicorn -c config/unicorn.rb -D从项目目录启动它时效果很好。但是,当我使用上帝来启动它时,我收到错误陈述unicorn is not part of the bundle. Add it to Gemfile. (Gem::LoadError)。我的gemfile中有独角兽。我一直在苦苦挣扎一段时间,没有多少帮助。有线索吗?

我得到的确切错误是

/Users/pranav/.rvm/gems/ruby-2.1.5@global/gems/bundler-1.11.2/lib/bundler/rubygems_integration.rb:304:in `block in replace_gem': unicorn is not part of the bundle. Add it to Gemfile. (Gem::LoadError)
    from /Users/pranav/.rvm/gems/ruby-2.1.5/bin/unicorn:22:in `<main>'
    from /Users/pranav/.rvm/gems/ruby-2.1.5/bin/ruby_executable_hooks:15:in `eval'
    from /Users/pranav/.rvm/gems/ruby-2.1.5/bin/ruby_executable_hooks:15:in `<main>'

这是我使用的神配置

proj_dir = ENV['DIR_API_HANDLER']

script_name = 'api_handler'
pid_file = File.join(proj_dir, 'shared', 'pids', 'unicorn.pid')
log_file = File.join(proj_dir, 'shared', 'log', 'unicorn.stderr.log')
God.watch do |w|
    w.name = script_name
    w.group = 'apihandler'

    w.log = log_file
    w.dir = proj_dir
    w.env = ENV

    w.start = "cd #{ proj_dir } && bundle exec unicorn -c config/unicorn.rb -D"

    # QUIT gracefully shuts down workers
    w.stop = "cd #{ proj_dir} && kill -QUIT `cat #{ pid_file }`"

    # USR2 causes the master to re-create itself and spawn a new worker pool
    w.restart = "kill -USR2 `cat #{ pid_file }`"

    w.start_grace = 10.seconds
    w.restart_grace = 15.seconds
    w.interval = 30.minutes
    w.pid_file = pid_file
    w.behavior(:clean_pid_file)

    w.start_if do |start|
        start.condition(:process_running) do |c|
            c.interval = 5.seconds
            c.running = false
        end
    end

    w.restart_if do |restart|
        restart.condition(:memory_usage) do |c|
            c.above = 300.megabytes
            c.times = [3, 5] # 3 out of 5 intervals
        end

        restart.condition(:cpu_usage) do |c|
            c.above = 50.percent
            c.times = 5
        end
    end

    # lifecycle
    w.lifecycle do |on|
        on.condition(:flapping) do |c|
            c.to_state = [:start, :restart]
            c.times = 5
            c.within = 5.minute
            c.transition = :unmonitored
            c.retry_in = 10.minutes
            c.retry_times = 5
            c.retry_within = 2.hours
        end
    end
end

我的Gemfile看起来像

source 'https://rubygems.org'
ruby '2.1.5'

gem 'sinatra'
gem 'sinatra-contrib'
gem 'json'
gem 'unicorn', '~>5.1.0'
gem 'ruby-kafka', '~>0.3.2'
gem 'dotenv'
gem 'curb'

config/unicorn.rb如下所示

# set path to application
app_dir = File.expand_path("../..", __FILE__)
shared_dir = "#{app_dir}/shared"
working_directory app_dir

# Set unicorn options
worker_processes 2
preload_app false
timeout 30
listen 9001

# Set up socket location
#listen "#{shared_dir}/sockets/unicorn.sock", :backlog => 64

# Logging
stderr_path "#{shared_dir}/log/unicorn.stderr.log"
stdout_path "#{shared_dir}/log/unicorn.stdout.log"

# Set master PID location
pid "#{shared_dir}/pids/unicorn.pid"

god -c config.god -D的日志低于

I [2016-04-22 18:42:37]  INFO: Loading octo.god
I [2016-04-22 18:42:37]  INFO: Syslog enabled.
I [2016-04-22 18:42:37]  INFO: Using pid file directory: /Users/pranav/.god/pids
I [2016-04-22 18:42:37]  INFO: Started on drbunix:///tmp/god.17165.sock
I [2016-04-22 18:42:37]  INFO: api_handler move 'unmonitored' to 'up'
I [2016-04-22 18:42:37]  INFO: api_handler moved 'unmonitored' to 'up'
I [2016-04-22 18:42:37]  INFO: api_handler [trigger] process is not running (ProcessRunning)
I [2016-04-22 18:42:37]  INFO: api_handler move 'up' to 'start'
I [2016-04-22 18:42:37]  INFO: api_handler before_start: no pid file to delete (CleanPidFile)
I [2016-04-22 18:42:37]  INFO: api_handler start: cd /Users/pranav/workspace/apihandler && bundle exec unicorn -c config/unicorn.rb -D
W [2016-04-22 18:42:38]  WARN: api_handler start command exited with non-zero code = 1

看起来上帝正在使用PID文件的默认位置,而明确指定了位置。可能是因为这个吗?

0 个答案:

没有答案