Updated mcollective.init according to OSCI-658
[packages/precise/mcollective.git] / lib / mcollective / windows_daemon.rb
diff --git a/lib/mcollective/windows_daemon.rb b/lib/mcollective/windows_daemon.rb
new file mode 100644 (file)
index 0000000..3516730
--- /dev/null
@@ -0,0 +1,25 @@
+require 'win32/daemon'
+
+module MCollective
+  class WindowsDaemon < Win32::Daemon
+    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
+
+    def service_main
+      Log.debug("Starting Windows Service Daemon")
+
+      runner = Runner.new(nil)
+      runner.run
+    end
+
+    def service_stop
+      Log.info("Windows service stopping")
+      PluginManager["connector_plugin"].disconnect
+      exit! 0
+    end
+  end
+end