当前位置: 首页>>代码示例>>PHP>>正文


PHP Host::scp方法代码示例

本文整理汇总了PHP中Host::scp方法的典型用法代码示例。如果您正苦于以下问题:PHP Host::scp方法的具体用法?PHP Host::scp怎么用?PHP Host::scp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Host的用法示例。


在下文中一共展示了Host::scp方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: deploy

 function deploy($target)
 {
     if (empty($this->targets[$target])) {
         $this->log->error("{$target} target does not exist");
     }
     $targ = $this->targets[$target];
     $dir = $this->rev;
     $pwd = NULL;
     if ($this->prompt) {
         echo "Key Password: ";
         $savetty = shell_exec('stty -g');
         shell_exec('stty -echo');
         $pwd = rtrim(fgets(STDIN), "\n");
         shell_exec('stty ' . $savetty);
         echo "\n";
     }
     $this->log->progress = 5;
     $this->log->verbose("Getting {$targ['scm']} info for {$targ['repository']}");
     $this->log->output("Deploying the following to {$target}");
     $cwd = getcwd();
     chdir($this->tmpdir);
     `{$targ['scm']} info --username {$targ['scm.user']} --password {$targ['scm.passwd']} --no-auth-cache --non-interactive --trust-server-cert {$targ['repository']} > {$dir}.info`;
     $this->log->progress = 10;
     if (php_sapi_name() == 'cli') {
         $this->log->output(trim(file_get_contents("{$dir}.info")));
     } else {
         $this->log->output(nl2br(trim(file_get_contents("{$dir}.info"))));
     }
     if (!is_dir($this->rev)) {
         $this->log->output("Exporting {$targ['repository']} to {$dir}");
         `{$targ['scm']} export -q --username {$targ['scm.user']} --password {$targ['scm.passwd']} --no-auth-cache --non-interactive --trust-server-cert {$targ['repository']} {$dir}`;
         $this->log->rollback_set("rm -rf {$dir}.info {$dir}");
     }
     $this->log->progress += (int) (100 / (count($targ['hosts']) + 1));
     // Clean up targets we don't need before pushing the code
     if (is_dir("{$dir}/deploy/targets")) {
         foreach (glob("{$dir}/deploy/targets/*") as $t) {
             if (basename($t) != $target) {
                 `rm -rf {$t}`;
             }
         }
     }
     $this->log->progress += 10;
     `tar czf {$dir}.tar.gz {$dir}`;
     $this->log->verbose("tar file {$dir}.tar.gz created");
     $this->log->rollback_add("rm {$dir}.tar.gz");
     $md5 = md5_file("{$dir}.tar.gz");
     $this->log->progress += 5;
     $this->log->verbose("md5 checksum is {$md5}");
     // Now push the tarball to each host
     $each_progress = (int) ((100 - $this->log->progress) / (count($targ['hosts']) + 1));
     foreach ($targ['hosts'] as $ip) {
         $host = new Host($ip, $targ, $this->log, $pwd);
         $targ['ssh'][$ip] = $host;
         $host->exec("mkdir -p {$targ['deploy_to']}/releases");
         // Alternatively you can use $host->sftp() here
         $host->scp("{$dir}.tar.gz", "{$targ['deploy_to']}/releases/{$dir}.tar.gz");
         $this->log->progress += $each_progress;
         $this->log->rollback_add("rm -f {$targ['deploy_to']}/releases/{$dir}.tar.gz", $ip);
         // Make sure the file got there uncorrupted
         $result = $host->exec("md5sum -b {$targ['deploy_to']}/releases/{$dir}.tar.gz");
         list($remote_md5, $junk) = explode(' ', $result, 2);
         if ($md5 != $remote_md5) {
             $this->log->error("Local checksum {$md5} does not match remote checksum {$remote_md5}");
         }
         $this->log->verbose("File uploaded and checksum matched");
     }
     // Multiple loops to do these almost in parallel
     $each_progress = (int) ((100 - $this->log->progress) / (count($targ['hosts']) + 1));
     foreach ($targ['ssh'] as $ip => $host) {
         $this->log->progress += $each_progress;
         $host->exec("cd {$targ['deploy_to']}/releases && tar zxf {$dir}.tar.gz && rm {$dir}.tar.gz && cd {$dir} && REVISION={$dir} make {$target}");
         if (strlen(trim($dir))) {
             $this->log->rollback_add("rm -rf {$targ['deploy_to']}/releases/{$dir}", $ip);
         }
     }
     // Sanity check
     $each_progress = (int) ((100 - $this->log->progress) / (count($targ['hosts']) + 1));
     foreach ($targ['ssh'] as $ip => $host) {
         $this->log->progress += $each_progress;
         $current_version[$ip] = $host->exec("curl -s -S -H 'Host: {$targ['application']}' 'localhost/setrev.php'");
         if ($current_version[$ip]) {
             $this->log->rollback_add("curl -s -S -H 'Host: {$targ['application']}' 'localhost/setrev.php?user={$this->user}&rel=rollback&rev={$current_version[$ip]}'", $ip);
         }
     }
     // Move the symlink into place and hit the local setrev script
     $each_progress = (int) ((100 - $this->log->progress) / (count($targ['hosts']) + 1));
     foreach ($targ['ssh'] as $ip => $host) {
         $this->log->progress += $each_progress;
         $this->log->output("Moving symlink from {$current_version[$ip]} to {$dir} on {$host->name}");
         $host->exec("ln -s {$targ['deploy_to']}/releases/{$dir} {$targ['deploy_to']}/new_current && mv -Tf {$targ['deploy_to']}/new_current {$targ['deploy_to']}/current");
         if ($current_version[$ip]) {
             $this->log->rollback_add("ln -s {$targ['deploy_to']}/releases/{$current_version[$ip]} {$targ['deploy_to']}/new_current && mv -Tf {$targ['deploy_to']}/new_current {$targ['deploy_to']}/current");
         }
         $this->log->output("Symlink moved, version {$dir} is now active");
         $host->exec("curl -s -S -H 'Host: {$targ['application']}' 'localhost/setrev.php?user={$this->user}&rel={$targ['repository']}&rev={$dir}'");
         $this->log->rollback_add("curl -s -S -H 'Host: {$targ['application']}' 'localhost/setrev.php?user={$this->user}&rel={$targ['repository']}&rev={$current_version[$ip]}'", $ip);
     }
     // Deploy was good - non-critical cleanup after this point
     $this->log->rollback_set('');
//.........这里部分代码省略.........
开发者ID:rlerdorf,项目名称:WePloy,代码行数:101,代码来源:ploy.php


注:本文中的Host::scp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。