コード例 #1
0
ファイル: WalleController.php プロジェクト: lina1/walle-web
 /**
  * upgrade walle 更新walle版本
  *
  * @throws yii\console\Exception
  */
 public function actionUpgrade()
 {
     $commander = new Command(['console']);
     // stash save local change 暂存本地修改
     echo 'stash save local change 暂存本地修改: git stash save ...', PHP_EOL;
     $commander->runLocalCommand('/usr/bin/env git stash save');
     // pull code 更新代码
     echo 'pull code 更新代码: git pull ...', PHP_EOL;
     $commander->runLocalCommand('/usr/bin/env git pull');
     // stash pop local change 弹出暂存本地修改
     echo 'stash pop local change 弹出暂存本地修改: git stash pop ...', PHP_EOL;
     $commander->runLocalCommand('/usr/bin/env git stash pop');
     // init walle 初始化项目
     $this->runAction('setup', ['interactive' => $this->interactive]);
     // checkout the current version查看最新版本
     echo "\n--------------------------------------------------------", PHP_EOL;
     echo "Congratulations To Upgrade. Your Walle Current Version:", PHP_EOL;
     $this->runAction('index', ['interactive' => $this->interactive]);
 }
コード例 #2
0
 /**
  * 执行远程服务器任务集合
  * 对于目标机器更多的时候是一台机器完成一组命令,而不是每条命令逐台机器执行
  *
  * @param $version
  * @throws \Exception
  */
 private function _updateRemoteServers($version)
 {
     $cmd = [];
     // pre-release task
     if ($preRelease = WalleTask::getRemoteTaskCommand($this->conf->pre_release, $version)) {
         $cmd[] = $preRelease;
     }
     // link
     if ($linkCmd = $this->walleFolder->getLinkCommand($version)) {
         $cmd[] = $linkCmd;
     }
     // post-release task
     if ($postRelease = WalleTask::getRemoteTaskCommand($this->conf->post_release, $version)) {
         $cmd[] = $postRelease;
     }
     $sTime = Command::getMs();
     // run the task package
     $ret = $this->walleTask->runRemoteTaskCommandPackage($cmd);
     // 记录执行时间
     $duration = Command::getMs() - $sTime;
     Record::saveRecord($this->walleTask, $this->task->id, Record::ACTION_UPDATE_REMOTE, $duration);
     if (!$ret) {
         throw new \Exception('全量更新服务器出错');
     }
     return true;
 }
コード例 #3
0
ファイル: Record.php プロジェクト: 9618211/walle-web
 /**
  * 保存记录
  *
  * @param Command $commandObj
  * @param $task_id
  * @param $action
  * @param $duration
  * @return mixed
  */
 public static function saveRecord(Command $commandObj, $task_id, $action, $duration)
 {
     $record = new static();
     $record->attributes = ['user_id' => \Yii::$app->user->id, 'task_id' => $task_id, 'status' => (int) $commandObj->getExeStatus(), 'action' => $action, 'created_at' => time(), 'command' => var_export($commandObj->getExeCommand(), true), 'memo' => var_export($commandObj->getExeLog(), true), 'duration' => $duration];
     return $record->save();
 }
コード例 #4
0
 /**
  * 软链接
  */
 private function _link($version = null)
 {
     // 创建链接指向
     $folder = new Folder();
     $sTime = Command::getMs();
     $ret = $folder->setConfig($this->conf)->link($version);
     // 记录执行时间
     $duration = Command::getMs() - $sTime;
     Record::saveRecord($folder, $this->task->id, Record::ACTION_LINK, $duration);
     if (!$ret) {
         throw new \Exception('创建链接出错');
     }
     return true;
 }