今の状況
unicornを起動させようとしましたが、「すでに起動されている」とのエラーでプロセスをkillしようとすると、「そのようなプロセスはありません」と返されてしまいます。
Capistranoでデプロイが完了した状態で、ページにアクセスするとWe're sorry, but something went wrong.
とRailsのエラーが表示されている状況です。ブラウザのステータスには502との表示。
原因はおそらく、Railsのエラーが表示されているので、unicornの起動が何らかの形で勝手に起動しているんだと思います。
勝手に起動しているということは、unicornとcapistranoでpidの正しい設定がされていないのが原因ではないかと予想しているのですが、様々なサイトを参考にして設定してもうまくいきません。
解決策を教えていただけると、助かります。よろしくお願いします。
unicornのエラーログ
ArgumentError: Already running on PID:18201 (or pid=tmp/pids/unicorn.pid is stale) /var/www/RailsApp/shared/bundle/ruby/2.5.0/gems/unicorn-5.4.0/lib/unicorn/http_server.rb:205:in `pid=' /var/www/RailsApp/shared/bundle/ruby/2.5.0/gems/unicorn-5.4.0/lib/unicorn/http_server.rb:137:in `start' /var/www/RailsApp/shared/bundle/ruby/2.5.0/gems/unicorn-5.4.0/bin/unicorn_rails:209:in `<top (required)>' /var/www/RailsApp/shared/bundle/ruby/2.5.0/bin/unicorn_rails:23:in `load' /var/www/RailsApp/shared/bundle/ruby/2.5.0/bin/unicorn_rails:23:in `<top (required)>'
行ったkill手順
すでに起動しているとのログなので
0. ps aux | grep unicorn
コマンドでプロセスを確認
root 18853 0.0 0.1 112676 976 pts/0 R+ 15:56 0:00 grep --color=auto unicorn ``` 0. killコマンドで`kill -QUIT 18853`とkillしても、「そのようなプロセスはありません」と返される。 0. 再度プロセスを確認すると、PIDが変わっている。 0. またkillしてもプロセスがないの繰り返し。 # ファイル構成 /var/www/RailsApp/releases/20180507065819/lib/capistrano/tasks/unicorn.rb /var/www/RailsApp/shared/tmp/pids/unicorn.pid # ファイル config/deploy.rb ``` ruby lock "~> 3.10.2" set :application, "アプリケーション名" set :repo_url, "git@github.〇〇/〇〇.git" set :deploy_to, '/var/www/デプロイ先のディレクトリ名' set :default_env, { :DEVISE_SECRET_KEY => ENV['DEVISE_SECRET_KEY'] } append :linked_files, "config/database.yml" set :linked_files, %w{config/database.yml config/secrets.yml} set :linked_dirs, %w{bin log tmp/pids tmp/cache sockets bundle public/system public/assets} set :unicorn_pid, "#{shared_path}/tmp/pids/unicorn.pid" set :ssh_options, { verify_host_key: :secure, forward_agent: true } set :rbenv_type, :user set :rbenv_ruby, '2.5.1' set :rbenv_path, '/usr/local/rbenv' set :log_level, :debug after 'deploy:publishing', 'deploy:restart' namespace :deploy do task :restart do on roles(:app) do within current_path do if test("[ -e #{fetch(:unicorn_pid)} ]") execute :kill, "-s QUIT ", pid end secret = capture :bundle, "exec rake secret" execute "echo SECRET_KEY_BASE='#{secret}' > #{current_path}/.env" execute :bundle, "exec unicorn", "-c", fetch(:unicorn_config_path), "-E", fetch(:rails_env), "-D" end end end end ``` lib/capistrano/tasks/unicorn.rb ``` ruby rails_root = File.expand_path('../../../', __FILE__) ENV['BUNDLE_GEMFILE'] = rails_root + "/Gemfile" worker_processes 2 timeout 30 preload_app true stderr_path File.expand_path('../../../../log/unicorn_stderr.log', __FILE__) app_path = File.expand_path('../../../', __FILE__) shared_path = File.expand_path('../../../shared/', __FILE__) pid "#{shared_path}/tmp/pids/unicorn.pid" before_fork do |server, worker| defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect! old_pid = "#{server.config[:pid]}.oldbin" if old_pid != server.pid begin sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU Process.kill(sig, File.read(old_pid).to_i) rescue Errno::ENOENT, Errno::ESRCH end end end after_fork do |server, worker| defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection end ``` # 環境 CentOS7 Nginx unicorn
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。