Class: Chef::Application::WindowsService

Inherits:
Win32::Daemon
  • Object
show all
Includes:
Mixlib::CLI
Defined in:
lib/chef/application/windows_service.rb

Instance Method Summary collapse

Instance Method Details

#service_initObject



69
70
71
72
# File 'lib/chef/application/windows_service.rb', line 69

def service_init
  reconfigure
  Chef::Log.info("Chef Client Service initialized")
end

#service_main(*startup_parameters) ⇒ Object



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
117
118
119
# File 'lib/chef/application/windows_service.rb', line 74

def service_main(*startup_parameters)

  while running?
    if state == RUNNING
      begin
        # Reconfigure each time through to pick up any changes in the client file
        Chef::Log.info("Reconfiguring with startup parameters")
        reconfigure(startup_parameters)

        splay = rand Chef::Config[:splay]
        Chef::Log.debug("Splay sleep #{splay} seconds")
        sleep splay

        # If we've stopped, then bail out now, instead of going on to run Chef
        next if state != RUNNING

        @chef_client = Chef::Client.new(
          @chef_client_json, 
          :override_runlist => config[:override_runlist]
        )
        @chef_client_json = nil

        @chef_client.run
        @chef_client = nil

        Chef::Log.debug("Sleeping for #{Chef::Config[:interval]} seconds")
        client_sleep Chef::Config[:interval]
      rescue Chef::Application::Wakeup => e
        Chef::Log.debug("Received Wakeup signal.  Starting run.")
        next
      rescue SystemExit => e
        raise
      rescue Exception => e
        Chef::Log.error("#{e.class}: #{e}")
        Chef::Application.debug_stacktrace(e)
        Chef::Log.error("Sleeping for #{Chef::Config[:interval]} seconds before trying again")
        client_sleep Chef::Config[:interval]
        retry
      ensure
        GC.start
      end
    else # PAUSED or IDLE
      sleep 5
    end
  end
end

#service_pauseObject



129
130
131
# File 'lib/chef/application/windows_service.rb', line 129

def service_pause
  Chef::Log.info("SERVICE_CONTROL_PAUSE received, pausing")
end

#service_resumeObject



133
134
135
# File 'lib/chef/application/windows_service.rb', line 133

def service_resume
  Chef::Log.info("SERVICE_CONTROL_CONTINUE received, resuming")
end

#service_shutdownObject



137
138
139
# File 'lib/chef/application/windows_service.rb', line 137

def service_shutdown
  Chef::Log.info("SERVICE_CONTROL_SHUTDOWN received, shutting down")
end

#service_stopObject

Control Signal Callback Methods



125
126
127
# File 'lib/chef/application/windows_service.rb', line 125

def service_stop
  Chef::Log.info("SERVICE_CONTROL_STOP received, stopping")
end