| ... | @@ -372,20 +372,29 @@ def finish_operation(name, operation): | ... | @@ -372,20 +372,29 @@ def finish_operation(name, operation): |
| 372 | json.dumps({'_stop': operation['id']}).encode(), timeout=18) | 372 | json.dumps({'_stop': operation['id']}).encode(), timeout=18) |
| 373 | elif operation.get('worker'): | 373 | elif operation.get('worker'): |
| 374 | directory = 'C:\\ProgramData\\SnowglobeComputer\\' + operation['id'] | 374 | directory = 'C:\\ProgramData\\SnowglobeComputer\\' + operation['id'] |
| 375 | guest_exec(name, operation['worker'], ['--release' if operation.get('keep_spawn') else '--cleanup', directory], timeout=58) | 375 | try: |
| 376 | else: | 376 | guest_exec(name, operation['worker'], ['--release' if operation.get('keep_spawn') else '--cleanup', directory], timeout=58) |
| | 377 | except ValueError: |
| | 378 | pass |
| | 379 | else: |
| | 380 | (vms.DISKS / name / 'computer-operation.json').unlink() |
| | 381 | return |
| | 382 | if operation['platform'] == 'windows': |
| 377 | run = operation['id'] | 383 | run = operation['id'] |
| 378 | directory = 'C:\\ProgramData\\SnowglobeComputer\\' + run | 384 | directory = 'C:\\ProgramData\\SnowglobeComputer\\' + run |
| 379 | cleanup = "$ErrorActionPreference='Stop';$d='"+directory+"';" | 385 | cleanup = "$ErrorActionPreference='Stop';$d='"+directory+"';" |
| 380 | cleanup += "if(Test-Path -LiteralPath ($d+'\\request.json')){Remove-Item -LiteralPath ($d+'\\request.json') -Force};" | 386 | cleanup += "if(Test-Path -LiteralPath ($d+'\\request.json')){Remove-Item -LiteralPath ($d+'\\request.json') -Force};" |
| 381 | cleanup += "$s=New-Object -ComObject Schedule.Service;$s.Connect();$f=$s.GetFolder('\\');" | 387 | cleanup += "$s=New-Object -ComObject Schedule.Service;$s.Connect();$f=$s.GetFolder('\\');" |
| 382 | cleanup += "$t=$f.GetTasks(1) | Where-Object {$_.Name -eq 'SnowglobeComputer-"+run+"'};if($t){" | 388 | cleanup += "$t=$f.GetTasks(1) | Where-Object {$_.Name -eq 'SnowglobeComputer-"+run+"'};" |
| 383 | if not operation.get('keep_spawn'): | 389 | if not operation.get('keep_spawn'): |
| | 390 | if operation.get('worker'): |
| | 391 | cleanup += "[Reflection.Assembly]::LoadFrom('"+operation['worker']+"')|Out-Null;[ComputerProcess]::Stop($d+'\\request.json');" |
| 384 | cleanup += "$workers=@(Get-WmiObject Win32_Process | Where-Object {$_.CommandLine -like ('*'+$d+'\\request.json*')} | ForEach-Object {$p=Get-Process -Id $_.ProcessId -ErrorAction SilentlyContinue;if($p){$null=$p.Handle;$p}});" | 392 | cleanup += "$workers=@(Get-WmiObject Win32_Process | Where-Object {$_.CommandLine -like ('*'+$d+'\\request.json*')} | ForEach-Object {$p=Get-Process -Id $_.ProcessId -ErrorAction SilentlyContinue;if($p){$null=$p.Handle;$p}});" |
| 385 | cleanup += "[Reflection.Assembly]::LoadFrom($t.Definition.Actions.Item(1).Path)|Out-Null;[ComputerProcess]::Stop($d+'\\request.json');" | 393 | if not operation.get('worker'): |
| 386 | cleanup += "$t.Stop(0);while($t.State -eq 4){Start-Sleep -Milliseconds 100};" | 394 | cleanup += "if($t){[Reflection.Assembly]::LoadFrom($t.Definition.Actions.Item(1).Path)|Out-Null;[ComputerProcess]::Stop($d+'\\request.json')};" |
| | 395 | cleanup += "if($t){$t.Stop(0);while($t.State -eq 4){Start-Sleep -Milliseconds 100}};" |
| 387 | cleanup += "foreach($p in $workers){if(!$p.WaitForExit(10000)){throw 'Process cleanup failed'};$p.Dispose()};" | 396 | cleanup += "foreach($p in $workers){if(!$p.WaitForExit(10000)){throw 'Process cleanup failed'};$p.Dispose()};" |
| 388 | cleanup += "$f.DeleteTask('SnowglobeComputer-"+run+"',0)};" | 397 | cleanup += "if($t){$f.DeleteTask('SnowglobeComputer-"+run+"',0)};" |
| 389 | if not operation.get('keep_spawn'): | 398 | if not operation.get('keep_spawn'): |
| 390 | cleanup += "if(Test-Path -LiteralPath $d){Remove-Item -LiteralPath $d -Recurse -Force}" | 399 | cleanup += "if(Test-Path -LiteralPath $d){Remove-Item -LiteralPath $d -Recurse -Force}" |
| 391 | powershell(name, cleanup, timeout=58) | 400 | powershell(name, cleanup, timeout=58) |