docs(ops): 起動スクリプトをリポジトリ管理下に置き、本番障害の罠を記録 - #7
Merged
Merged
Conversation
PM2 が実行している /opt/appcfg/toolify-start.sh は VPS 上にしか存在せず、 全ブランチの履歴を通じて一度も追跡されていなかった(VPS のディスクが飛べば 復元手段がない)。現物をそのまま ops/toolify-start.sh として取り込む。 あわせて docs/DEPLOY.md に 2026-09-17〜18 の本番障害で判明した罠を記録: - rsync -az --delete の同期先に起動スクリプトを置くと毎回消える(502 の原因) - HOSTNAME=127.0.0.1 は自己 proxy の EPROTO で全ページ 500。公開ドメイン名を使う - 既定ポート 3000 は別アプリが占有しているので PORT=8500 が必須 - NODE_OPTIONS の heap 上限 300 では V8 が OOM abort する(現在 400) - dump.pm2 の古い値は実効値を汚さない。判定は /proc/<pid>/environ で行う - 上記はいずれもデプロイが「成功」表示のまま起きる(落ちるのはスモークテストだけ) deploy.yml は変更しない。自動配置は上記1点目と干渉するため反映は手動のままとする。 本番の挙動は変わらない(ドキュメントとスクリプトの保全のみ)。 Claude-Session: https://claude.ai/code/session_01ENHPNZ5ngcdrTHJ2H6oAFd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
2026-09-17〜18 に本番が 502 → 500 と連続で停止した。復旧の過程で、
PM2 が実行している起動スクリプトが VPS 上にしか存在しないことが判明した。
VPS のディスクが飛べば復元手段がない。スクリプト自身は冒頭で
「リポジトリ内の本ファイルがソース」と述べていたが、事実と異なっていた。
変更
ops/toolify-start.shを追加。VPS の現物をそのまま取得(diff 0 で一致を確認済み)。冒頭コメントだけ、正本の所在と反映手順を事実に合わせて修正した。
docs/DEPLOY.mdに「0. 起動スクリプトと踏んだ罠」を追加。記録した罠(すべて実際に本番を落としたもの)
rsync -az --deleteの同期先に起動スクリプトを置くHOSTNAME=127.0.0.1EPROTOで 全ページ 500PORT未指定EADDRINUSENODE_OPTIONSheap 300Ineffective mark-compactsで abortdump.pm2の古い値2 の切り分けは nginx と同じヘッダを付けて叩く必要がある(素の curl は 200 を返す)。
5 は「古い値が残っている=危険」と短絡しかけた例で、
pm2 delete→pm2 resurrectで実地に再現して実害なしと確認した経緯まで残した。
変更しないもの
deploy.ymlは触っていない。 スクリプトの自動配置は罠 1 と干渉して同じ事故を作り込むため、VPS への反映は手動のままとする(手順は DEPLOY.md に記載)。
本番の挙動は一切変わらない(ドキュメントとスクリプトの保全のみ)。
https://claude.ai/code/session_01ENHPNZ5ngcdrTHJ2H6oAFd