Repository: isucon/isucon11-qualify (language: go)

Issue:
[infra] bench を再起動したらベンチにコケるようになる問題の修正
* ベンチは初回起動時に JIA_SERVICE_URL に値を変える
* ベンチを再起動すると GIP が変わる
* ベンチにコケる

> 21:23:53.422240 ===> PREPARE
> 21:24:01.679216 ERR: prepare: timeout: http: timeout: Post "https://3.115.149.10/api/isu": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
> 21:24:04.682904 ERR: prepare: timeout: http: timeout: Post "https://3.115.149.10/api/isu": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
> 21:24:04.683049 ERR: prepare: critical: アプリケーション互換性チェックに失敗しました


Discussion / hints:
~~@ryoha000 さんにお願いしました :kansya:~~

issue 間違えた


Fix patch:
diff --git a/provisioning/ansible/roles/bench.supervisor/files/etc/systemd/system/isuxportal-supervisor.service b/provisioning/ansible/roles/bench.supervisor/files/etc/systemd/system/isuxportal-supervisor.service
index 1d6f999f0..9cd936a67 100644
--- a/provisioning/ansible/roles/bench.supervisor/files/etc/systemd/system/isuxportal-supervisor.service
+++ b/provisioning/ansible/roles/bench.supervisor/files/etc/systemd/system/isuxportal-supervisor.service
@@ -24,6 +24,8 @@ EnvironmentFile=/home/isucon/isuxportal-supervisor.env
 AmbientCapabilities=CAP_NET_BIND_SERVICE
 CapabilityBoundingSet=CAP_NET_BIND_SERVICE
 
+# bench の public address を取得して EnvironmentFile に追記 or 更新する
+ExecStartPre=/home/isucon/bin/generate-env.sh
 # bench 差し替えを graceful に行うための設定
 ExecStartPre=-/bin/mv /tmp/isuxportal-supervisor /home/isucon/bin/isuxportal-supervisor
 ExecStartPre=-/bin/mv /tmp/bench /home/isucon/bench/bench
diff --git a/provisioning/ansible/roles/bench.supervisor/files/home/isucon/bin/generate-env_aws.sh b/provisioning/ansible/roles/bench.supervisor/files/home/isucon/bin/generate-env_aws.sh
new file mode 100644
index 000000000..bc92bba9e
--- /dev/null
+++ b/provisioning/ansible/roles/bench.supervisor/files/home/isucon/bin/generate-env_aws.sh
@@ -0,0 +1,14 @@
+#!/usr/bin/env bash
+
+TARGET_FILE=/home/isucon/isuxportal-supervisor.env
+PUBLIC_ADDR="$(curl -s --retry 5 --retry-connrefused --max-time 10 --connect-timeout 5 http://169.254.169.254/latest/meta-data/public-ipv4)"
+
+if egrep '^JIA_SERVICE_URL' ${TARGET_FILE} &> /dev/null; then
+perl -pi -e 's|^(JIA_SERVICE_URL=).*$|$1"http://'${PUBLIC_ADDR}':5000"|g' ${TARGET_FILE}
+else
+cat << _EOF_ >> ${TARGET_FILE}
+JIA_SERVICE_URL="http://${PUBLIC_ADDR}:5000"
+_EOF_
+fi
+
+chown isucon: ${TARGET_FILE}
diff --git a/provisioning/ansible/roles/bench.supervisor/files/var/lib/cloud/scripts/per-instance/generate-env_aws.sh b/provisioning/ansible/roles/bench.supervisor/files/var/lib/cloud/scripts/per-instance/generate-env_aws.sh
deleted file mode 100644
index f85a4b495..000000000
--- a/provisioning/ansible/roles/bench.supervisor/files/var/lib/cloud/scripts/per-instance/generate-env_aws.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/usr/bin/env bash
-
-cat << _EOF_ >> /home/isucon/isuxportal-supervisor.env
-JIA_SERVICE_URL="http://$(curl -s --retry 5 --retry-connrefused --max-time 10 --connect-timeout 5 http://169.254.169.254/latest/meta-data/public-ipv4):5000"
-_EOF_
-chown isucon: /home/isucon/isuxportal-supervisor.env
diff --git a/provisioning/ansible/roles/bench.supervisor/tasks/generate_env.yml b/provisioning/ansible/roles/bench.supervisor/tasks/generate_env.yml
index c52e8abb9..c771cdfab 100644
--- a/provisioning/ansible/roles/bench.supervisor/tasks/generate_env.yml
+++ b/provisioning/ansible/roles/bench.supervisor/tasks/generate_env.yml
@@ -4,8 +4,8 @@
     - aws
   become_user: root
   copy:
-    src: "var/lib/cloud/scripts/per-instance/generate-env_aws.sh"
-    dest: "/var/lib/cloud/scripts/per-instance/generate-env.sh"
-    owner: "root"
-    group: "root"
+    src: "home/isucon/bin/generate-env_aws.sh"
+    dest: "/home/isucon/bin/generate-env.sh"
+    owner: "isucon"
+    group: "isucon"
     mode: "0755"


Test patch: