在Rails中使用Capistrano部署时无法运行/etc/profile.d/chruby.sh

时间:2018-01-13 15:02:22

标签: ruby-on-rails ruby bash shell chruby

我一直在尝试在EC2实例上部署我的rails应用程序。我已经采取的步骤是

本地:

  1. 我通过写Gemfilebundle install安装了所有宝石:

    group :development do
      gem 'capistrano'
      gem 'capistrano3-puma'
      gem 'capistrano-rails', require: false
      gem 'capistrano-bundler', require: false
      gem 'capistrano-chruby'
    end
    
  2. 我编辑了Capfile以要求模块

    require "capistrano/setup"
    require "capistrano/deploy"
    require "capistrano/scm/git"
    install_plugin Capistrano::SCM::Git
    require "capistrano/chruby"
    require "capistrano/bundler"
    require "capistrano/rails/assets"
    require "capistrano/rails/migrations"
    require "capistrano/puma"
    Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
    
  3. 我也在config/deploy.rb进行了必要的更改,特别是

    set :chruby_ruby, 'ruby-2.3.0'
    
  4. 在服务器/实例上:

    1. 已安装的Ruby
    2. 已安装Chruby并包含在/etc/profile.d/chruby.sh中:

      source xx/xx/xx/chruby.sh
      source xx/xx/xx/auto.sh
      
    3. 为应用创建了一个文件夹,并创建了database.ymlapplication.yml

    4. 完成所有这些操作后,当我运行cap production deploy时,它可以通过检查和git克隆并链接文件和目录,但在bundler:install上失败,会出现错误,如

      01 /usr/local/bin/chruby-exec ruby-2.3.0 -- bundle install --path /home/deploy…
      01 /bin/sh: 2: /etc/profile.d/chruby.sh:
      01 source: not found
      01
      01 /bin/sh: 3: /etc/profile.d/chruby.sh:
      01 source: not found
      01
      01 /bin/sh: 1:
      01 chruby: not found
      01
      

      由于只有使用RVM或JRuby将Rails部署到AWS的示例,我无法弄清楚我哪里出错了。

2 个答案:

答案 0 :(得分:4)

表面上,问题出在'/ bin / sh',它不支持'source'。

使用“ bash”时,源是“。”的别名。命令。目前尚不清楚系统上的默认'/ bin / sh'是什么。如果它是/ bin / dash(薄荷19)-您将必须用替换每个sourec。'

. xx/xx/xx/chruby.sh
. xx/xx/xx/auto.sh

可能您将不得不对可能使用“源代码”的引用文件(/etc/profile.d/*.sh)进行类似的修复。

更新1 假设“ / bin / ls”是破折号(readlink -f /bin/sh的后缀,它将显示/ bin / dash或其他* sh程序)。如果使用“破折号”,则可以在检查是否在破折号下运行后在/ etc / profile中设置alias。从理论上讲,将允许使用“源代码”的脚本正常工作。

case "$(readlink -f /proc/$$/exe)" in
    */dash) alias source=. ;;
esac

答案 1 :(得分:0)

我同意破折号

但我还有另一种情况

  1. 在chruby-exec中添加shebang

  2. export SHELL=/bin/bash

chruby-exec source on github

最后一行是

exec "$SHELL" "${shell_opts[@]}" -c "$command"

因此环境变量SHELL在这里起着重要的作用。

@ alchemist95您能否检查chruby-exec的第一行

您似乎在chruby-exec上具有较旧的版本 this commit Ensure that chruby-exec runs under bash.已于2013年添加。

相关问题