teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

該当コードの追加

2020/07/08 00:21

投稿

sakanafuto
sakanafuto

スコア0

title CHANGED
File without changes
body CHANGED
@@ -51,4 +51,153 @@
51
51
  Identity added: /home/Stelle/.ssh/xxx_key_rsa (/home/Stelle/.ssh/xxx_key_rsa)
52
52
  ```
53
53
 
54
- この後にローカルで先程のようにデプロイするとエラーに成ってしまいます。
54
+ この後にローカルで先程のようにデプロイするとエラーに成ってしまいます。
55
+
56
+ ##該当コード
57
+ `config/deproy.rb`
58
+ ```
59
+ lock "3.5.0"
60
+
61
+ set :application, "stelle"
62
+ set :repo_url, "git@github.com:sakanafuto/xxx.git"
63
+
64
+ set :deploy_to, "/var/www/stelle"
65
+
66
+ set :scm, :git
67
+ set :format, :pretty
68
+ set :log_level, :debug
69
+
70
+ set :pty, true
71
+
72
+ set :keep_releases, 5
73
+
74
+ set :rbenv_type, :user
75
+ set :rbenv_ruby, '2.6.5'
76
+
77
+ set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec"
78
+ set :rbenv_map_bins, %w{rake gem bundle ruby rails}
79
+
80
+ set :linked_files, fetch(:linked_files, []).push('config/master.key')
81
+
82
+ set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')
83
+
84
+ set :bundle_jobs, 4
85
+
86
+
87
+ namespace :deploy do
88
+
89
+ desc 'Restart application'
90
+ task :restart do
91
+ on roles(:app) do
92
+ invoke 'unicorn:restart'
93
+ end
94
+ end
95
+
96
+ desc 'Create database'
97
+ task :db_create do
98
+ on roles(:db) do |host|
99
+ with rails_env: fetch(:rails_env) do
100
+ within current_path do
101
+ execute :bundle, :exec, :rake, 'db:create'
102
+ end
103
+ end
104
+ end
105
+ end
106
+
107
+ desc 'Run seed'
108
+ task :seed do
109
+ on roles(:app) do
110
+ with rails_env: fetch(:rails_env) do
111
+ within current_path do
112
+ execute :bundle, :exec, :rake, 'db:seed'
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
118
+
119
+ after 'deploy:publishing', 'deploy:restart'
120
+ ```
121
+
122
+ `config/deploy/production.rb`
123
+ ```
124
+ server '3.xxx.xxx.x', user: 'Stelle', roles: %w{app db web}
125
+
126
+ set :ssh_options, {
127
+ keys: '~/.ssh/xxx_key_rsa',
128
+ forward_agent: true
129
+ }
130
+ ```
131
+
132
+ `config/unicorn/production.rb`
133
+
134
+ ```
135
+ app_path = '/var/www/stelle'
136
+
137
+ worker_processes 2
138
+ working_directory "#{app_path}" + "/current"
139
+
140
+ preload_app true
141
+
142
+ timeout 30
143
+
144
+ listen "/tmp/sockets/unicorn.sock", :backlog => 64
145
+
146
+ pid "#{app_path}/shared/tmp/pids/unicorn.pid"
147
+
148
+ # Set the path of the log files inside the log folder of the testapp
149
+ stderr_path "#{app_path}/current/log/unicorn.stderr.log"
150
+ stdout_path "#{app_path}/current/log/unicorn.stdout.log"
151
+
152
+ before_fork do |server, worker|
153
+ ENV['BUNDLE_GEMFILE'] = File.expand_path('Gemfile', ENV['RAILS_ROOT'])
154
+ end
155
+
156
+ before_fork do |server, worker|
157
+ defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!
158
+
159
+ old_pid = "#{server.config[:pid]}.oldbin"
160
+ if old_pid != server.pid
161
+ begin
162
+ sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
163
+ Process.kill(sig, File.read(old_pid).to_i)
164
+ rescue Errno::ENOENT, Errno::ESRCH
165
+ end
166
+ end
167
+
168
+ sleep 1
169
+ end
170
+
171
+ after_fork do |server, worker|
172
+ defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
173
+ end
174
+ ```
175
+
176
+ `Capfile`
177
+ ```
178
+ require "capistrano/setup"
179
+ require "capistrano/deploy"
180
+
181
+ # require "capistrano/scm/git"
182
+ # install_plugin Capistrano::SCM::Git
183
+
184
+ require "capistrano/rbenv"
185
+
186
+ require "capistrano/rails"
187
+ require "capistrano/rails/assets"
188
+ require "capistrano/rails/migrations"
189
+
190
+ require "capistrano/bundler"
191
+ require "capistrano3/unicorn"
192
+
193
+ Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
194
+ ```
195
+
196
+ `Gemfile`
197
+ ```
198
+ gem 'capistrano', '~>3.5.0'
199
+ gem 'capistrano-bundler', '~> 1.1.3'
200
+ gem 'capistrano-rails', '~> 1.1.7'
201
+ gem 'capistrano-rbenv'
202
+ gem 'capistrano3-unicorn'
203
+ ```