28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/flock_of_chefs/flocked_chef.rb', line 28
def run_application
unless Chef::Platform.windows?
SELF_PIPE.replace IO.pipe
trap("USR1") do
Chef::Log.info("SIGUSR1 received, waking up")
SELF_PIPE[1].putc('.') end
end
if Chef::Config[:version]
puts "Chef version: #{::Chef::VERSION}"
end
if Chef::Config[:daemonize]
Chef::Daemon.daemonize("chef-client")
end
loop do
begin
if Chef::Config[:splay]
splay = rand Chef::Config[:splay]
Chef::Log.debug("Splay sleep #{splay} seconds")
sleep splay
end
run_chef_client
if Chef::Config[:interval]
Chef::Log.debug("Sleeping for #{Chef::Config[:interval]} seconds")
unless SELF_PIPE.empty?
client_sleep Chef::Config[:interval]
else
sleep Chef::Config[:interval]
end
else
Chef::Application.exit! "Exiting", 0
end
rescue Chef::Application::Wakeup => e
Chef::Log.debug("Received Wakeup signal. Starting run.")
next
rescue SystemExit => e
raise
rescue Exception => e
if Chef::Config[:interval]
Chef::Log.error("#{e.class}: #{e}")
Chef::Application.debug_stacktrace(e)
Chef::Log.error("Sleeping for #{Chef::Config[:interval]} seconds before trying again")
unless SELF_PIPE.empty?
client_sleep Chef::Config[:interval]
else
sleep Chef::Config[:interval]
end
retry
else
Chef::Application.debug_stacktrace(e)
Chef::Application.fatal!("#{e.class}: #{e.message}", 1)
end
end
end
end
|