Azure云服务在部署后运行PowerShell脚本

时间:2017-11-17 07:13:53

标签: powershell azure asp.net-web-api iis-7 azure-cloud-services

我有一个Azure云服务,并希望网站appPool在预定时间而不是定期时间内回收。 所以我创建了一个PowerShell脚本来执行更改并通过命令使用任务执行PS脚本。 但它不起作用,因为Azure部署任务在部署之前而不是之后运行。 所以,我将睡眠添加到我的任务中并将其作为后台任务启动。

function getProfileHeightStandardfromDB() {
  return new Promise((resolve, reject) => {
    db.transaction(
      tx => {
        tx.executeSql('select standard, metricweight, metricheight, imperialheight, imperialweight, bmi, metricgoalweight, imperialgoalweight from profile', [], (_, { rows }) => {
          //console.log(rows);
          console.log(rows);

          //console.log(parseFloat(rows._array[0].metricheight));
          profileheight = parseFloat(rows._array[0].metricheight);
          profilestandard = rows._array[0].standard;
          console.log('Profileheight ===>'+profileheight);
          console.log('Profilestandard ===>'+profilestandard);

          // what you resolve here is what will be the result of
          // await getProfileHeightStandardfromDB(); 
          resolve({ profileheight, profilestandard });
      });
    }, null, null);
  });      
}

以下是StartPool.cmd

<Task commandLine="..\StartUpScripts\StartPool.cmd" executionContext="elevated" taskType="background">
</Task>

以下是pool.ps1

Powershell -executionpolicy remotesigned -File ..\..\approot\StartUpScripts\pool.ps1 
EXIT /B 0

文件夹结构就像

# Set the cloud service apppool recycle time to schedule time

# ** Import WebAdministration Module **
Import-Module WebAdministration

# List all sites, applications and appPools
while(!($myWeb = Get-Website -name "*mySiteName*")){
    Write-Host "Website not installed. Waiting 10 seconds..."
    Start-Sleep 10
}
$poolName = $myWeb.applicationPool

$resetTime = "09:00"

$poolPath="IIS:\AppPools\" + $poolName      
Set-ItemProperty -Path $poolPath -Name Recycling.periodicRestart.schedule -Value @{value=$resetTime}
Set-ItemProperty -Path $poolPath -Name Recycling.periodicRestart.time -Value 00:00:00

exit 0

但它不起作用。如果我通过登录服务器来执行脚本就可以了。 请提前帮助,谢谢。

0 个答案:

没有答案