質問編集履歴
2
ログ、各staging\.rbの内容を追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -168,7 +168,141 @@
|
|
168
168
|
|
169
169
|
```
|
170
170
|
|
171
|
-
|
171
|
+
__追加__
|
172
|
+
|
173
|
+
ログ
|
174
|
+
|
175
|
+
```
|
176
|
+
|
177
|
+
INFO [47bc3a49] Running $HOME/.rbenv/bin/rbenv exec bundle exec unicorn -c /var/www/myapp/current/config/unicorn/staging.rb -E staging -D as yappari@(ipアドレス)
|
178
|
+
|
179
|
+
DEBUG [47bc3a49] Command: cd /var/www/myapp/current && ( export PATH="/usr/local/rbenv/shims:/usr/local/rbenv/bin:$PATH" RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.3.0" RAILS_ENV="staging" ; $HOME/.rbenv/bin/rbenv exec bundle exec unicorn -c /var/www/myapp/current/config/unicorn/staging.rb -E staging -D )
|
180
|
+
|
181
|
+
DEBUG [47bc3a49] bundler: failed to load command: unicorn (/var/www/myapp/shared/bundle/ruby/2.3.0/bin/unicorn)
|
182
|
+
|
183
|
+
```
|
184
|
+
|
185
|
+
config/unicorn/staging.rb
|
186
|
+
|
187
|
+
```
|
188
|
+
|
189
|
+
@app_path = '/var/www/myapp'
|
190
|
+
|
191
|
+
working_directory @app_path + "/current"
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
worker_processes 2
|
196
|
+
|
197
|
+
preload_app true
|
198
|
+
|
199
|
+
timeout 30
|
200
|
+
|
201
|
+
listen "/tmp/unicorn.sock", :backlog => 64
|
202
|
+
|
203
|
+
pid "/var/www/myapp/shared/tmp/pids/unicorn.pid"
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
stderr_path "#{@app_path}/log/unicorn.stderr.log"
|
208
|
+
|
209
|
+
stdout_path "#{@app_path}/log/unicorn.stdout.log"
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
before_fork do |server, worker|
|
214
|
+
|
215
|
+
ENV['BUNDLE_GEMFILE'] = File.expand_path('Gemfile', ENV['RAILS_ROOT'])
|
216
|
+
|
217
|
+
end
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
before_fork do |server, worker|
|
222
|
+
|
223
|
+
if defined?(ActiveRecord::Base)
|
224
|
+
|
225
|
+
ActiveRecord::Base.connection.disconnect!
|
226
|
+
|
227
|
+
end
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
old_pid = "#{server.config[:pid]}.oldbin"
|
232
|
+
|
233
|
+
if File.exists?(old_pid) && server.pid != old_pid
|
234
|
+
|
235
|
+
begin
|
236
|
+
|
237
|
+
Process.kill("QUIT", File.read(old_pid).to_i)
|
238
|
+
|
239
|
+
rescue Errno::ENOENT, Errno::ESRCH
|
240
|
+
|
241
|
+
end
|
242
|
+
|
243
|
+
end
|
244
|
+
|
245
|
+
end
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
after_fork do |server, worker|
|
250
|
+
|
251
|
+
if defined?(ActiveRecord::Base)
|
252
|
+
|
253
|
+
ActiveRecord::Base.establish_connection
|
254
|
+
|
255
|
+
end
|
256
|
+
|
257
|
+
end
|
258
|
+
|
259
|
+
```
|
260
|
+
|
261
|
+
config/deploy/staging.rb
|
262
|
+
|
263
|
+
```
|
264
|
+
|
265
|
+
set :rails_env, "staging"
|
266
|
+
|
267
|
+
set :unicorn_rack_env, "staging"
|
268
|
+
|
269
|
+
set :deploy_to, '/var/www/myapp'
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
user = "yappari"
|
274
|
+
|
275
|
+
ipaddress = "(ipアドレス)"
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
role :app, ["#{user}@#{ipaddress}"]
|
280
|
+
|
281
|
+
role :web, ["#{user}@#{ipaddress}"]
|
282
|
+
|
283
|
+
role :db, ["#{user}@#{ipaddress}"]
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
server '(ipアドレス)', user: 'yappari', roles: %w{web app}
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
set :ssh_options, {
|
292
|
+
|
293
|
+
keys: %w(/home/vagrant/.ssh/id_rsa),
|
294
|
+
|
295
|
+
forward_agent: true,
|
296
|
+
|
297
|
+
auth_methods: %w(publickey),
|
298
|
+
|
299
|
+
port: (ポート番号)
|
300
|
+
|
301
|
+
}
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
```
|
172
306
|
|
173
307
|
どうかお力を貸していただけないでしょうか?
|
174
308
|
|
1
ソースコードを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,9 +6,11 @@
|
|
6
6
|
|
7
7
|
こちらのサイトを参考にさせていただきまして、railsアプリのデプロイに挑戦しています。
|
8
8
|
|
9
|
-
|
9
|
+
ローカルのCentOSからさくらvpsへのデプロイです。
|
10
10
|
|
11
11
|
|
12
|
+
|
13
|
+
アプリ自体はrails new sample しただけの空っぽです。
|
12
14
|
|
13
15
|
|
14
16
|
|
@@ -50,4 +52,126 @@
|
|
50
52
|
|
51
53
|
|
52
54
|
|
55
|
+
|
56
|
+
|
57
|
+
###補足のソースコード
|
58
|
+
|
59
|
+
Capfile
|
60
|
+
|
61
|
+
```
|
62
|
+
|
63
|
+
require 'capistrano/setup'
|
64
|
+
|
65
|
+
require 'capistrano/deploy'
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
require 'sshkit/sudo'
|
70
|
+
|
71
|
+
# https://github.com/capistrano-plugins/capistrano-safe-deploy-to
|
72
|
+
|
73
|
+
require 'capistrano/safe_deploy_to' # 追加
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
# rbenvを使用している場合
|
78
|
+
|
79
|
+
require 'capistrano/rbenv'
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
# デプロイ先のサーバで、ユーザディレクトリでrbenvをインストールしている場合
|
84
|
+
|
85
|
+
set :rbenv_type, :user
|
86
|
+
|
87
|
+
set :rbenv_ruby, '2.3.0'
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
require 'capistrano/bundler'
|
92
|
+
|
93
|
+
require 'capistrano/rails/assets'
|
94
|
+
|
95
|
+
require 'capistrano/rails/migrations'
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
require 'capistrano3/unicorn'
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
# Rails4から分離したsecrets.ymlの環境変数を .envファイルで管理する
|
104
|
+
|
105
|
+
set :linked_files, %w{config/secrets.yml .env}
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
# タスクを読み込むけど、今回は特に使わない
|
110
|
+
|
111
|
+
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
|
112
|
+
|
113
|
+
```
|
114
|
+
|
115
|
+
deploy.rb
|
116
|
+
|
117
|
+
```
|
118
|
+
|
119
|
+
lock '3.4.1'
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
set :application, 'sample'
|
124
|
+
|
125
|
+
set :repo_url, 'git@github.com:yappari/sample.git'
|
126
|
+
|
127
|
+
set :branch, 'master'
|
128
|
+
|
129
|
+
set :deploy_to, '/var/www/myapp'
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
set :scm, :git
|
138
|
+
|
139
|
+
set :log_level, :debug
|
140
|
+
|
141
|
+
set :pty, true
|
142
|
+
|
143
|
+
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets bundle public/system public/assets}
|
144
|
+
|
145
|
+
set :default_env, { path: "/usr/local/rbenv/shims:/usr/local/rbenv/bin:$PATH" }
|
146
|
+
|
147
|
+
set :keep_releases, 5
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
after 'deploy:publishing', 'deploy:restart'
|
152
|
+
|
153
|
+
namespace :deploy do
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
desc 'Restart application'
|
158
|
+
|
159
|
+
task :restart do
|
160
|
+
|
161
|
+
invoke 'unicorn:restart'
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
```
|
170
|
+
|
171
|
+
|
172
|
+
|
53
173
|
どうかお力を貸していただけないでしょうか?
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
情報を追加いたしました。よろしくお願いいたします。
|