question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] RunPowerShellScript execution hangs while deprovisioning Linux VM with waagent

See original GitHub issue

RunPowerShellScript hangs while executing ‘sudo waagent -deprovision+user -force’

I want to be able to deprovision a VM from Azure Runbook. I’m using PowerShell as follows:

$restUri = 'https://management.azure.com/subscriptions/'+ $azContext.Subscription.Id+'/resourceGroups/'+$resourceGroupName+ `
    '/providers/Microsoft.Compute/virtualMachines/'+$VMName+'/runCommand?api-version=2017-03-30'
$body = @{
  'commandId' = 'RunShellScript'
  'script' = @('sudo waagent -deprovision+user -force')
}
$response = Invoke-webrequest -Uri $restUri -Method Post -Headers $authHeader -Body $($body | ConvertTo-Json)

$asyncstatus = $($response.headers.'Azure-AsyncOperation')
$status = "InProgress"
While($status -eq "InProgress")`
{
  Write-Output "Status: $status"
  $response = invoke-webrequest -uri $asyncstatus -Headers $authHeader
  $status = $($response.Content | ConvertFrom-Json).status -eq "InProgress"
  sleep 5
}

Write-Output $($response.Content | ConvertFrom-Json).properties.output.message

Observed behavior: the user is deprovisioned, but the REST API call never completes so I keep getting “InProgress” every 5 seconds until the Runbook token times out. Expected behavior: the REST API call completes once the user is deprovisioned.

Note: same call (‘sudo waagent -deprovision+user -force’) completes OK when run via SSH.

  • Distro and Version: Ubuntu 18.04 LTS

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
abaymarcommented, Nov 6, 2020

@o-l-a-v you are correct - thank you for pointing out

1reaction
narrietacommented, Sep 15, 2020

@abaymar Yes, agreed. We have a work item for this in our queue, but at this point we are focused on other tasks. Once we get to it I’ll post to #1792

Read more comments on GitHub >

github_iconTop Results From Across the Web

Run scripts in a Windows VM in Azure using action Run ...
This article describes how to run PowerShell scripts within an Azure Windows virtual machine by using the Run Command feature.
Read more >
Azure Run Command for Dummies - Mandiant
On Windows, the RunPowerShellScript command executes PowerShell on the virtual machine as the SYSTEM user. On Linux, the RunShellScript command ...
Read more >
How to remotely start service on Azure VM with powershell 5.1
When i run from Azure portal via "Run Command" - it hangs. When i run from the VM itself - it says: "Service...
Read more >
Test | PDF | Virtual Machine | Microsoft Azure - Scribd
If your intent is to work with Linux VMs, look at Azure and Linux. ... If an error arises during self-service maintenance, the...
Read more >
How to Run scripts on Azure Virtual Machines with the Run ...
To do so, select the VM and Run command. From here select a pre-created operation or RunPowerShellScript / RunShellScript. 1.png. Enter the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found