簡體   English   中英

Azure自定義腳本擴展任務未在后台運行

[英]Azure Custom Script extension tasks not running in background

我正在使用Azure自定義腳本擴展自動執行Azure VM的部署。 在一種情況下,我正在安裝XAMPP並配置各種服務,但是在安裝所有組件之后,apache進程不再運行。 如果我登錄到計算機並手動啟動該過程,它將運行正常。

這是我用來啟動安裝和配置XAMPP的Powershell腳本的腳本

$password =  ConvertTo-SecureString "password" -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential("$env:COMPUTERNAME\username", $password)
$command = $file = $PSScriptRoot + "\WebServerSetup.ps1"
Enable-PSRemoting –force
Invoke-Command -FilePath $command -Credential $credential -ComputerName $env:COMPUTERNAME
Disable-PSRemoting -Force

設置Web服務器的腳本很長,但是這里是我啟動Apache服務的地方

Start-Process c:\xampp\apache_stop.bat  

Start-Sleep -Seconds 15

Start-Job c:\xampp\apache_start.bat 

運行自動化腳本后,所有配置均已完成,但該過程未運行...如果我手動運行該命令,它將運行正常。 我以為問題是因為bat文件想要在其自己的窗口中運行,所以我嘗試了“ xampp_start.exe”,該文件沒有打開新窗口,結果是相同的。

問題似乎在於, Invoke-CommandInvoke-Command自動關閉從其會話啟動的所有進程。

因此,簡單的解決方案應該是:

不要使用Invoke-Command啟動Powershell腳本。

如果您必須提供憑據,請嘗試以下操作:

Start-Process powershell -ArgumentList "$command" -Credential $credential

否則,只需運行腳本:

$command

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM