Unicorn is not part of the bundle while starting from God

301 Views Asked by At

I have a sinatra app that works great when i start it from the project directory using bundle exec unicorn -c config/unicorn.rb -D. However when i use god to start it, I get error stating unicorn is not part of the bundle. Add it to Gemfile. (Gem::LoadError). I do have unicorn in my gemfile. I have been struggling with it for some time now, without much help. Any clues?

The exact error I get is

/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>'

Here is the god config I use

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

My Gemfile looks like

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'

The config/unicorn.rb looks like below

# 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"

The log from god -c config.god -D is below

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

It looks like God is using default location for PID file, while the location is explicitly specified. Could it be because of this?

0

There are 0 best solutions below