Skip to content

Instantly share code, notes, and snippets.

@camous
Created March 14, 2017 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save camous/00dae80c86d49ae223f1b7dcd227cb4e to your computer and use it in GitHub Desktop.
Save camous/00dae80c86d49ae223f1b7dcd227cb4e to your computer and use it in GitHub Desktop.
Lists & kills webjob with based on command name
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