当我添加一个web角色到我的node.js项目,一个下载。生成Ps1。这是干什么用的?我在任何地方都找不到关于它的任何文档。
我可以看到脚本的作用,我只是不知道它何时被调用或为什么被调用。文件内容如下:
$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
}
}
好了,我明白了:
下载。Ps1是用来下载node.exe的,所以如果你想让你的应用运行起来,这是非常重要的。该脚本是从Setup_Worker调用的。cmd(如果您正在部署工作角色)或Setup_Web. cmd。CMD(如果您正在部署web角色)。它接受以下参数:'%RUNTIMEURL%' '%RUNTIMEURLOVERRIDE%' '。%RUNTIMEURL%在ServiceDefinition.csdef中定义和初始化。我找不到'%RUNTIMEURLOVERRIDE%'是在哪里定义的,实际上,在没有这个参数的情况下运行脚本很好。
我已经写了一篇关于这个的博客文章:https://shilessam.wordpress.com/2014/07/08/azure-node-js-download-ps1-a-what-what/