Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 200
alchemist95 Avatar asked Jan 13 '18 15:01

alchemist95


1 Answers

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
like image 146
dash-o Avatar answered Nov 01 '22 06:11

dash-o