Taku’s Teckブログ

Teckはわざとです。

gcloudが動かなくなった話と、GPUを積んだGCEのメンテナンスについて

今日仕事でハマったことの話

gcloudが動かなくなった

久しぶりのサーバーメンテでgcloudコマンドを実行しようとしたところ、実行できなくなっていた。

※解決策を探してこられた方は「解決法」まで

-> % gcloud
ERROR:root:code for hash md5 was not found.
Traceback (most recent call last):
File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 147, in <module>
globals()[__func_name] = __get_hash(__func_name)
File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
raise ValueError('unsupported hash type ' + name)
...
(省略)
...
def __init__(self, algorithm=hashlib.sha256):

This usually indicates corruption in your gcloud installation or problems with your Python interpreter.

Please verify that the following is the path to a working Python 2.7 or 3.5+ executable:
/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python

If it is not, please set the CLOUDSDK_PYTHON environment variable to point to a working Python 2.7 or 3.5+ executable.

If you are still experiencing problems, please reinstall the Cloud SDK using the instructions here:
https://cloud.google.com/sdk/
gcloudが動かなくなったので試したこと

pythonがおかしくなったのか、アップデートとか色々試してみる。

% brew reinstall python@2

Python 2系を使っているようなのでまずこれをやったけど変わらず。

% brew reinstall python

→じゃあバージョン指定しなければ?とやったけど変わらず。

そこで、

If you are still experiencing problems, please reinstall the Cloud SDK using the instructions here: https://cloud.google.com/sdk/

(Cloud SDKを再インストールしろ)

とあったので

curl https://sdk.cloud.google.com | bash

やろうとしたが、ここでも同じく

ERROR:root:code for hash md5 was not found.
Traceback (most recent call last):

らがでる。

どうしたもんかと思いまたもGoogle先生

gcloud ERROR:root:code for hash md5 was not found.

とかと助けを求めると、いくつかヒットするので皆同じようなことが起こってるんだなと。

まずこれを参考に

qiita.com

$ brew update && brew upgrade

バージョンの問題で、全部アップグレードしてしまえと。 やってみたところ結果は変わらず。

解決法

最終的に解決になったのはこちら teratail.com

正確には回答の参考になったという以下のリンク

medium.com

$ brew switch openssl 1.0.2r Cleaning /usr/local/Cellar/openssl/1.0.2q Opt link created for /usr/local/Cellar/openssl/1.0.2q

brew upgradeの後にswitchで切り替える必要があった。

なのでまず

$ ls /usr/local/Cellar/openssl

でどのバージョンがインストールされているか確認し、

表示されたバージョンに切り替える

$ brew switch openssl 1.0.2r Cleaning /usr/local/Cellar/openssl/1.0.2q Opt link created for /usr/local/Cellar/openssl/1.0.2q

これにてgcloudが動くように。結局なぜこうなったか理解までは至らなかったものの、解決までに色々試したり(DL待ちが長い)ググったりで2〜3時間かかってしまった。

GPUを積んだGCEのメンテナンス

GCEの仕組みについてわかっておらず、サーバーが勝手に再起動されていたのでその調査をして分かったこと。

保守を引き継いだサーバーでcronが仕込まれてないのに再起動された形跡があったので調べる。

StackDriverのログとかと追ったところ、再起動されたタイミングに

compute.instances.terminateOnHostMaintenance

というログが。

これを調べるとメンテナンスが、ライブマイグレーションで行われない際に実行されるものらしい。

インスタンス可用性ポリシーの設定  |  Compute Engine ドキュメント  |  Google Cloud

こちらは、GCEには「ライブマイグレーション*1」と言う無停止でメンテナンス(ソフトやハードの更新)を行ってくれる素晴らしい機能があるのだけど、GPU積んでる場合は使えず再起動されるとのことであった。

cloud.google.com

メンテナンスも月1行われるけど、いつされるかはされる60分前にならないとわからない。

これが最初の導入者が理解して織り込み済みだったかは定かではないが、おそらくこれまで気にせず運用されていたと想定・・

60分前にならないとわからず、その時に別のホストに移すとは厳しいなと思いつつ、 一旦は月に 1 回実行であり、そこまでクリティカルなサーバー出ないとのことで対応は見送り。

こんなそんなで1日トラブル対応に費やした日であった。

*1:参照:apps-gcp.com