如何使用 PowerShell 或 CLI 启动本地 Azure Service Fabric 集群

How to start local Azure Service Fabric Cluster with PowerShell or CLI

我在 Azure Service Fabric 中进行开发,有几次 Service Fabric 因某种原因(通常在重启后)未启动。系统托盘中的 Service Fabric Manager 响应时间很糟糕(如果它有响应的话)。

是否有可用于启动本地 Service Fabric 的 PowerShell cmdlet 甚至 cli 命令?

您可以只使用 Start-Service cmdlet

PS C:\windows\system32> Start-Service FabricHostSvc
WARNING: Waiting for service 'Microsoft Service Fabric Host Service (FabricHostSvc)' to start...

您还可以通过运行 Get-Service

检查主机是否为运行
PS C:\windows\system32> Get-Service FabrichostSvc

Status   Name               DisplayName
------   ----               -----------
Running  FabrichostSvc      Microsoft Service Fabric Host Service

如果是运行你也可以用Restart-Service

PS C:\windows\system32> Restart-Service FabrichostSvc
WARNING: Waiting for service 'Microsoft Service Fabric Host Service (FabrichostSvc)' to start...
WARNING: Waiting for service 'Microsoft Service Fabric Host Service     (FabrichostSvc)' to start...

我遇到了类似的问题,最终使用了我在此处找到的 SDK 随附的实用函数:

C:\Program Files\Microsoft SDKs\Service Fabric\Tools\Scripts\ClusterSetupUtilities.psm1

在我的 powershell 脚本中,我使用以下命令导入实用程序函数:

# Import the cluster setup utility module
$sdkInstallPath = (Get-ItemProperty 'HKLM:\Software\Microsoft\Service Fabric SDK').FabricSDKScriptsPath
$modulePath = Join-Path -Path $sdkInstallPath -ChildPath "ClusterSetupUtilities.psm1"
Import-Module $modulePath

然后我有以下检查集群是否 运行ning 如果不是则启动它:

# Start the local cluster if needed
if (-not (IsLocalClusterRunning))
{
    StartLocalCluster
}

在幕后,它基本上做了与凯文在他的回答中所做的相同的事情 (Start-Service FabricHostSvc)。因此,如果您要设置 PowerShell 脚本,这可能会有所帮助,但如果您只想 运行 PowerShell 中的命令,导入实用程序可能会很麻烦。