Sha256: f4d926281264ad7ef6a4014165cd9dc18403cc6de34529e05c46b610463a35f6

Contents?: true

Size: 1.54 KB

Versions: 3

Compression:

Stored size: 1.54 KB

Contents

# kill the task so we can recreate it
schtasks /delete /tn "chef-solo" /f 2>&1 | out-null

# Ensure the chef task running file doesn't exist from a previous failure
if (Test-Path "<%= options[:chef_task_running] %>") {
  del "<%= options[:chef_task_running] %>"
}

# schedule the task to run once in the far distant future
schtasks /create /tn "chef-solo" /xml "<%= options[:chef_task_xml] %>" /ru "<%= options[:user] %>" /rp "<%= options[:pass] %>" | Out-Null

# start the scheduled task right now
schtasks /run /tn "chef-solo" | Out-Null

# wait for run_chef.ps1 to start or timeout after 1 minute
$timeoutSeconds = 60
$elapsedSeconds = 0
while ( (!(Test-Path "<%= options[:chef_task_running] %>")) -and ($elapsedSeconds -lt $timeoutSeconds) ) {
  Start-Sleep -s 1
  $elapsedSeconds++
}

if ($elapsedSeconds -ge $timeoutSeconds) {
  Write-Error "Timed out waiting for chef scheduled task to start"
  exit -2
}

# read the entire file, but only write out new lines we haven't seen before
$numLinesRead = 0
$success = $TRUE
while (Test-Path "<%= options[:chef_task_running] %>") {
  Start-Sleep -m 100
  
  if (Test-Path "<%= options[:chef_stdout_log] %>") {
    $text = (get-content "<%= options[:chef_stdout_log] %>")
    $numLines = ($text | Measure-Object -line).lines    
    $numLinesToRead = $numLines - $numLinesRead
    
    if ($numLinesToRead -gt 0) {
      $text | select -first $numLinesToRead -skip $numLinesRead | ForEach {
        Write-Host "$_"
      }
      $numLinesRead += $numLinesToRead
    }
  }
}

exit Get-Content "<%= options[:chef_task_exitcode] %>"

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vagrant-windows-1.3.2 lib/vagrant-windows/scripts/cheftask.ps1.erb
vagrant-windows-1.3.1 lib/vagrant-windows/scripts/cheftask.ps1.erb
vagrant-windows-1.3.0 lib/vagrant-windows/scripts/cheftask.ps1.erb