1

I am trying to deploy mailman with daemon and capistrano for my rails app into the production, but I receive this error on my local machine:

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

Below is my deploy.rb file:

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"

And below is my gemfile:

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'

I am using capistrano (3.4.0) and capistrano-rvm (0.1.2).

And I have tried to use rvm1-capistrano3 and rvm-capistrano gem as suggested in this thread, but no luck.

Could somebody help out?

Thanks!

####################### UPDATE 1 #####################

This is what I got what i do git grep usr.bin.env on my local machine:

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

####################### UPDATE 2 #####################

I already have set the path for my rvm in my ~/.bash_profile:

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*
~   
Community
  • 1
  • 1
Ryzal Yusoff
  • 957
  • 2
  • 22
  • 49

2 Answers2

0

Looks like the user deploy on 173.63.11.34 has no access to the ruby executable.

Make sure you install the ruby, rvm et, al, in the context of deploy user or in the global scope on 173.63.11.34.

One way to check is to ssh into 173.63.11.34 as deploy user and see if you will be able to execute ruby or rvm etc.

Dharam Gollapudi
  • 6,328
  • 2
  • 34
  • 42
  • Hey thanks for the response, but I have definitely installed ruby and rvm in the context of `deploy` user. I have tried to ssh to the server and test ruby as u suggested and it works fine. I tested it with irb command like this: `deploy@Myapp:~/apps/myapp/current$ irb` – Ryzal Yusoff Mar 09 '16 at 23:43
0

either you have not installed your rvm or rbenv, chruby or ruby binary some other thing in your production server.

or more likely you misplaced or forgot to add the PATH and or source scripts like

for rvm

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

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

or

for rbenv

export PATH="$PATH:$HOME/.rbenv/bin"

eval "$(rbenv init - )"

export PATH="$PATH:$HOME/.rbenv/plugins/ruby-build/bin"

or

for chruby

source /usr/share/chruby/chruby.sh

source /usr/share/chruby/auto.sh

RUBIES+=(/opt/rubies/*)

or

something like that

Community
  • 1
  • 1
krazedkrish
  • 638
  • 3
  • 10
  • Hey, I have definitely have rvm installed on my production server, and I have also already set it's PATH on my ~/.bash_profile. See my Update 2 above – Ryzal Yusoff Mar 18 '16 at 16:41
  • Which shell do you get when you login as deploy in the remote shell. Is it sh bash ssh. Try command echo $SHELL if it is sh instead of bash, you .bash_profile won't work – krazedkrish Mar 19 '16 at 02:56