From 8f7630c73ae0bd1e65a8bf6da858a9edefb73452 Mon Sep 17 00:00:00 2001 From: Simon Sprankel Date: Wed, 18 Nov 2026 13:17:30 +0100 Subject: [PATCH] Make env.php swap in magento:cleanup_cache_prefix atomic The task deleted shared/app/etc/env.php before moving env_tmp.php into place. With the documented hook order the task runs before deploy:symlink, so the previous release is still being served and its env.php symlink dangles for the duration of two SSH round trips. A single mv -f is an atomic rename. The rm of the release symlink is dropped as well, because {{bin/symlink}} is ln -nfs and already replaces an existing link. --- docs/recipe/magento2.md | 10 +++++----- recipe/magento2.php | 7 +++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/docs/recipe/magento2.md b/docs/recipe/magento2.md index 98176c9d3..ccbb5b3a0 100644 --- a/docs/recipe/magento2.md +++ b/docs/recipe/magento2.md @@ -761,7 +761,7 @@ After successful deployment, move the tmp_env.php file to env.php ready for next ### magento\:cron\:stop {#magento-cron-stop} -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L595) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L594) Remove cron from crontab and kill running cron jobs. @@ -773,7 +773,7 @@ To use this feature, add the following to your deployer scripts: ### magento\:cron\:install {#magento-cron-install} -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L611) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L610) Install cron in crontab. @@ -785,7 +785,7 @@ To use this feature, add the following to your deployer scripts: ### artifact\:prepare {#artifact-prepare} -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L617) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L616) Prepares an artifact on the target server. @@ -805,7 +805,7 @@ This task is group task which contains next tasks: ### artifact\:finish {#artifact-finish} -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L630) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L629) Executes the tasks after artifact is released. @@ -821,7 +821,7 @@ This task is group task which contains next tasks: ### artifact\:deploy {#artifact-deploy} -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L639) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L638) Actually releases the artifact deployment. diff --git a/recipe/magento2.php b/recipe/magento2.php index 12d612657..b6602f166 100644 --- a/recipe/magento2.php +++ b/recipe/magento2.php @@ -577,10 +577,9 @@ function magentoDeployAssetsSplit(string $area): void */ desc('Cleanup cache id_prefix env files'); task('magento:cleanup_cache_prefix', function () { - run('rm {{deploy_path}}/shared/' . ENV_CONFIG_FILE_PATH); - run('rm {{release_or_current_path}}/' . ENV_CONFIG_FILE_PATH); - run('mv {{deploy_path}}/shared/' . TMP_ENV_CONFIG_FILE_PATH . ' {{deploy_path}}/shared/' . ENV_CONFIG_FILE_PATH); - // Symlink shared dir to release dir + // Atomic rename, so the currently served release never sees a missing env.php. + run('mv -f {{deploy_path}}/shared/' . TMP_ENV_CONFIG_FILE_PATH . ' {{deploy_path}}/shared/' . ENV_CONFIG_FILE_PATH); + // Symlink shared dir to release dir, {{bin/symlink}} already forces the overwrite run('{{bin/symlink}} {{deploy_path}}/shared/' . ENV_CONFIG_FILE_PATH . ' {{release_path}}/' . ENV_CONFIG_FILE_PATH); });