Improving rsync related routines
This commit is contained in:
parent
b52ca641b6
commit
bd3fbc8c02
|
@ -272,6 +272,7 @@ function deploy_put_file($name, $path, $contents, $opts = 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: use deploy_scp_put_file_async(..) internally?
|
||||||
function deploy_scp_put_file($name, $local_path, $remote_path, $opts = 0)
|
function deploy_scp_put_file($name, $local_path, $remote_path, $opts = 0)
|
||||||
{
|
{
|
||||||
$decl = deploy_get_node($name);
|
$decl = deploy_get_node($name);
|
||||||
|
@ -359,12 +360,13 @@ function deploy_scp_put_file_async($name, $local_path, $remote_path, $opts = 0)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function deploy_rsync_async($name, $src_dir, $dst_dir, $rsync_opts = '', $opts = 0)
|
//TODO: use deploy_rsync_async(..) internally?
|
||||||
|
function deploy_rsync($name, $src, $dst, $rsync_opts = '', $opts = 0)
|
||||||
{
|
{
|
||||||
return Amp\call(function() use($name, $src_dir, $dst_dir, $rsync_opts, $opts) {
|
|
||||||
|
|
||||||
$decl = deploy_get_node($name);
|
$decl = deploy_get_node($name);
|
||||||
|
|
||||||
|
$dst = deploy_str($decl, $dst);
|
||||||
|
|
||||||
$tmp_key_file = tempnam("/tmp", "ssh_");
|
$tmp_key_file = tempnam("/tmp", "ssh_");
|
||||||
$key_str = $decl->get('ssh_key_str');
|
$key_str = $decl->get('ssh_key_str');
|
||||||
|
|
||||||
|
@ -372,13 +374,65 @@ function deploy_rsync_async($name, $src_dir, $dst_dir, $rsync_opts = '', $opts =
|
||||||
{
|
{
|
||||||
file_put_contents($tmp_key_file, $key_str);
|
file_put_contents($tmp_key_file, $key_str);
|
||||||
|
|
||||||
$ssh_transport = "ssh -A -o StrictHostKeyChecking=no -o ConnectTimeout=90 -o ConnectionAttempts=30 -i $tmp_key_file";
|
foreach($decl->get('hosts') as $host)
|
||||||
|
{
|
||||||
|
list($ssh_host, $ssh_port) = deploy_ssh_host_port($host);
|
||||||
|
|
||||||
|
$ssh_transport = "-e 'ssh -A -o StrictHostKeyChecking=no -o ConnectTimeout=90 -o ConnectionAttempts=30 -i $tmp_key_file -p $ssh_port'";
|
||||||
|
$ssh_host_prefix = $decl->get('user') . '@' . $ssh_host . ':';
|
||||||
|
|
||||||
|
if($ssh_host === 'localhost')
|
||||||
|
{
|
||||||
|
$ssh_transport = '';
|
||||||
|
$ssh_host_prefix = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$cmd = "rsync $ssh_transport -a $rsync_opts $src {$ssh_host_prefix}$dst";
|
||||||
|
|
||||||
|
if(($opts & DEPLOY_OPT_SILENT) == 0)
|
||||||
|
echo "[RSN] $host: $cmd\n";
|
||||||
|
|
||||||
|
system($cmd, $ret);
|
||||||
|
|
||||||
|
if($ret !== 0)
|
||||||
|
throw new Exception("Could not rsync $src to remote $dst: $ret");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
unlink($tmp_key_file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function deploy_rsync_async($name, $src, $dst, $rsync_opts = '', $opts = 0)
|
||||||
|
{
|
||||||
|
return Amp\call(function() use($name, $src, $dst, $rsync_opts, $opts) {
|
||||||
|
|
||||||
|
$decl = deploy_get_node($name);
|
||||||
|
|
||||||
|
$dst = deploy_str($decl, $dst);
|
||||||
|
|
||||||
|
$tmp_key_file = tempnam("/tmp", "ssh_");
|
||||||
|
$key_str = $decl->get('ssh_key_str');
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
file_put_contents($tmp_key_file, $key_str);
|
||||||
|
|
||||||
foreach($decl->get('hosts') as $host)
|
foreach($decl->get('hosts') as $host)
|
||||||
{
|
{
|
||||||
list($ssh_host, $ssh_port) = deploy_ssh_host_port($host);
|
list($ssh_host, $ssh_port) = deploy_ssh_host_port($host);
|
||||||
|
|
||||||
$proc_cmd = "rsync -e '" . $ssh_transport . " -p $ssh_port' -a $rsync_opts $src_dir/ " . $decl->get('user') . '@' . $ssh_host . ":$dst_dir/";
|
$ssh_transport = "-e 'ssh -A -o StrictHostKeyChecking=no -o ConnectTimeout=90 -o ConnectionAttempts=30 -i $tmp_key_file -p $ssh_port'";
|
||||||
|
$ssh_host_prefix = $decl->get('user') . '@' . $ssh_host . ':';
|
||||||
|
|
||||||
|
if($ssh_host === 'localhost')
|
||||||
|
{
|
||||||
|
$ssh_transport = '';
|
||||||
|
$ssh_host_prefix = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$proc_cmd = "rsync $ssh_transport -a $rsync_opts $src {$ssh_host_prefix}$dst";
|
||||||
|
|
||||||
if(($opts & DEPLOY_OPT_SILENT) == 0)
|
if(($opts & DEPLOY_OPT_SILENT) == 0)
|
||||||
echo "[RSN] $host: $proc_cmd\n";
|
echo "[RSN] $host: $proc_cmd\n";
|
||||||
|
@ -394,7 +448,7 @@ function deploy_rsync_async($name, $src_dir, $dst_dir, $rsync_opts = '', $opts =
|
||||||
$status = yield $proc->join();
|
$status = yield $proc->join();
|
||||||
|
|
||||||
if($status !== 0)
|
if($status !== 0)
|
||||||
throw new Exception("Could not rsync $src_dir to remote $dst_dir: $status");
|
throw new Exception("Could not rsync $src to remote $dst: $status");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
|
Loading…
Reference in New Issue