获取当前进程配置的ansible状态
public static getAnsibleStatus ( ) : boolean | ||
return | boolean |
/** * 收尾做处理工作,如清理本地的部署空间 * * @param $version * @return bool|int */ public function cleanUpLocal($version) { $cmd[] = 'rm -rf ' . Project::getDeployWorkspace($version); if (Project::getAnsibleStatus()) { $cmd[] = 'rm -f ' . Project::getDeployPackagePath($version); } if ($this->config->repo_type == Project::REPO_SVN) { $cmd[] = sprintf('rm -rf %s-svn', rtrim(Project::getDeployWorkspace($version), '/')); } $command = join(' && ', $cmd); return $this->runLocalCommand($command); }
/** * 传输文件/目录到指定目标机器 * * @return bool * @throws \Exception */ private function _transmission() { if (Project::getAnsibleStatus()) { // ansible copy return $this->_ansibleCopy(); } else { // 循环 rsync return $this->_rsync(); } }
/** * 执行远程服务器任务集合 * 对于目标机器更多的时候是一台机器完成一组命令,而不是每条命令逐台机器执行 * * @param array $tasks * @param integer $delay 每台机器延迟执行post_release任务间隔, 不推荐使用, 仅当业务无法平滑重启时使用 * @return mixed */ public function runRemoteTaskCommandPackage($tasks, $delay = 0) { $task = join(' && ', $tasks); if (Project::getAnsibleStatus() && !$delay) { // ansible 并发执行远程命令 return $this->runRemoteCommandByAnsibleShell($task); } else { return $this->runRemoteCommand($task, $delay); } }
/** * 获取文件的MD5 * * @param $file * @return bool */ public function getFileMd5($file) { $cmd[] = "test -f /usr/bin/md5sum && md5sum {$file}"; $command = join(' && ', $cmd); if (Project::getAnsibleStatus()) { // ansible 并发执行远程命令 return $this->runRemoteCommandByAnsibleShell($command); } else { return $this->runRemoteCommand($command); } }
/** * 传输文件/目录到指定目标机器 * * @return bool * @throws \Exception */ private function _transmission() { $sTime = Command::getMs(); if (Project::getAnsibleStatus()) { // ansible copy $this->walleFolder->ansibleCopyFiles($this->conf, $this->task); } else { // 循环 scp $this->walleFolder->scpCopyFiles($this->conf, $this->task); } // 记录执行时间 $duration = Command::getMs() - $sTime; Record::saveRecord($this->walleFolder, $this->task->id, Record::ACTION_SYNC, $duration); return true; }