chef-zero-scheduled-task 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93c85c79fb07b95c44580437d30c3b455caf6a46
4
- data.tar.gz: aa1fea084946933ad28210ac8e70d7c14b799864
3
+ metadata.gz: ba0ff7403a98e72130aab8075f648e671aa0071d
4
+ data.tar.gz: b1ec792ba273e5f7774bcc0c5932c5c3fae06da4
5
5
  SHA512:
6
- metadata.gz: 48b83ae84bd2b3a56b114a6e2cb238730a38e4cc48b4a175b66501f657b33f4d780151d2a04bf00245f8b6e06f4e04cbb4faac15454f41a5b2e6211eb4c4fb24
7
- data.tar.gz: 6651285c082f1ff736139efce7be4bcec26d6d10ca03748c63bac72b740a2f3a667e73aefc8915e523e2c3f3a5aada63233abab16d1de1c84d0fda2136c4eded
6
+ metadata.gz: d6ba2c795558b572f51e33b2dcde005894f300c2db4e1d26ace3aadf8615c9d2d5a83201576764423ed18854b9d7d05e3547a88081e52e654b899fe1d7e10232
7
+ data.tar.gz: 0ee7b9a8500655f381832dfa7ec072eb56d59f13e95aaaf311c83ea0dd35a3a1165c0e466b3553e4e84016e46b4fe11bb7b5e69eedafab0862b8170f7f71001c
@@ -2,7 +2,7 @@ module Chef
2
2
  module Zero
3
3
  module Scheduled
4
4
  module Task
5
- VERSION = "0.0.4"
5
+ VERSION = "0.0.5"
6
6
  end
7
7
  end
8
8
  end
@@ -69,19 +69,27 @@ module Kitchen
69
69
 
70
70
  def run_scheduled_task_command
71
71
  <<-EOH
72
- if (test-path 'c:/chef/tk.log') {
73
- remove-item c:/chef/tk.log -force
74
- }
72
+ try {
73
+ $npipeServer = new-object System.IO.Pipes.NamedPipeServerStream( 'task', [System.IO.Pipes.PipeDirection]::In)
74
+ $pipeReader = new-object System.IO.StreamReader($npipeServer)
75
75
  schtasks /run /tn "chef-tk"
76
- $host.ui.WriteLine('Running scheduled task chef-tk.')
77
- do {
78
- $host.ui.WriteLine(' The task is still running.')
79
- start-sleep -seconds 5
80
- $state = schtasks /query /tn chef-tk /fo csv /v | convertfrom-csv
81
- } while ($state.status -like 'Running')
82
- $host.ui.WriteLine('')
83
- get-content c:/chef/tk.log -readcount 0
84
- $host.setshouldexit((gc c:/chef/exit_code.txt -readcount 0).trim())
76
+ $npipeserver.waitforconnection()
77
+ $host.ui.writeline('Connected to the scheduled task.')
78
+ while ($npipeserver.IsConnected) {
79
+ $output = $pipereader.ReadLine()
80
+ if ($output -like 'SCHEDULED_TASK_DONE:*') {
81
+ $exit_code = ($output -replace 'SCHEDULED_TASK_DONE:').trim()
82
+ }
83
+ else {
84
+ $host.ui.WriteLine($output)
85
+ }
86
+ }
87
+ }
88
+ finally {
89
+ $pipereader.dispose()
90
+ $npipeserver.dispose()
91
+ $host.setshouldexit($exit_code)
92
+ }
85
93
  EOH
86
94
  end
87
95
 
@@ -95,19 +103,22 @@ module Kitchen
95
103
 
96
104
  def scheduled_task_command
97
105
  <<-EOH
98
- $pre_cmd = '$env:temp = "' + $env:temp + '"'
106
+ $pre_cmd = '$env:temp = "' + $env:temp + '"' + ";"
107
+ $pre_cmd += 'start-sleep -seconds 5;'
108
+ $pre_cmd += '$npipeClient = new-object System.IO.Pipes.NamedPipeClientStream( $env:ComputerName,'
109
+ $pre_cmd += '"task", [System.IO.Pipes.PipeDirection]::Out); $npipeclient.connect();'
110
+ $pre_cmd += '$pipeWriter = new-object System.IO.StreamWriter($npipeClient);'
111
+ $pre_cmd += '$pipeWriter.AutoFlush = $true'
99
112
  $cmd_path = "#{remote_path_join(config[:root_path], 'chef-client-script.ps1')}"
100
- $cmd_to_eval = gc $cmd_path | out-string
101
- $cmd = $executioncontext.invokecommand.expandstring($cmd_to_eval)
102
- $post_cmd = '$LastExitCode | out-file c:/chef/exit_code.txt'
103
- $cmd_folder = split-path $cmd_path
104
- if (-not (test-path $cmd_folder)) {$null = mkdir $cmd_folder}
105
- $pre_cmd, $cmd, $post_cmd | out-file $cmd_path
113
+ $cmd_to_eval = gc $cmd_path -readcount 0 | out-string
114
+ $cmd = $executioncontext.invokecommand.expandstring($cmd_to_eval) -replace '\r\n'
115
+ $cmd = "$cmd | " + '% {} {$pipewriter.writeline($_)} {$pipewriter.writeline("SCHEDULED_TASK_DONE: $LastExitCode");$pipewriter.dispose();$npipeclient.dispose()}'
116
+ $pre_cmd, $cmd | out-file $cmd_path
106
117
  EOH
107
118
  end
108
119
 
109
120
  def prepare_client_zero_script
110
- cmd = [local_mode_command, *chef_client_args, '--logfile c:\chef\tk.log'].join(' ')
121
+ cmd = [local_mode_command, *chef_client_args].join(' ')
111
122
  File.open(File.join(sandbox_path, 'chef-client-script.ps1'), 'w') do |file|
112
123
  file.write(cmd)
113
124
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-zero-scheduled-task
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Murawski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-24 00:00:00.000000000 Z
11
+ date: 2015-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler