Repository navigation
lftp での WordPress メンテ表示対応 + マーカー処理の mtime 保存(差分転送の改善) - #3
Merged
Merged
Conversation
3点の改善: 1. include の sed で mtime を保存(php / wordpress) sed -i は置換が無くてもファイルを書き直して mtime を更新するため、全 .php を 無条件に sed -i すると、git-restore-mtime 等で安定させた mtime が毎回更新され、 lftp mirror が未変更ファイルまで再送していた。grep で対象を絞り、sed 前後で mtime を保存・復元することで差分転送を効かせる(挙動=マーカー除去結果は同一)。 2. wordpress include を rsync(SSH) / lftp(FTP) 両対応に メンテ表示の .maintenance 設置/削除を $DEP_COMMAND で分岐(rsync は ssh、 lftp は lftp で put/rm)。パーミッション設定は SSH 前提のため lftp では skip。 DEP_WP_DIR(.maintenance の設置先, 既定 wp) を追加。 3. deploy.sh に EXIT trap の teardown フックを追加 include で on_teardown が定義されていれば、同期の成功・失敗・中断いずれでも 必ず実行する。これによりメンテ表示の解除を確実化。あわせて .maintenance の $upgrading を未来時刻(既定60分, DEP_MAINTENANCE_MAX_MINUTES)に設定し、WP の 10分自動解除で長時間デプロイの途中解除を防ぎつつ、teardown 失敗時は自動復帰。
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.
背景
福永紙工サイト(lftp/FTP デプロイ・SSH不可)の自動デプロイ導入中に、以下2つの実運用課題が判明したため改善します。
git-restore-mtimeで mtime を安定化しても、include のbefore_syncが全 .php を無条件にsed -iするため mtime が毎回更新され、lftp mirrorが変更の無い .php(実測で約2,244件)を毎回再送していた。wordpress/.depinc.shはメンテ表示・パーミッション設定が SSH 前提で、FTP のみのサーバでは利用できなかった。変更内容
1. include の sed で mtime を保存(
php/wordpress/)grepで実際にマーカー(#DEP_*_RM///DEP_*_RM)を含むファイルだけを対象化。sedの前後で mtime を保存・復元(stat -c %Y→touch -d @<epoch>)。2.
wordpress/.depinc.shを rsync(SSH) / lftp(FTP) 両対応に.maintenance設置/削除を$DEP_COMMANDで分岐(rsync→ssh、lftp→lftp の put/rm)。DEP_WP_DIR(.maintenanceの設置先, 既定wp)を追加。3.
deploy.shに EXIT trap の teardown フックon_teardownを定義していれば、同期の成功・失敗・中断いずれでも必ず実行(trap ... EXIT)。.maintenanceの$upgradingを未来時刻(既定60分,DEP_MAINTENANCE_MAX_MINUTES)に設定。WP の10分自動解除による長時間デプロイ途中での解除を防ぎつつ、teardown が万一走らなくてもこの時間で自動復帰(永久ロック防止)。互換性
$upgradingが time() → 未来時刻に変更)。.depignoreに.maintenanceを含めること(既存ドキュメント通り)。検証状況
.maintenanceput/rm と、失敗時の teardown 動作。備考
stat -c/touch -d @)前提です(ubuntu-latest ランナー想定。既存 include も GNU 前提のsed -iを使用)。🤖 Generated with Claude Code