Powershell Azure自定义脚本扩展任务未在后台运行
我正在使用Azure自定义脚本扩展来自动部署Azure VM。在一个例子中,我正在安装XAMPP并配置各种服务,但是在安装完所有内容之后,apache进程将不再运行。如果我登录到机器并手动启动该进程,它就会正常运行 下面是我用来启动安装和配置XAMPP的powershell脚本的脚本Powershell Azure自定义脚本扩展任务未在后台运行,powershell,azure,Powershell,Azure,我正在使用Azure自定义脚本扩展来自动部署Azure VM。在一个例子中,我正在安装XAMPP并配置各种服务,但是在安装完所有内容之后,apache进程将不再运行。如果我登录到机器并手动启动该进程,它就会正常运行 下面是我用来启动安装和配置XAMPP的powershell脚本的脚本 $password = ConvertTo-SecureString "password" -AsPlainText -Force $credential = New-Object System.Manageme
$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命令
在命令执行后自动关闭从其会话启动的所有进程
因此,简单的解决方案应该是:
不要使用Invoke命令启动powershell脚本
如果必须提供凭据,请尝试以下操作:
Start-Process powershell -ArgumentList "$command" -Credential $credential
否则,只需运行脚本:
$command
您使用start job而不是start process有什么具体原因吗?我读到它会在后台运行该进程,所以我尝试了一下。我还尝试了使用各种参数启动进程,如-Wait和-NoWindow,但都不起作用。。。好吧,让我换一种说法。。所有人都开始了这个过程,但是一旦脚本完成,Apache程序就停止了。您是否检查了Apache日志文件中的错误?还可以尝试使用提供的凭据启动它