Единорог не использует версию ruby ​​по умолчанию - PullRequest
0 голосов
/ 27 сентября 2018

У меня есть приложение rails, использующее единорога, nginx на aws.Я только что обновил версию ruby ​​с 2.0 до 2.2.1.

ruby -v возвращает

ruby ​​2.2.1p85 (редакция 2015-02-26 49769) [x86_64-linux]

Я пытался перезапустить службу единорога

sudo service unicorn_game-mercenaries_production stop
sudo service unicorn_game-mercenaries_production start

, и в результате было

/ home / gamemercs / .rvm / gems / ruby-2.2.1@game-mercenaries/gems/bundler-1.10.6/lib/bundler/definition.rb: 412: в validate_ruby!': Your Ruby version is 2.0.0, but your Gemfile specified 2.2.1 (Bundler::RubyVersionMismatch) from /home/gamemercs/.rvm/gems/ruby-2.2.1@game-mercenaries/gems/bundler-1.10.6/lib/bundler.rb:123:in setup 'из /home/gamemercs/.rvm/gems/ruby-2.2.1@game-mercenaries / gems / bundler-1.10.6 / lib / bundler / setup.rb: 18: в <top (required)>' from /usr/share/ruby/vendor_ruby/2.0/rubygems/core_ext/kernel_require.rb:55:in require 'from /usr/share/ruby/vendor_ruby/2.0/rubygems/core_ext/kernel_require.rb:55:in`require '

Вот мой единорог. rb:

working_directory "/home/gamemercs/rails_apps/game-mercenaries/current"
pid "/home/gamemercs/rails_apps/game-mercenaries/shared/tmp/pids/unicorn.pid"
stdout_path "/home/gamemercs/rails_apps/game-mercenaries/shared/log/unicorn.stdout.log"
stderr_path "/home/gamemercs/rails_apps/game-mercenaries/shared/log/unicorn.stderr.log"


listen "/tmp/unicorn.game-mercenaries_production.sock"


worker_processes 2
timeout 30

preload_app true

before_exec do |server|
  ENV["BUNDLE_GEMFILE"] = "/home/gamemercs/rails_apps/game-mercenaries/current/Gemfile"
end

before_fork do |server, worker|
  # Disconnect since the database connection will not carry over
  if defined? ActiveRecord::Base
    ActiveRecord::Base.connection.disconnect!
  end

  # Quit the old unicorn process
  old_pid = "#{server.config[:pid]}.oldbin"
  if File.exists?(old_pid) && server.pid != old_pid
    begin
      Process.kill("QUIT", File.read(old_pid).to_i)
    rescue Errno::ENOENT, Errno::ESRCH
      # someone else did our job for us
    end
  end

  if defined?(Resque)
    Resque.redis.quit
  end
  p 'stop'

  sleep 1
end

after_fork do |server, worker|
  # Start up the database connection again in the worker
  if defined?(ActiveRecord::Base)
    ActiveRecord::Base.establish_connection
  end

  p 'start'
  if defined?(Resque)
    Resque.redis = 'localhost:6379'
  end
end

/ etc / init.d / unicorn_game-mercenaries_production

#!/bin/bash
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Manage unicorn server
# Description: Start, stop, restart unicorn server for a specific application.
### END INIT INFO
set -e

# Feel free to change any of the following variables for your app:
TIMEOUT=${TIMEOUT-60}
APP_ROOT=/home/gamemercs/rails_apps/game-mercenaries/current
PID=/home/gamemercs/rails_apps/game-mercenaries/shared/tmp/pids/unicorn.pid

AS_USER=gamemercs
CMD="export HOME; true "${HOME:=$(getent passwd "$AS_USER" | cut -d: -f6;)}" ; cd $APP_ROOT && ~/.rvm/bin/rvm 2.2.1@game-mercenaries do bundle exec unicorn -D -c /home/gamemercs/rails_apps/game-mercenaries/shared/config/unicorn.rb -E production"

set -u

OLD_PIN="$PID.oldbin"

sig () {
  test -s "$PID" && kill -$1 `cat $PID`
}

oldsig () {
  test -s $OLD_PIN && kill -$1 `cat $OLD_PIN`
}

run () {
  if [ "$(id -un)" = "$AS_USER" ]; then
    eval $1
  else
    su -c "$1" - $AS_USER
  fi
}

case "$1" in
start)
  sig 0 && echo >&2 "Already running" && exit 0
  run "$CMD"
  ;;
stop)
  sig QUIT && exit 0
  echo >&2 "Not running"
  ;;
force-stop)
  sig TERM && exit 0
  echo >&2 "Not running"
  ;;
restart|reload)
  sig USR2 && echo reloaded OK && exit 0
  echo >&2 "Couldn't reload, starting '$CMD' instead"
  run "$CMD"
  ;;
upgrade)
  if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
  then
    n=$TIMEOUT
    while test -s $OLD_PIN && test $n -ge 0
    do
      printf '.' && sleep 1 && n=$(( $n - 1 ))
    done
    echo

    if test $n -lt 0 && test -s $OLD_PIN
    then
      echo >&2 "$OLD_PIN still exists after $TIMEOUT seconds"
      exit 1
    fi
    exit 0
  fi
  echo >&2 "Couldn't upgrade, starting '$CMD' instead"
  run "$CMD"
  ;;
reopen-logs)
  sig USR1
  ;;
*)
  echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
  exit 1
  ;;
esac

Я быценю любую помощь.Как я могу заставить единорога использовать ruby ​​по умолчанию (v2.2.1)?

1 Ответ

0 голосов
/ 27 сентября 2018

Можете ли вы отредактировать GEM_HOME и GEM_PATH в /etc/init.d/unicorn, чтобы отразить ваш новый путь / номер версии ruby?

...