6

When i deploy to pre server everything's woking fine. But if i try to deploy to staging server i get this error:
bundler: command not found: bin/delayed_job

file - config/deploy/staging.rb

set :rails_env, 'staging'  
set :eager_load, :true  
set :unicorn_rack_env, 'staging'  
role :app, %w{deploy@x.x.x.x}  
role :web, %w{deploy@x.x.x.x}  
role :db, %w{deploy@x.x.x.x}  

set :rvm_type, :auto                    # Defaults to: :auto  
set :rvm_ruby_version, '2.1.2'  

set :rails_env, 'staging'  
set :eager_load, :true    
role :app, %w{deploy@x.x.x.}  
role :web, %w{deploy@x.x.x.}  
role :db, %w{deploy@x.x.x.}  
set :rvm_type, :auto                    # Defaults to: :auto  
set :rvm_ruby_version, '2.1.2'  
set :deploy_to, '/var/www/app'  
server 'x.x.x', user: 'deploy', roles: %w{web app} , port: 222  
set :unicorn_pid, ->{ "#{deploy_to}/shared/tmp/pids/unicorn.pid" }  
set :scm, :git  
set :ssh_options, { user: 'superman' }  
set :keep_releases, 5  

restart of delayed jobs -

namespace :delayed_job do  
  def args  
    fetch(:delayed_job_args, "")   
  end

  def delayed_job_roles  
    fetch(:delayed_job_server_role, :app)   
  end   

  desc 'Stop the delayed_job process'  
  task :stop do  
    on roles(delayed_job_roles) do  
      within release_path do  
        with rails_env: fetch(:rails_env) do  
          execute :bundle, :exec, :'bin/delayed_job', :stop  
        end  
      end  
    end   
  end  

  desc 'Start the delayed_job process'
  task :start do  
    on roles(delayed_job_roles) do  
      within release_path do  
        with rails_env: fetch(:rails_env) do  
          execute :bundle, :exec, :'bin/delayed_job', args, :start  
        end  
      end  
    end   
  end  

  desc 'Restart the delayed_job process'  
  task :restart do  
    on roles(delayed_job_roles) do  
      within release_path do  
        with rails_env: fetch(:rails_env) do  
          execute :bundle, :exec, :'bin/delayed_job', args, :restart  
        end  
      end  
    end   
  end  
end 

Could you please give me a hand in this issue ? Thanks in advance!

UPDATE 1
More info on this error :
lib/capistrano/tasks/delayed_job.rake:33 which is execute :bundle, :exec, :'bin/delayed_job', args, :restart

mikdiet
  • 9,859
  • 8
  • 59
  • 68
Elmor
  • 4,775
  • 6
  • 38
  • 70

6 Answers6

9

You should run once on destination server:

bundle exec rails generate delayed_job

This will generate delayed_job executable script in shared/bin

Benjamin Harel
  • 2,906
  • 3
  • 24
  • 32
  • Is there any reason you would not want to generate the bins in dev and add to the source code? Or is it better to run generate on the server side with each deploy? Thanks, – max kaplan Apr 04 '16 at 23:31
  • maxkaplan you should be generating this in development and checking the bin file into source control – JamieD Aug 19 '16 at 21:15
2

Check if you can see delayed_job on your staging server in #{deploy_to}/shared/bin/

If it's not there, copy it there from your project's bin folder.

  • It's absent in both places – Elmor Oct 08 '14 at 12:28
  • 2
    It could also be that `bin/delayed_job` does not have permissions to be executable. see [this other question](https://stackoverflow.com/questions/26958355/bundler-not-executable-script-delayed-job) which can be fixed by running `chmod +x bin/delayed_job ` from your current release directory before trying to start/stop/restart etc – Jay Killeen Sep 16 '19 at 21:54
2

In addition to operations in answer by Rider. Following will perform 'bundle exec rails generate delayed_job' on remote if bin/delayed_job is missing there. Put it in config/deploy.rb file.

namespace :delayed_job do

  desc "Install Deployed Job executable if needed"
  task :install do
    on roles(delayed_job_roles) do |host|
      within release_path do
        # Only install if not already present
        unless test("[ -f #{release_path}/#{delayed_job_bin} ]")
          with rails_env: fetch(:rails_env) do
            execute :bundle, :exec, :rails, :generate, :delayed_job
          end
        end
      end
    end
  end

  before :start, :install
  before :restart, :install

end
vellotis
  • 829
  • 1
  • 12
  • 26
1

This is happening because the delayed_job executable is missing on the server. It should exist in the bin directory. To fix this you should generate the executable on your development machine and check it in to source control.

This command will generate the executable for you:

bundle exec rails generate delayed_job

JamieD
  • 2,707
  • 2
  • 20
  • 19
0

Its better to use Capistrano::DelayedJob Gem

Delayed Job support for Capistrano 3.x

Add this line to your application's Gemfile:

gem 'capistrano3-delayed-job', '~> 1.0'

Require in Capfile to use the default task:

require 'capistrano/delayed-job'

Add this to your deploy.rb file

after 'deploy:published', 'restart' do
    invoke 'delayed_job:restart'
end

For more configurable options https://github.com/platanus/capistrano3-delayed-job

monteirobrena
  • 2,562
  • 1
  • 33
  • 45
Animesh
  • 1,005
  • 10
  • 20
0

Please check if you setup your rails_env system variable correctly.

Jack Vo
  • 279
  • 2
  • 10