Created
March 14, 2017 20:27
-
-
Save camous/00dae80c86d49ae223f1b7dcd227cb4e to your computer and use it in GitHub Desktop.
Lists & kills webjob with based on command name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[string] $AppServiceName = $ENV:AZURE_APPNAME, | |
[string] $CommandLine = $ENV:AZURE_WEBJOBCOMMANDLINE, | |
[string] $Headers = $ENV:AZURE_SCM_HEADERS | |
) | |
Try | |
{ | |
Write-Warning "Killing processes $CommandLine in $AppServiceName" | |
$HeadersHash = ConvertFrom-StringData -StringData $Headers | |
$HeadersHash | |
$processes = Invoke-RestMethod -Uri "https://$AppServiceName.scm.azurewebsites.net/api/processes" -Header $HeadersHash | |
$targets = $processes | | |
% { Invoke-RestMethod -Uri "https://$AppServiceName.scm.azurewebsites.net/api/processes/$($_.id)" -Header $HeadersHash } | | |
? { $_.command_line -eq $CommandLine } | |
foreach($target in $targets){ | |
Write-Warning "Killing PID $($target.id) : $($target.command_line)" | |
Invoke-RestMethod -Uri "https://$AppServiceName.scm.azurewebsites.net/api/processes/$($target.id)" -Header $HeadersHash -Method Delete | |
} | |
}Catch | |
{ | |
Write-Error $_.Exception.Message | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment