= Description The Daemon class is a wrapper class that allows you to run your code as a Windows service. = Synopsis class Daemon def service_main while running? sleep 3 File.open("c:\\test.log", "a"){ |f| f.puts "service is running" } end end end Daemon.mainloop = Singleton Methods Daemon.mainloop This is the method that actually puts your code into a loop and allows it to run as a service. The code that is actually run while in the mainloop is what you defined in the Daemon#service_main method. = Instance Methods Daemon#running? Returns whether or not the daemon is running. This is just a shortcut for checking if the state is RUNNING, PAUSED or IDLE. This is typically used within your service_main method. See the demo_daemon.rb file in the 'examples' directory for an example of how it's used in practice. Daemon#service_init Any code defined defined within this method occurs before service_main is reached. Any initialization code that takes more than two seconds to execute should be placed here. Otherwise, your service may timeout when you try to start it. Daemon#service_main(*args) You are expected to define your own service_main() method. The code defined in this method is the code that will run while running as a service. Any +args+ passed to Service.start are passed to this method. Daemon#state Returns the current state of the Daemon. For a list of valid states, see the Constants section below. = Signal Event Hooks These methods are called if defined within your Daemon class, and the appropriate signal is received by your service. Daemon#service_stop Called if the service receives a SERVICE_CONTROL_STOP signal. This is what the Service.stop() method sends. Daemon#service_pause Called if the service receives a SERVICE_CONTROL_PAUSE signal. This is what the Service.pause() method sends. Daemon#service_resume Called if the service receives a SERVICE_CONTROL_CONTINUE signal. This is what the Service.resume() method sends. Daemon#service_interrogate Called if the service receives a SERVICE_CONTROL_INTERROGATE signal. This notifies a service that it should report its current status information to the service control manager. Daemon#service_shutdown Called if the service receives a SERVICE_CONTROL_SHUTDOWN signal. Daemon#service_netbindadd Called if the service receives a SERVICE_CONTROL_NETBINDADD signal. This notifies a network service that there is a new component for binding. Daemon#service_netbinddisable Called if the service receives a SERVICE_CONTROL_NETBINDDISABLE signal. This notifies a network service that one of its bindings has been disabled. Daemon#service_netbindenable Called if the service receives a SERVICE_CONTROL_NETBINDENABLE signal. This Notifies a network service that a disabled binding has been enabled. Daemon#service_netbindremove Called if the service receives a SERVICE_CONTROL_NETBINDREMOVE signal. This notifies a network service that that a component for binding has been removed. Daemon#service_paramchange Called if the service receives a SERVICE_CONTROL_PARAMCHANGE signal. This notifies a service that its startup parameters have changed. = Constants === Service state constants Daemon::CONTINUE_PENDING The service continue is pending. Daemon::PAUSE_PENDING The service pause is pending. Daemon::PAUSED The service is paused (but not STOPPED). Daemon::RUNNING The service is running. Daemon::START_PENDING The service is starting (but is not yet in a RUNNING state). Daemon::STOP_PENDING The service is stopping (but is not yet in a STOPPED state). Daemon::STOPPED The service is not running. Daemon::IDLE The service is running, in an idle state. This is a custom state that we added that gets around a thread blocking issue. = Notes You must create a service before you can actually run it. Look in the examples directory for the files 'demo_daemon.rb' and 'demodaemon_ctl.rb'. They're small and straightforward examples of how to control, install and setup your own Daemon. = Known Bugs None known. Please report any bugs you find on the Bug tracker at http://rubyforge.org/projects/win32utils. = Future Plans Rewrite the Daemon class in pure Ruby. Suggestions welcome. Please log them on the Feature Request tracker at http://rubyforge.org/projects/win32utils = Acknowledgements Many thanks go to Patrick Hurley for providing the fix for the thread blocking issue. Thanks also go to Kevin Burge for his patch that solved service responsiveness issues. = Copyright (C) 2003-2011 Daniel J. Berger, All Rights Reserved = License Artistic 2.0 = Warranty This package is provided "as is" and without any express or implied warranties, including, without limitation, the implied warranties of merchantability and fitness for a particular purpose. = Author(s) * Daniel J. Berger * Park Heesob