Class: Chef::Application::WindowsService
- Inherits:
-
Win32::Daemon
- Object
- Win32::Daemon
- Chef::Application::WindowsService
show all
- Includes:
- Mixin::ShellOut, Mixlib::CLI
- Defined in:
- lib/chef/application/windows_service.rb
Instance Method Summary
collapse
apply_default_env, maybe_add_timeout, #shell_out, #shell_out!
Instance Method Details
#service_init ⇒ Object
65
66
67
68
69
70
71
|
# File 'lib/chef/application/windows_service.rb', line 65
def service_init
@service_action_mutex = Mutex.new
@service_signal = ConditionVariable.new
reconfigure
Chef::Log.info("#{Chef::Dist::CLIENT} Service initialized")
end
|
#service_main(*startup_parameters) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/chef/application/windows_service.rb', line 73
def service_main(*startup_parameters)
timeout = rand Chef::Config[:splay]
while running?
@service_action_mutex.synchronize do
begin
Chef::Log.info("Next #{Chef::Dist::CLIENT} run will happen in #{timeout} seconds")
@service_signal.wait(@service_action_mutex, timeout)
next if state != RUNNING
Chef::Log.info("Reconfiguring with startup parameters")
reconfigure(startup_parameters)
timeout = Chef::Config[:interval]
timeout += rand Chef::Config[:splay]
next if state != RUNNING
Chef::Log.info("#{Chef::Dist::CLIENT} service is starting a #{Chef::Dist::CLIENT} run...")
run_chef_client
rescue SystemExit => e
Chef::Log.error("#{e.class}: #{e}")
rescue Exception => e
Chef::Log.error("#{e.class}: #{e}")
end
end
end
Chef::Log.trace("Giving signal callbacks some time to exit...")
sleep 1
Chef::Log.trace("Exiting service...")
end
|
#service_pause ⇒ Object
146
147
148
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/chef/application/windows_service.rb', line 146
def service_pause
Chef::Log.info("PAUSE request from operating system.")
if @service_action_mutex.locked?
Chef::Log.info("Currently a #{Chef::Dist::PRODUCT} run is happening.")
Chef::Log.info("Service will pause once it's completed.")
else
Chef::Log.info("Service is pausing....")
end
end
|
#service_resume ⇒ Object
160
161
162
163
164
165
166
|
# File 'lib/chef/application/windows_service.rb', line 160
def service_resume
Chef::Log.info("RESUME signal received from the OS.")
Chef::Log.info("Service is resuming....")
end
|
#service_shutdown ⇒ Object
168
169
170
171
172
173
174
|
# File 'lib/chef/application/windows_service.rb', line 168
def service_shutdown
Chef::Log.info("SHUTDOWN signal received from the OS.")
service_stop
end
|
#service_stop ⇒ Object
Control Signal Callback Methods
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/chef/application/windows_service.rb', line 122
def service_stop
run_warning_displayed = false
Chef::Log.info("STOP request from operating system.")
loop do
if @service_action_mutex.try_lock
@service_signal.signal
@service_action_mutex.unlock
break
else
unless run_warning_displayed
Chef::Log.info("Currently a #{Chef::Dist::PRODUCT} run is happening on this system.")
Chef::Log.info("Service will stop when run is completed.")
run_warning_displayed = true
end
Chef::Log.trace("Waiting for #{Chef::Dist::PRODUCT} run...")
sleep 1
end
end
Chef::Log.info("Service is stopping....")
end
|