From a6bcfdadddd7d1178ee46d5cc1819c7ea60669b9 Mon Sep 17 00:00:00 2001 From: Stefan Paletta Date: Fri, 13 Mar 2015 11:51:27 +0100 Subject: [PATCH] =?UTF-8?q?when=20releasing=20or=20rolling=20back,=20don?= =?UTF-8?q?=E2=80=99t=20chown=20the=20=C2=BBcurrent=C2=AB=20symlink=20befo?= =?UTF-8?q?re=20we=20changed=20/=20created=20it.=20also=20don=E2=80=99t=20?= =?UTF-8?q?screw=20up=20the=20ssh=20cmdline=20if=20no=20username=20was=20g?= =?UTF-8?q?iven.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mage/Task/AbstractTask.php | 3 ++- Mage/Task/BuiltIn/Deployment/ReleaseTask.php | 13 +++++++------ Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php | 4 +++- Mage/Task/BuiltIn/Releases/RollbackTask.php | 12 +++++------- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/Mage/Task/AbstractTask.php b/Mage/Task/AbstractTask.php index 491adfb..5c4e36b 100644 --- a/Mage/Task/AbstractTask.php +++ b/Mage/Task/AbstractTask.php @@ -202,7 +202,8 @@ abstract class AbstractTask $localCommand = 'ssh ' . $this->getConfig()->getHostIdentityFileOption() . $needs_tty . ' -p ' . $this->getConfig()->getHostPort() . ' ' . '-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ' . $this->getConfig()->getConnectTimeoutOption() - . $this->getConfig()->deployment('user') . '@' . $this->getConfig()->getHostName(); + . ( $this->getConfig()->deployment('user') != '' ? $this->getConfig()->deployment('user') . '@' : '' ) + . $this->getConfig()->getHostName(); $remoteCommand = str_replace('"', '\"', $command); if ($cdToDirectoryFirst) { diff --git a/Mage/Task/BuiltIn/Deployment/ReleaseTask.php b/Mage/Task/BuiltIn/Deployment/ReleaseTask.php index 095116e..ce1d838 100644 --- a/Mage/Task/BuiltIn/Deployment/ReleaseTask.php +++ b/Mage/Task/BuiltIn/Deployment/ReleaseTask.php @@ -78,18 +78,19 @@ class ReleaseTask extends AbstractTask implements IsReleaseAware, SkipOnOverride $command = 'chown -R ' . $userGroup . ' ' . $currentCopy . ' && ' . 'chown ' . $userGroup . ' ' . $releasesDirectory; - if (file_exists($symlink)) { - $command.= ' && ' . 'chown -h ' . $userGroup . ' ' . $symlink; - } $result = $this->runCommandRemote($command); if (!$result) { return $result; } } - // Remove symlink if exists; create new symlink and change owner - $tmplink = $currentCopy . '.tmp'; - $command = "ln -sfn {$currentCopy} {$tmplink} && mv -fT {$tmplink} {$symlink}"; + // Switch symlink and change owner + $tmplink = $symlink . '.tmp'; + $command = "ln -sfn {$currentCopy} {$tmplink}"; + if ($resultFetch && $userGroup != '') { + $command.= " && chown -h {$userGroup} {$tmplink}"; + } + $command.= " && mv -fT {$tmplink} {$symlink}"; $result = $this->runCommandRemote($command); if ($result) { diff --git a/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php b/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php index cd8f648..c5a37b9 100644 --- a/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php +++ b/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php @@ -100,7 +100,9 @@ class RsyncTask extends BaseStrategyTaskAbstract implements IsReleaseAware . $this->excludes($excludes) . ' ' . $this->excludesListFile($excludesListFilePath) . ' ' . $this->getConfig()->deployment('from') . ' ' - . $this->getConfig()->deployment('user') . '@' . $this->getConfig()->getHostName() . ':' . $deployToDirectory; + . ( $this->getConfig()->deployment('user') ? $this->getConfig()->deployment('user') . '@' : '' ) + . $this->getConfig()->getHostName() . ':' . $deployToDirectory; + $result = $this->runCommandLocal($command); return $result; diff --git a/Mage/Task/BuiltIn/Releases/RollbackTask.php b/Mage/Task/BuiltIn/Releases/RollbackTask.php index a881ec6..c220c85 100644 --- a/Mage/Task/BuiltIn/Releases/RollbackTask.php +++ b/Mage/Task/BuiltIn/Releases/RollbackTask.php @@ -136,14 +136,12 @@ class RollbackTask extends AbstractTask implements IsReleaseAware $userGroup = ''; $resultFetch = $this->runCommandRemote('ls -ld ' . $rollbackTo . ' | awk \'{print \$3":"\$4}\'', $userGroup); - $tmplink = $rollbackTo . '.tmp'; - $command = 'ln -sfn ' . $currentCopy . ' ' . $tmplink - . ' && ' - . 'mv -T ' . $tmplink . ' ' . $symlink; - - if ($resultFetch) { - $command .= ' && chown -h ' . $userGroup . ' ' . $symlink; + $tmplink = $symlink . '.tmp'; + $command = "ln -sfn {$currentCopy} {$tmplink}"; + if ($resultFetch && $userGroup) { + $command .= " && chown -h {$userGroup} ${tmplink}"; } + $command .= " && mv -T {$tmplink} {$symlink}"; $result = $this->runCommandRemote($command);