Capistrano给出" / usr / bin / env:ruby:没有这样的文件或目录"执行上限部署时

时间:2016-03-09 21:16:20

标签: ruby-on-rails ruby-on-rails-4 capistrano daemon mailman

我正在尝试将带有守护进程和capistrano的mailman部署到我的rails应用程序中,但是我在本地计算机上收到此错误:

SSHKit::Runner::ExecuteError: Exception while executing on host 173.63.11.34: Exception while executing on host 178.62.16.69: script/mailman_daemon.rb exit status: 127
script/mailman_daemon.rb stdout: Nothing written
script/mailman_daemon.rb stderr: /usr/bin/env: ruby: No such file or directory

以下是我的deploy.rb文件:

server '173.63.11.34', port: 22, roles: [:web, :app, :db], primary: true

set :repo_url,        'git@github.com:ryzalyusoff/xxxx.git'
set :application,     'xxxx'
set :user,            'deploy'
set :puma_threads,    [4, 16]
set :puma_workers,    0

set :pty,             false
set :use_sudo,        false
set :stage,           :production
set :deploy_via,      :remote_cache
set :deploy_to,       "/home/#{fetch(:user)}/apps/#{fetch(:application)}"
set :puma_bind,       "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock"
set :puma_state,      "#{shared_path}/tmp/pids/puma.state"
set :puma_pid,        "#{shared_path}/tmp/pids/puma.pid"
set :puma_access_log, "#{release_path}/log/puma.error.log"
set :puma_error_log,  "#{release_path}/log/puma.access.log"
set :ssh_options,     { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa.pub) }
set :puma_preload_app, true
set :puma_worker_timeout, nil
set :puma_init_active_record, true  # Change to false when not using ActiveRecord


set :whenever_identifier, ->{ "myapp_#{fetch(:stage)}" }

namespace :puma do
  desc 'Create Directories for Puma Pids and Socket'
  task :make_dirs do
    on roles(:app) do
      execute "mkdir #{shared_path}/tmp/sockets -p"
      execute "mkdir #{shared_path}/tmp/pids -p"
    end
  end

  before :start, :make_dirs
end

namespace :deploy do
  desc "Make sure local git is in sync with remote."
  task :check_revision do
    on roles(:app) do
      unless `git rev-parse HEAD` == `git rev-parse origin/master`
        puts "WARNING: HEAD is not the same as origin/master"
        puts "Run `git push` to sync changes."
        exit
      end
    end
  end

  desc 'Initial Deploy'
  task :initial do
    on roles(:app) do
      before 'deploy:restart', 'puma:start'
      invoke 'deploy'
    end
  end

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      invoke 'puma:restart'
    end
  end

  before :starting,     :check_revision
  after  :finishing,    :compile_assets
  after  :finishing,    :cleanup
  after  :finishing,    :restart

end


# Mailman configuration
namespace :mailman do
  desc "Mailman::Start"
  task :start do
    on roles(:app) do
      within release_path do
        with default_env: fetch(:default_env) do
          execute "script/mailman_daemon.rb", "start"
        end
      end
    end
  end

  desc "Mailman::Stop"
  task :stop do
    on roles(:app) do
      within release_path do
        with default_env: fetch(:default_env) do
          execute "script/mailman_daemon.rb", "stop"
        end
      end
    end
  end

  desc "Mailman::Restart"
  task :restart do
    on roles(:app) do
      invoke("mailman:stop")
      invoke("mailman:start")
    end
  end
end

before "deploy:cleanup", "mailman:restart"

以下是我的宝石文件:

source 'https://rubygems.org'

ruby "2.0.0"

gem 'rails', '4.2.3'
gem 'mysql2', '~> 0.3.18'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc

group :development, :test do
  gem 'byebug'
  gem 'web-console', '~> 2.0'
  gem "rails-erd"
  gem 'capistrano',           require: false
  gem 'capistrano-rvm',       require: false
  gem 'capistrano-rails',     require: false
  gem 'capistrano-bundler',   require: false
  gem 'capistrano3-puma',     require: false
  gem 'rvm1-capistrano3', require: false
end

group :production do
  gem 'rails_12factor', '0.0.2'
  gem 'thin'
  gem 'puma', '3.1.0'
end

gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'bootstrap-sass', '~> 3.3.4.1'
gem "better_errors"
gem "devise"
gem 'rails_admin', '~> 0.6.8'
gem 'jquery-ui-rails'
gem 'execjs'
gem 'therubyracer', :platforms => :ruby
gem "compass-rails", github: "Compass/compass-rails", branch: "master"
gem 'sucker_punch', '~> 2.0', '>= 2.0.1'
gem 'carrierwave'
gem "fog-aws"

# Sending SMS
gem 'twilio-ruby'
gem 'postmark-rails', "~> 0.5.2"
# Cronjob
gem 'whenever', '~> 0.9.4'
gem 'griddler'
gem 'mailman'
gem 'email_reply_parser', '~> 0.5.8'
gem 'mail_extract', '~> 0.1.4'
gem 'daemons', '~> 1.2', '>= 1.2.3'
gem 'delayed_job_active_record'

我使用的是capistrano(3.4.0)和capistrano-rvm(0.1.2)。

我尝试使用rvm1-capistrano3和rvm-capistrano gem,如thread所示,但没有运气。

有人可以帮忙吗?

谢谢!

#######################更新1 ################### ##

这就是我在本地机器上得到的git grep usr.bin.env

bin/bundle:#!/usr/bin/env ruby.exe
bin/delayed_job:#!/usr/bin/env ruby
bin/rails:#!/usr/bin/env ruby.exe
bin/rake:#!/usr/bin/env ruby.exe
bin/setup:#!/usr/bin/env ruby.exe
script/mailman_daemon.rb:#!/usr/bin/env ruby
script/mailman_server:#!/usr/bin/env ruby

#######################更新2 ################### ##

我已经在〜/ .bash_profile中为我的rvm设置了路径:

export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting

[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
~   

2 个答案:

答案 0 :(得分:0)

看起来173.63.11.34上的用户deploy无法访问ruby可执行文件。

请务必在ruby用户的上下文或173.63.11.34的全局范围内安装rvmdeploy等。

检查的一种方法是将ssh改为173.63.11.34作为deploy用户,看看您是否能够执行rubyrvm等。

答案 1 :(得分:0)

要么你没有在你的生产服务器中安装你的rvm或rbenv,chruby或ruby二进制文件。

或更有可能放错地方忘记添加PATH和/或源脚本

  

表示rvm

     

export PATH =“$ PATH:$ HOME / .rvm / bin”#将RVM添加到PATH以进行脚本编写

     

[[-s“$ HOME / .rvm / scripts / rvm”]]&&来源“$ HOME / .rvm / scripts / rvm”

  

表示rbenv

     

export PATH =“$ PATH:$ HOME / .rbenv / bin”

     

eval“$(rbenv init - )”

     

export PATH =“$ PATH:$ HOME / .rbenv / plugins / ruby​​-build / bin”

  

for chruby

     

来源/usr/share/chruby/chruby.sh

     

来源/usr/share/chruby/auto.sh

     

RUBIES + =(/选择/红宝石/ *)

类似的东西