Skip to content

Commit

Permalink
Fix for scheduled task cancellation (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobb42 authored and knithinc committed Jun 15, 2018
1 parent f5a1ae8 commit 930484f
Show file tree
Hide file tree
Showing 4 changed files with 566 additions and 483 deletions.
31 changes: 21 additions & 10 deletions bootstorm-vm-boot-time/VMBootAll.ps1
Expand Up @@ -38,11 +38,11 @@ Configuration ConfigureVMBootAll
# Log file
$logFileName = "VMBootDSC.log"
$logFilePath = "$localPath\$logFileName"

$AzureAccountUsername = $AzureAccountCreds.UserName
$AzureAccountPasswordBSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($AzureAccountCreds.Password)
$AzureAccountPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($AzureAccountPasswordBSTR)

$VMAdminUserName = $VMAdminCreds.UserName
$VMAdminPasswordBSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($VMAdminCreds.Password)
$VMAdminPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($VMAdminPasswordBSTR)
Expand Down Expand Up @@ -95,26 +95,37 @@ Configuration ConfigureVMBootAll
$storageEndpoint = $storageEndpoint.Substring(0, $storageEndpoint.LastIndexOf(":"))
}
}

"Storage endpoint given: $using:AzureStorageEndpoint Storage endpoint passed to script: $storageEndpoint" | Tee-Object -FilePath $logFilePath -Append


# Disable windows update
sc.exe config wuauserv start=disabled
sc.exe stop wuauserv

# Enable task scheduler event logs
$taskSchedulerlogName = 'Microsoft-Windows-TaskScheduler/Operational'
$taskLog = New-Object System.Diagnostics.Eventing.Reader.EventLogConfiguration $taskSchedulerlogName
$taskLog.IsEnabled=$true
$taskLog.SaveChanges()

$psPath = $using:PSPath
$psScriptDir = Split-Path -Parent -Path $psPath
$psScriptName = "VMBootAllScript.ps1"
$psScriptPath = "$psScriptDir\$psScriptName"
$action = New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument "& $psScriptPath -azureUserName $azureUsername -azurePassword $azurePassword -tenant $tenant -location $location -vmName $vmName -vmCount $vmCount -azureStorageAccount $storageAccount -azureStorageAccessKey $storageKey -azureStorageEndpoint $storageEndpoint -AzureSubscription $subscription -Verbose" -ErrorAction Ignore
$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).AddMinutes(5) -RepetitionInterval (New-TimeSpan -Minutes 10) -RepetitionDuration (New-TimeSpan -Minutes 30) -ErrorAction Ignore
$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).AddMinutes(5) -ErrorAction Ignore
$settings = New-ScheduledTaskSettingsSet -StartWhenAvailable -RunOnlyIfNetworkAvailable -DontStopOnIdleEnd -RestartCount 3 -RestartInterval (New-TimeSpan -Minutes 2) -ErrorAction Ignore
Unregister-ScheduledTask -TaskName "VMBootAll" -Confirm:0 -ErrorAction Ignore
Register-ScheduledTask -Action $action -Trigger $trigger -Settings $settings -TaskName "VMBootAll" -Description "VMBootstorm" -User $vmAdminUserName -Password $vmAdminPassword -RunLevel Highest -ErrorAction Ignore


######################
### AZURE RM SETUP ###
######################
$logFilePath = $using:logFilePath
$azureStackSdkPath = $using:azureStackSdkPath
$azureStackInstallerPath = $using:azureStackInstallerPath

if((IsAzureStack -Location $location) -eq $true) {
# Ignore server certificate errors to avoid https://api.azurestack.local/ certificate error
add-type @"
Expand Down Expand Up @@ -183,26 +194,26 @@ Configuration ConfigureVMBootAll
}
}
}
Disable-AzureRmDataCollection
Disable-AzureRmDataCollection

# Test status file
$statusFilePath = "$localPath\VMBootStatus.log"

# Wait for VM bootstorm test to finish if vm count is small and DSC can finish within 90 minutes
$waitCount = 75
while(((Test-Path $statusFilePath) -eq $false) -and ($waitCount -gt 0)) {
"Waiting for bootstorm test to finish $waitCount" | Tee-Object -FilePath $logFilePath -Append
Start-Sleep -Seconds 60
$waitCount--
}

if((Test-Path $statusFilePath) -eq $false) {
"Bootstorm test finished successfully." | Tee-Object -FilePath $logFilePath -Append
}
else {
"Bootstorm test not finished successfully." | Tee-Object -FilePath $logFilePath -Append
}
}
}
}
}

Binary file modified bootstorm-vm-boot-time/VMBootAll.zip
Binary file not shown.

0 comments on commit 930484f

Please sign in to comment.