RagtimeWilly
RagtimeWilly

Reputation: 5445

Force delete of Service Fabric application

I am having issues during development where an exception during service start up causes the application to get stuck in an error state. This prevents further debugging. I can't seem to delete the application through the cluster management portal either, it just times out.

The only way I've found to fix is to reset the cluster, which takes a few minutes and deletes all other applications from the cluster as well.

What's the correct way to force delete of an individual application?

Upvotes: 3

Views: 2682

Answers (2)

RagtimeWilly
RagtimeWilly

Reputation: 5445

I created the following powershell script which seems to do the trick:

param([string]$applicationName = "SomeAppName", [string]$version = "1.0.0")

$applicationUri = "fabric:/" + $applicationName
$applicationTypeName = $applicationName + "Type"

Connect-ServiceFabricCluster localhost:19000

Write-Host ""
Write-Host "Removing $applicationUri from local cluster"

Remove-ServiceFabricApplication -ApplicationName fabric:/$applicationName

Write-Host ""
Write-Host "Removing $applicationTypeName (v$version) from local cluster"

Unregister-ServiceFabricApplicationType -ApplicationTypeName $applicationTypeName -ApplicationTypeVersion $version

Write-Host ""
Write-Host "Complete"

Can be called like so:

.\Delete-SF-App.ps1 -applicationName "MyService" -version "1.0.0"

EDIT:

If the above doesn't work then the below powershell command can be used to remove individual replicas:

$nodes = Get-ServiceFabricNode

foreach($node in $nodes)
{
    $replicas = Get-ServiceFabricDeployedReplica -NodeName $node.NodeName -ApplicationName $applicationName
    foreach ($replica in $replicas)
    {
        Remove-ServiceFabricReplica -ForceRemove -NodeName $node.NodeName -PartitionId $replica.Partitionid -ReplicaOrInstanceId $replica.ReplicaOrInstanceId
    }
}

Upvotes: 3

Oleg Karasik
Oleg Karasik

Reputation: 969

Please ignore this answer if you aren't using Visual Studio for development and debugging.

I know the question is already answered but have you tried to change Application Debug Mode setting in Visual Studio to Remove Application?

Upvotes: 0

Related Questions