Not able to run /etc/profile.d/chruby.sh while deploying using Capistrano in Rails
Asked Answered
L

2

6

I have been trying to deploy my rails application on an EC2 instance. The steps which i have taken already are

Locally:

  1. I installed all the gems by writing in Gemfile and bundle install:

    group :development do
      gem 'capistrano'
      gem 'capistrano3-puma'
      gem 'capistrano-rails', require: false
      gem 'capistrano-bundler', require: false
      gem 'capistrano-chruby'
    end
    
  2. I edited my Capfile to require the modules

    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. I made the necessary changes in config/deploy.rb as well, specially

    set :chruby_ruby, 'ruby-2.3.0'
    

On the Server/Instance:

  1. Installed Ruby
  2. Installed Chruby and included in /etc/profile.d/chruby.sh these:

    source xx/xx/xx/chruby.sh
    source xx/xx/xx/auto.sh
    
  3. Made a folder for app and also created database.yml and application.yml.

Having Done all this, when I run cap production deploy, it starts fine with checking and git cloning and linking files and directories but fails on bundler:install, giving an error like

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

Since there are only examples with deploying Rails to AWS using either RVM or JRuby, I am not able to figure out where I am going wrong.

Leverrier answered 13/1, 2018 at 15:2 Comment(0)
M
4

On surface, the problem is with '/bin/sh', which does not support 'source'.

When using 'bash', source is aliases to the '.' command. It's not clear what is the default '/bin/sh' on your system. If it's /bin/dash (Mint 19) - you will have to replace every sourec with .'

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

It might be that you will have to make similar fixes to referenced files (/etc/profile.d/*.sh) which may use 'source'.

Update 1 Assuming the '/bin/ls' is dash (heck with readlink -f /bin/sh, it will show /bin/dash, or other *sh program). If using 'dash', possible to setup alias in /etc/profile, after checking if running under dash. In theory, will allow scripts using 'source' to work without changes.

case "$(readlink -f /proc/$$/exe)" in
    */dash) alias source=. ;;
esac
Morion answered 13/11, 2019 at 16:54 Comment(0)
C
0

I agree with dash-o

but I have one more scenario

  1. adding shebang in chruby-exec

  2. export SHELL=/bin/bash

in chruby-exec source on github

last line is

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

so environment variable SHELL plays important role here.

@alchemist95 can you please check first line of chruby-exec

you seem to have older version on chruby-exec as this commit Ensure that chruby-exec runs under bash. has been added in 2013.

Carlton answered 20/11, 2019 at 7:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.