質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Capistrano

Rubyで書かれたサーバオーケストレーションで、複数のサーバでスクリプトを実行する際に用いられます。主な使用用途はWebアプリケーションのデプロイメントです。 アプリケーションのバージョンアップ自動化、およびデータベースの変更などもできます。

Q&A

0回答

304閲覧

Capistranoでデプロイするたびにサーバーからの反応が遅くなる。

adwadwadw

総合スコア56

Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Capistrano

Rubyで書かれたサーバオーケストレーションで、複数のサーバでスクリプトを実行する際に用いられます。主な使用用途はWebアプリケーションのデプロイメントです。 アプリケーションのバージョンアップ自動化、およびデータベースの変更などもできます。

0グッド

0クリップ

投稿2017/12/26 10:22

Capistranoを使って自動デプロイをしています。デプロイを何回か繰り返していくうちに、コマンドを入力してからの反応が遅くなりました。どんどん自動デプロイの時間が数十倍にもなり、最終的にはWebpackerでcompileしている時に停止してしまいました。どのようなことが原因だと考えられるでしょうか。特にエラーログは出ておりません。
一度サーバーを停止して、また起動すると回復しますが、またデプロイを繰り返すと遅くなります。

deploy.rb

ruby

1# config valid for current version and patch releases of Capistrano 2lock '3.10.1' 3 4# デプロイするアプリケーション名 5set :application, 'project' 6 7# cloneするgitのレポジトリ 8set :repo_url, 'http://url' 9 10# deployするブランチ。デフォルトはmasterなのでなくても可。 11set :branch, 'master' 12 13# deploy先のディレクトリ。 14set :deploy_to, '/var/www/project' 15 16# シンボリックリンクファイル。 17set :linked_files, fetch(:linked_files, []).push('config/settings.yml') 18 19# シンボリックリンクフォルダ。 20set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system') 21# 保持するバージョン数 22set :keep_releases, 3 23 24# rubyのバージョン(例) 25set :rbenv_ruby, '2.4.1' 26set :whenever_environment, :production 27set :whenever_identifier, ->{ "#{fetch(:application)}_#{fetch(:stage)}" } 28 29#ログのレベル。 30set :log_level, :debug 31 32# コネクション継続 33set :ssh_options, :keepalive => true 34 35set :unicorn_pid, "#{shared_path}/tmp/pids/unicorn.pid" 36set :unicorn_config_path, "#{release_path}/config/unicorn.rb" 37 38after 'deploy:publishing', 'deploy:restart' 39namespace :deploy do 40 desc 'Restart application' 41 task :restart do 42 invoke 'unicorn:restart' 43 end 44end

deploy/production.rb

ruby

1server 'ip', user: 'user', roles: %w{app db web} 2 3#ssh 4set :ssh_options, keys: '~/.ssh/key'

Capfile

Capfile

1require 'capistrano/setup' 2require 'capistrano/deploy' 3require "capistrano/scm/git" 4install_plugin Capistrano::SCM::Git 5require 'capistrano/bundler' 6require 'capistrano/rbenv' 7require 'capistrano/rails' 8require 'capistrano/rails/assets' 9require 'capistrano/rails/migrations' 10require 'capistrano3/unicorn' 11require 'capistrano/yarn' 12require "whenever/capistrano" 13# Load custom tasks from `lib/capistrano/tasks` if you have any defined 14Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r } 15

lib/capistrano/tasks/uniconr.rake

rake

1namespace :load do 2 task :defaults do 3 set :unicorn_pid, -> { File.join(current_path, "tmp", "pids", "unicorn.pid") } 4 set :unicorn_rack_env, -> { fetch(:rails_env) ? fetch(:rails_env) : "deployment" } 5 set :unicorn_config_path, -> { File.join(current_path, "config", "unicorn", "#{fetch(:unicorn_rack_env)}.rb") } 6 set :unicorn_roles, -> { :app } 7 set :unicorn_options, -> { "" } 8 set :unicorn_restart_sleep_time, 3 9 set :unicorn_exec, -> { "unicorn" } 10 end 11end 12 13namespace :unicorn do 14 desc "Start Unicorn" 15 task :start do 16 on roles(fetch(:unicorn_roles)) do 17 within current_path do 18 if test("[ -e #{fetch(:unicorn_pid)} ] && kill -0 #{pid}") 19 info "unicorn is running..." 20 else 21 with rails_env: fetch(:rails_env) do 22 execute :bundle, "exec #{fetch(:unicorn_exec)}", "-c", fetch(:unicorn_config_path), "-E", fetch(:unicorn_rack_env), "-D", fetch(:unicorn_options) 23 end 24 end 25 end 26 end 27 end 28 29 desc "Stop Unicorn (QUIT)" 30 task :stop do 31 on roles(fetch(:unicorn_roles)) do 32 within current_path do 33 if test("[ -e #{fetch(:unicorn_pid)} ]") 34 if test("kill -0 #{pid}") 35 info "stopping unicorn..." 36 execute :kill, "-s QUIT", pid 37 else 38 info "cleaning up dead unicorn pid..." 39 execute :rm, fetch(:unicorn_pid) 40 end 41 else 42 info "unicorn is not running..." 43 end 44 end 45 end 46 end 47 48 desc "Reload Unicorn (HUP); use this when preload_app: false" 49 task :reload do 50 invoke "unicorn:start" 51 on roles(fetch(:unicorn_roles)) do 52 within current_path do 53 info "reloading..." 54 execute :kill, "-s HUP", pid 55 end 56 end 57 end 58 59 desc "Restart Unicorn (USR2); use this when preload_app: true" 60 task :restart do 61 invoke "unicorn:start" 62 on roles(fetch(:unicorn_roles)) do 63 within current_path do 64 info "unicorn restarting..." 65 execute :kill, "-s USR2", pid 66 end 67 end 68 end 69 70 desc "Duplicate Unicorn; alias of unicorn:restart" 71 task :duplicate do 72 invoke "unicorn:restart" 73 end 74 75 desc "Legacy Restart (USR2 + QUIT); use this when preload_app: true and oldbin pid needs cleanup" 76 task :legacy_restart do 77 invoke "unicorn:restart" 78 on roles(fetch(:unicorn_roles)) do 79 within current_path do 80 execute :sleep, fetch(:unicorn_restart_sleep_time) 81 if test("[ -e #{fetch(:unicorn_pid)}.oldbin ]") 82 execute :kill, "-s QUIT", pid_oldbin 83 end 84 end 85 end 86 end 87 88 desc "Add a worker (TTIN)" 89 task :add_worker do 90 on roles(fetch(:unicorn_roles)) do 91 within current_path do 92 info "adding worker" 93 execute :kill, "-s TTIN", pid 94 end 95 end 96 end 97 98 desc "Remove a worker (TTOU)" 99 task :remove_worker do 100 on roles(fetch(:unicorn_roles)) do 101 within current_path do 102 info "removing worker" 103 execute :kill, "-s TTOU", pid 104 end 105 end 106 end 107end 108 109def pid 110 "`cat #{fetch(:unicorn_pid)}`" 111end 112 113def pid_oldbin 114 "`cat #{fetch(:unicorn_pid)}.oldbin`" 115end

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問