【问题标题】:Not able to run /etc/profile.d/chruby.sh while deploying using Capistrano in Rails在 Rails 中使用 Capistrano 部署时无法运行 /etc/profile.d/chruby.sh
【发布时间】:2018-01-13 15:02:22
【问题描述】:

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

本地:

  1. 我通过写Gemfile和bundle install安装了所有的gem:

    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'
    

在服务器/实例上:

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

    source xx/xx/xx/chruby.sh
    source xx/xx/xx/auto.sh
    
  3. 为应用创建了一个文件夹,还创建了database.yml和application.yml。

完成这一切后,当我运行 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 的示例,我无法弄清楚我哪里出错了。

【问题讨论】:

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


    【解决方案1】:

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

    当使用 'bash' 时,source 是 '.' 的别名命令。目前尚不清楚系统上的默认“/bin/sh”是什么。如果是 /bin/dash (Mint 19) - 你将不得不用 .' 替换每个源代码。'

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

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

    更新 1 假设 '/bin/ls' 是破折号(见鬼readlink -f /bin/sh,它将显示 /bin/dash 或其他 *sh 程序)。如果使用'dash',可以在/etc/profile 中设置alias,检查是否在dash 下运行。理论上,将允许使用“源”的脚本无需更改即可工作。

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

    【讨论】:

      【解决方案2】:

      我同意破折号

      但我还有一个场景

      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 上有旧版本 2013年新增this commit Ensure that chruby-exec runs under bash.。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-01-08
        • 2014-01-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-06-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多