Class: MCollective::WindowsDaemon

Inherits:
Win32::Daemon
  • Object
show all
Defined in:
lib/mcollective/windows_daemon.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.daemonize_runner(pid = nil) ⇒ Object



6
7
8
9
10
11
# File 'lib/mcollective/windows_daemon.rb', line 6

def self.daemonize_runner(pid=nil)
  raise "Writing pid files are not supported on the Windows Platform" if pid
  raise "The Windows Daemonizer should only be used on the Windows Platform" unless Util.windows?

  WindowsDaemon.mainloop
end

Instance Method Details

#service_mainObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/mcollective/windows_daemon.rb', line 13

def service_main
  Log.debug("Starting Windows Service Daemon")

  @runner = Runner.new(nil)
  @runner.main_loop

  # On shut down there may be threads outside of the runner's context that are
  # in a sleeping state, causing the stop action to wait for them to cleanly exit.
  # We get around this by iterating the list of threads and killing everything that
  # isn't the main thread, letting us shut down cleanly.
  Thread.list.each do |t|
    if t != Thread.current
      t.kill
    end
  end
end

#service_pauseObject



35
36
37
38
# File 'lib/mcollective/windows_daemon.rb', line 35

def service_pause
  Log.info("Pausing MCollective Windows server")
  @runner.pause
end

#service_resumeObject



40
41
42
43
# File 'lib/mcollective/windows_daemon.rb', line 40

def service_resume
  Log.info("Resuming MCollective Windows server")
  @runner.resume
end

#service_stopObject



30
31
32
33
# File 'lib/mcollective/windows_daemon.rb', line 30

def service_stop
  Log.info("Windows service stopping")
  @runner.stop
end