getHosts() public static method

获取当前进程配置的目标机器host列表
public static getHosts ( )
Example #1
0
 /**
  * 将多个文件/目录通过tar + scp传输到指定的多个目标机
  *
  * @param Project $project
  * @param TaskModel $task
  * @return bool
  * @throws \Exception
  */
 public function scpCopyFiles(Project $project, TaskModel $task)
 {
     // 1. 宿主机 tar 打包
     $this->_packageFiles($project, $task);
     // 2. 传输 tar.gz 文件
     foreach (Project::getHosts() as $remoteHost) {
         // 循环 scp 传输
         $this->_copyPackageToServer($remoteHost, $project, $task);
     }
     // 3. 目标机 tar 解压
     $this->_unpackageFiles($project, $task);
     return true;
 }
Example #2
0
 /**
  * 同步文件到服务器
  *
  * @return bool
  * @throws \Exception
  */
 private function _rsync()
 {
     // 同步文件
     foreach (Project::getHosts() as $remoteHost) {
         $sTime = Command::getMs();
         $ret = $this->walleFolder->syncFiles($remoteHost, $this->task->link_id);
         // 记录执行时间
         $duration = Command::getMs() - $sTime;
         Record::saveRecord($this->walleFolder, $this->task->id, Record::ACTION_SYNC, $duration);
         if (!$ret) {
             throw new \Exception('同步文件到服务器出错');
         }
     }
     return true;
 }