LoginSignup
5
3

More than 5 years have passed since last update.

Unicorn 再起動できない

Last updated at Posted at 2018-04-01

事の発端

開発環境では改修した結果がブラウザで確認できてるのに、
本番環境では結果がブラウザ上で反映されていない問題が起きた。
何か差異が生まれてる。
そこでプロセス上で動作するアプリケーションサーバの「Unicorn」を再起動して解決するか
試すことにした。

コンソール
vagrant@vagrant-ubuntu-trusty:~/workspace/raichu$ cap production unicorn:stop
(Backtrace restricted to imported tasks)
cap aborted!
Capfile locked at 3.6.0, but 3.10.1 is loaded

Tasks: TOP => production
(See full trace by running task with --trace)

ググったけどよくわからない

Capfile locked at 3.6.0, but 3.10.1 is loadedと返却されている原因がよくわからなかった
必死でググってconfig/deproy.rbのlockを修正する答えにたどり着く

config\deploy.rb
# 今回はここを3.6.0から3.10.1の設定にする
lock '3.10.1'

# デプロイするアプリケーション名はここで設定

set :application, 'raichu'

# cloneしたいgitのレポジトリを設定(xxx:ユーザ名、yyy:アプリケーション名)

set :repo_url, 'git@github.com:xxx/yyy.git'

# deployするブランチ。デフォルトはmasterなのでなくてもいいっぽい。

set :branch, ENV['BRANCH'] || 'master'

# deploy先のディレクトリ。

set :deploy_to, '/var/www/raichu'

# シンボリックリンク(ショートカットてきな)をはるフォルダ・ファイル

set :linked_files, %w{.env config/secrets.yml}

set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets public/uploads}

# 保持するバージョンの個数

set :keep_releases, 5

# Rubyのバージョン

set :rbenv_ruby, '2.3.0'

set :rbenv_type, :system


#出力するログレベル

set :log_level, :debug

namespace :deploy do

  desc 'Restart application'

  task :restart do

    invoke 'unicorn:restart'

  end

  desc 'Create database'

  task :db_create do

    on roles(:db) do |host|

      with rails_env: fetch(:rails_env) do

        within current_path do

          execute :bundle, :exec, :rake, 'db:create'

        end

      end

    end

  end

  desc 'Run seed'

  task :seed do

    on roles(:app) do

      with rails_env: fetch(:rails_env) do

        within current_path do

          execute :bundle, :exec, :rake, 'db:seed'

        end

      end

    end

  end


  after :publishing, :restart

  after :restart, :clear_cache do

    on roles(:web), in: :groups, limit: 3, wait: 10 do

    end

  end

end

設定が完了したのでunicorn再起動へ。。。

コンソール
vagrant@vagrant-ubuntu-trusty:~/workspace/raichu$ cap production unicorn:stop
[Deprecation Notice] Future versions of Capistrano will not load the Git SCM
plugin by default. To silence this deprecation warning, add the following to
your Capfile after `require "capistrano/deploy"`:

    require "capistrano/scm/git"
    install_plugin Capistrano::SCM::Git

00:00 unicorn:stop
      stopping unicorn...
      01 kill -s QUIT `cat /var/www/raichu/current/tmp/pids/unicorn.pid`
    ✔ 01 app@"アプリのIPアドレス" 0.096s
vagrant@vagrant-ubuntu-trusty:~/workspace/raichu$

再起動おk、おつぎはデプロイ

コンソール
vagrant@vagrant-ubuntu-trusty:~/workspace/raichu$ bundle exec cap production deploy
(Backtrace restricted to imported tasks)
cap aborted!
Capfile locked at 3.10.1, but 3.6.0 is loaded

Tasks: TOP => production
(See full trace by running task with --trace)
vagrant@vagrant-ubuntu-trusty:~/workspace/Fakebook$

おっと今度はデプロイでCapfile locked at 3.10.1, but 3.6.0 is loadedと
返却されてしまいましたな^д^;
仕方がないのでもう一度config/deploy.rbを手動で3.6.0に戻す

config/deploy.rb
# もう一度lock3.10.1から3.6.0の設定にする
lock '3.6.0'

# 以下略

デプロイ実行

vagrant@vagrant-ubuntu-trusty:~/workspace/raichu$ bundle exec cap production deploy

しっかり実行されていくぅ

おわりに

今回は開発環境と本番環境のデプロイ結果後の差異についてまとめた。
vmファイルとjarファイルの更新後はtomcat再起動しないと
反映されないぞと現場でかなり叱られたことを思い出し、
それと同じことが起きているとおもって
たまたまUnicornを再起動したら
たまたまこの問題に直面してしまった。

また日曜日が潰れた、すし食いたい

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3