-
Notifications
You must be signed in to change notification settings - Fork 35
/
poller
executable file
·51 lines (40 loc) · 953 Bytes
/
poller
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env ruby
require 'yajl'
require 'yaml'
require 'optparse'
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
require 'chef/cache'
require 'chef/version'
class Poller
attr_reader :options
def initialize
@options = {}
optparse = OptionParser.new do |opts|
opts.banner = "Usage: #{$0}"
opts.on_tail('-h', '--help', 'Print this help message') do
puts opts
exit
end
opts.on('-s SLEEP',
"Specify a sleep interval that will infinitely loop execution") do |s|
@options[:sleep] = s
end
end
optparse.parse!
end
def cache
@cache ||= Chef::Cache.new()
end
def run
cache.update
end
end
if File.absolute_path($0) == File.absolute_path(__FILE__)
poller = Poller.new
poller.run
while poller.options[:sleep]
puts "Sleep time set to #{poller.options[:sleep]}"
sleep poller.options[:sleep].to_i
poller.run
end
end