2014-07-04 18 views
0

當我將web角色添加到我的node.js項目時,會生成一個download.ps1。這用於什麼?我無法在任何地方找到任何文檔。Azure download.ps1

我可以看到腳本做了什麼,我只是不知道它何時被調用或爲什麼。該文件的內容如下:如果你希望你的應用

download.ps1用於node.exe下載,所以這是非常重要的:

$runtimeUrl = $args[0] 
$overrideUrl = $args[1] 
$current = [string] (Get-Location -PSProvider FileSystem) 
$client = New-Object System.Net.WebClient 

function downloadWithRetry { 
    param([string]$url, [string]$dest, [int]$retry) 
    Write-Host 
    Write-Host "Attempt: $retry" 
    Write-Host 
    trap { 
     Write-Host $_.Exception.ToString() 
     if ($retry -lt 5) { 
      $retry=$retry+1 
      Write-Host 
      Write-Host "Waiting 5 seconds and retrying" 
      Write-Host 
      Start-Sleep -s 5 
      downloadWithRetry $url $dest $retry $client 
     } 
     else { 
      Write-Host "Download failed" 
      throw "Max number of retries downloading [5] exceeded" 
     } 
    } 
    $client.downloadfile($url, $dest) 
} 

function download($url, $dest) { 
    Write-Host "Downloading $url" 
    downloadWithRetry $url $dest 1 
} 

function copyOnVerify($file, $output) { 
    Write-Host "Verifying $file" 
    $verify = Get-AuthenticodeSignature $file 
    Out-Host -InputObject $verify 
    if ($verify.Status -ne "Valid") { 
    throw "Invalid signature for runtime package $file" 
    } 
    else { 
    mv $file $output 
    } 
} 

if ($overrideUrl) { 
    Write-Host "Using override url: $overrideUrl" 
    $url = $overrideUrl 
} 
else { 
    $url = $runtimeUrl 
} 

foreach($singleUrl in $url -split ";") 
{ 
    $suffix = Get-Random 
    $downloaddir = $current + "\sandbox" + $suffix 
    mkdir $downloaddir 
    $dest = $downloaddir + "\sandbox.exe" 
    download $singleUrl $dest 
    $final = $downloaddir + "\runtime.exe" 
    copyOnVerify $dest $final 
    if (Test-Path -LiteralPath $final) 
    { 
     cd $downloaddir 
     if ($host.Version.Major -eq 3) 
     { 
     .\runtime.exe -y | Out-Null 
     .\setup.cmd 
     } 
     else 
     { 
     Start-Process -FilePath $final -ArgumentList -y -Wait 
     $cmd = $downloaddir + "\setup.cmd" 
     Start-Process -FilePath $cmd -Wait 
     } 
    } 
    else 
    { 
     throw "Unable to verify package" 
    } 
    cd $current 
    if (Test-Path -LiteralPath $downloaddir) 
    { 
     Remove-Item -LiteralPath $downloaddir -Force -Recurse 
    } 
} 

回答

0

好吧,我想通了這一點跑。該腳本從Setup_Worker.cmd(如果您正在部署工作者角色)或Setup_Web.cmd(如果您正在部署Web角色)中調用。它需要以下參數:'%RUNTIMEURL%''%RUNTIMEURLOVERRIDE%'。在您的ServiceDefinition.csdef中定義並初始化了%RUNTIMEURL%。我找不到'%RUNTIMEURLOVERRIDE%'在哪裏定義,並且實際上運行沒有此參數的腳本可以正常工作。

我寫了一篇關於此的博文:https://shilessam.wordpress.com/2014/07/08/azure-node-js-download-ps1-a-what-what/