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

質問編集履歴

6

状況を追記

2020/05/19 11:56

投稿

coffee_like
coffee_like

スコア4

title CHANGED
@@ -1,1 +1,1 @@
1
- AWS ECSにて、サービスで実行したタスクが3分程で停止してしまう原因がわからない
1
+ AWS ECSにて、サービスで実行したタスクが3分置きに停止してしまう原因がわからない
body CHANGED
@@ -81,263 +81,6 @@
81
81
  Service Auto Scaling: サービスの必要数を直接調整しない
82
82
  ```
83
83
 
84
- ```task
85
- # タスク定義
86
-
87
- {
88
- "ipcMode": null,
89
- "executionRoleArn": null,
90
- "containerDefinitions": [
91
- {
92
- "dnsSearchDomains": null,
93
- "environmentFiles": null,
94
- "logConfiguration": {
95
- "logDriver": "json-file",
96
- "secretOptions": null,
97
- "options": null
98
- },
99
- "entryPoint": null,
100
- "portMappings": [
101
- {
102
- "hostPort": 0,
103
- "protocol": "tcp",
104
- "containerPort": 443
105
- }
106
- ],
107
- "command": null,
108
- "linuxParameters": null,
109
- "cpu": 0,
110
- "environment": [],
111
- "resourceRequirements": null,
112
- "ulimits": null,
113
- "dnsServers": null,
114
- "mountPoints": [
115
- {
116
- "readOnly": null,
117
- "containerPath": "/rails-app-root/tmp/sockets",
118
- "sourceVolume": "sockets"
119
- },
120
- {
121
- "readOnly": null,
122
- "containerPath": "/var/log/nginx",
123
- "sourceVolume": "logs"
124
- }
125
- ],
126
- "workingDirectory": null,
127
- "secrets": null,
128
- "dockerSecurityOptions": null,
129
- "memory": null,
130
- "memoryReservation": null,
131
- "volumesFrom": [],
132
- "stopTimeout": null,
133
- "image": "nginx-image",
134
- "startTimeout": null,
135
- "firelensConfiguration": null,
136
- "dependsOn": [
137
- {
138
- "containerName": "nginx",
139
- "condition": "START"
140
- }
141
- ],
142
- "disableNetworking": null,
143
- "interactive": null,
144
- "healthCheck": null,
145
- "essential": true,
146
- "links": null,
147
- "hostname": null,
148
- "extraHosts": null,
149
- "pseudoTerminal": null,
150
- "user": null,
151
- "readonlyRootFilesystem": null,
152
- "dockerLabels": null,
153
- "systemControls": null,
154
- "privileged": null,
155
- "name": "nginx"
156
- },
157
- {
158
- "dnsSearchDomains": null,
159
- "environmentFiles": null,
160
- "logConfiguration": {
161
- "logDriver": "json-file",
162
- "secretOptions": null,
163
- "options": null
164
- },
165
- "entryPoint": null,
166
- "portMappings": [
167
- {
168
- "hostPort": 0,
169
- "protocol": "tcp",
170
- "containerPort": 3000
171
- }
172
- ],
173
- "command": [],
174
- "linuxParameters": null,
175
- "cpu": 0,
176
- "environment": [
177
- {
178
- "name": "DB_HOST",
179
- "value": "rds-endpoint"
180
- },
181
- {
182
- "name": "DB_PASSWORD",
183
- "value": "db-password"
184
- },
185
- {
186
- "name": "DB_PORT",
187
- "value": "db-port"
188
- },
189
- {
190
- "name": "DB_USER_NAME",
191
- "value": "db-user"
192
- },
193
- {
194
- "name": "JAVA_HOME",
195
- "value": "/usr/lib/jvm/java-1.8.0-openjdk-amd64"
196
- },
197
- {
198
- "name": "RAILS_ENV",
199
- "value": "production"
200
- },
201
- {
202
- "name": "RAILS_LOG_TO_STDOUT",
203
- "value": "ture"
204
- },
205
- {
206
- "name": "RAILS_MASTER_KEY",
207
- "value": "master-key-value"
208
- },
209
- {
210
- "name": "TZ",
211
- "value": "Asia/Tokyo"
212
- }
213
- ],
214
- "resourceRequirements": null,
215
- "ulimits": null,
216
- "dnsServers": null,
217
- "mountPoints": [
218
- {
219
- "readOnly": null,
220
- "containerPath": "/rails-app-root/tmp/sockets",
221
- "sourceVolume": "sockets"
222
- },
223
- {
224
- "readOnly": null,
225
- "containerPath": "/rails-app-root/log",
226
- "sourceVolume": "logs"
227
- }
228
- ],
229
- "workingDirectory": null,
230
- "secrets": null,
231
- "dockerSecurityOptions": null,
232
- "memory": null,
233
- "memoryReservation": null,
234
- "volumesFrom": [],
235
- "stopTimeout": null,
236
- "image": "rails-app-image",
237
- "startTimeout": null,
238
- "firelensConfiguration": null,
239
- "dependsOn": null,
240
- "disableNetworking": null,
241
- "interactive": null,
242
- "healthCheck": null,
243
- "essential": true,
244
- "links": null,
245
- "hostname": null,
246
- "extraHosts": null,
247
- "pseudoTerminal": null,
248
- "user": null,
249
- "readonlyRootFilesystem": null,
250
- "dockerLabels": null,
251
- "systemControls": null,
252
- "privileged": null,
253
- "name": "rils-app"
254
- }
255
- ],
256
- "placementConstraints": [],
257
- "memory": "512",
258
- "taskRoleArn": null,
259
- "compatibilities": [
260
- "EC2"
261
- ],
262
- "taskDefinitionArn": "arn:aws:ecs:ap-northeast-1:arn-number:task-definition/task-name:task-number",
263
- "family": "rails_app_task",
264
- "requiresAttributes": [
265
- {
266
- "targetId": null,
267
- "targetType": null,
268
- "value": null,
269
- "name": "com.amazonaws.ecs.capability.ecr-auth"
270
- },
271
- {
272
- "targetId": null,
273
- "targetType": null,
274
- "value": null,
275
- "name": "ecs.capability.docker-plugin.local"
276
- },
277
- {
278
- "targetId": null,
279
- "targetType": null,
280
- "value": null,
281
- "name": "ecs.capability.container-ordering"
282
- },
283
- {
284
- "targetId": null,
285
- "targetType": null,
286
- "value": null,
287
- "name": "com.amazonaws.ecs.capability.docker-remote-api.1.25"
288
- },
289
- {
290
- "targetId": null,
291
- "targetType": null,
292
- "value": null,
293
- "name": "com.amazonaws.ecs.capability.logging-driver.json-file"
294
- },
295
- {
296
- "targetId": null,
297
- "targetType": null,
298
- "value": null,
299
- "name": "com.amazonaws.ecs.capability.docker-remote-api.1.18"
300
- }
301
- ],
302
- "pidMode": null,
303
- "requiresCompatibilities": [
304
- "EC2"
305
- ],
306
- "networkMode": "bridge",
307
- "cpu": "512",
308
- "revision": 96,
309
- "status": "ACTIVE",
310
- "inferenceAccelerators": null,
311
- "proxyConfiguration": null,
312
- "volumes": [
313
- {
314
- "efsVolumeConfiguration": null,
315
- "name": "sockets",
316
- "host": null,
317
- "dockerVolumeConfiguration": {
318
- "autoprovision": null,
319
- "labels": null,
320
- "scope": "task",
321
- "driver": "local",
322
- "driverOpts": null
323
- }
324
- },
325
- {
326
- "efsVolumeConfiguration": null,
327
- "name": "logs",
328
- "host": null,
329
- "dockerVolumeConfiguration": {
330
- "autoprovision": null,
331
- "labels": null,
332
- "scope": "task",
333
- "driver": "local",
334
- "driverOpts": null
335
- }
336
- }
337
- ]
338
- }
339
- ```
340
-
341
84
  ```RailsApp
342
85
  # Dockerfile
343
86
 
@@ -422,4 +165,37 @@
422
165
  ALBが絡むくらいしか差分はないように思うのですが、ALBが原因であるとは考えづらいです、、。
423
166
  このような問題の想定原因をご教授頂けますと幸いです。
424
167
 
425
- 宜しくお願い致します。
168
+ 宜しくお願い致します。
169
+
170
+ ### 追記
171
+
172
+ 5/19
173
+ 調べると以下の公式資料が該当し、停止したタスクには停止理由が表示されるとのことでした。
174
+ コンソールから確認すると、以下のようになっていました。
175
+
176
+ ```
177
+ 停止理由: Scaling activity initiated by deployment ecs-svc/123456789001122
178
+ ```
179
+
180
+ タスクの実行数を1にしてデプロイしているのですが、今回の問題だと永遠に新しいタスクが実行されてしまうため、確認したいことが終わるとタスク数を0にすることにより対応しています。
181
+ 上記は、そのタスク数0の変更に対してサービスが対応した結果だと思われます.
182
+
183
+
184
+
185
+ ```
186
+ 停止理由: Task failed ELB health checks in (target-group arn:aws:elasticloadbalancing:ap-northeast-1:...)
187
+ ```
188
+ 3分置きに終了してしまうタスクには、この様な停止理由が書かれていました。
189
+ タスクは、ターゲーットグループのヘルスチェックが何回か失敗すると、自動的に停止する仕様になっているのでしょうか?
190
+ ヘルスチェックがなぜ失敗するのか、原因を調査してみます。
191
+
192
+ 取り急ぎ、共有させて頂きます。
193
+
194
+
195
+ [https://docs.aws.amazon.com/ja_jp/AmazonECS/latest/developerguide/stopped-task-errors.html](https://docs.aws.amazon.com/ja_jp/AmazonECS/latest/developerguide/stopped-task-errors.html)
196
+
197
+ もう一つ追記です。
198
+ タスク数を2にしてデプロイしてみましたが、状況は変わりませんでした。
199
+ むしろ、実行されているタスク数は1から変わらず、少々おかしいような気がします。
200
+ こちらは、当方のECSやオートスケーリング、タスク配置についての理解不足が原因で、タスク数1が正常なのかなとも思っております。
201
+ こちらも共有させて頂きます。

5

追記

2020/05/19 11:56

投稿

coffee_like
coffee_like

スコア4

title CHANGED
File without changes
body CHANGED
@@ -8,6 +8,10 @@
8
8
  以前は問題なくサービスを実行できていたのですが、アプリの開発を行い、タスク定義をアップデートしたところ、
9
9
  上記のような問題が発生しました。
10
10
 
11
+ *5/19追記
12
+ 以前は問題なくサービスを実行できたと書きましたが、確認してみると、以前のコードでも上手く動きませんでした。
13
+ コード以外になんらかの変更を加えてしまい、それが原因となっている可能性が高そうです。
14
+
11
15
  ### 構成・前提
12
16
 
13
17
  ```

4

誤字を修正

2020/05/19 10:48

投稿

coffee_like
coffee_like

スコア4

title CHANGED
File without changes
body CHANGED
@@ -415,7 +415,7 @@
415
415
  なぜ、タスクは数分ですぐに停止してしまうのでしょうか?
416
416
 
417
417
  サービスを通さずに単発でタスクを実行した状態と、サービスを通してタスクを実行した状態の差分に原因があると考えていますが、その原因をつかめておりません。
418
- ALBが絡むくらいしか差分はないように思うのですが、ALBが原因であるとは考えづらいです、、。
418
+ ALBが絡むくらいしか差分はないように思うのですが、ALBが原因であるとは考えづらいです、、。
419
419
  このような問題の想定原因をご教授頂けますと幸いです。
420
420
 
421
421
  宜しくお願い致します。

3

ログに関する記載を追加

2020/05/19 09:04

投稿

coffee_like
coffee_like

スコア4

title CHANGED
@@ -1,1 +1,1 @@
1
- AWS ECSにて、サービスで実行したタスクが分で停止してしまう原因がわからない
1
+ AWS ECSにて、サービスで実行したタスクが3で停止してしまう原因がわからない
body CHANGED
@@ -50,6 +50,10 @@
50
50
  (Nginxコンテナは、443ポートで動的ポートマッピングしているため、`HTTP`にすることによりNginxコンテナへのヘルスチェックの通信を切る形になります)
51
51
 
52
52
 
53
+ ### ログ
54
+
55
+ Dockerの標準出力、NginxとRailsAppのログファイルにも、ログは一切出力されませんでした。
56
+
53
57
  ### 該当のソースコード
54
58
 
55
59
  ```servise

2

修正

2020/05/19 09:03

投稿

coffee_like
coffee_like

スコア4

title CHANGED
File without changes
body CHANGED
@@ -358,7 +358,7 @@
358
358
  FROM nginx:1.15.8
359
359
 
360
360
  RUN rm -f /etc/nginx/conf.d/*
361
- ADD docker/nginx/nginx.pro.conf /etc/nginx/conf.d/umbrellanotice.conf
361
+ ADD docker/nginx/nginx.pro.conf /etc/nginx/conf.d/rails_app.conf
362
362
 
363
363
  RUN apt-get update \
364
364
  && apt-get install -y \

1

タイポの修正, unicornの追加

2020/05/19 08:26

投稿

coffee_like
coffee_like

スコア4

title CHANGED
File without changes
body CHANGED
@@ -74,6 +74,8 @@
74
74
  ```
75
75
 
76
76
  ```task
77
+ # タスク定義
78
+
77
79
  {
78
80
  "ipcMode": null,
79
81
  "executionRoleArn": null,
@@ -328,7 +330,7 @@
328
330
  }
329
331
  ```
330
332
 
331
- ```rilsapp
333
+ ```RailsApp
332
334
  # Dockerfile
333
335
 
334
336
  FROM ruby:2.5.1