Module: W32Support
- Defined in:
- lib/mongrel_config/win32.rb
Overview
Simply abstracts the common stuff that the config tool needs to do when dealing with Win32. It is a very thin wrapper which may expand later.
Class Method Summary collapse
-
.delete(service_name) ⇒ Object
Deletes the service from the system.
-
.display(name) ⇒ Object
Just gets the display name of the service.
-
.do_and_wait(service_name, operation, wait_for) ⇒ Object
Performs one operations (like :start or :start) which need to be “monitored” until they’re done.
-
.list ⇒ Object
Lists all of the services that have “mongrel” in the binary_path_name of the service.
-
.start(service_name) ⇒ Object
Starts the requested service and calls a passed in block until the service is done.
-
.status(service_name) ⇒ Object
Returns the current_state field of the service.
-
.stop(service_name) ⇒ Object
Stops the service.
Class Method Details
.delete(service_name) ⇒ Object
Deletes the service from the system. It first tries to stop the service, and if you pass in a block it will call it while the service is being stopped.
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/mongrel_config/win32.rb', line 71 def W32Support.delete(service_name) begin W32Support.stop(service_name) do |status| yield status if block_given? end rescue end begin Win32::Service.delete(service_name) rescue end end |
.display(name) ⇒ Object
Just gets the display name of the service.
16 17 18 |
# File 'lib/mongrel_config/win32.rb', line 16 def W32Support.display(name) Win32::Service.getdisplayname(name) end |
.do_and_wait(service_name, operation, wait_for) ⇒ Object
Performs one operations (like :start or :start) which need to be “monitored” until they’re done. The wait_for parameter should be a regex for the content of the status like /running/ or /stopped/
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mongrel_config/win32.rb', line 24 def W32Support.do_and_wait(service_name, operation, wait_for) status = W32Support.status(service_name) if status =~ wait_for # already running call the block once and leave yield status else # start trying to start it Win32::Service.send(operation, service_name) status = W32Support.status(service_name) while status !~ wait_for yield status status = W32Support.status(service_name) end # do one last yield so they know it started yield status end end |
.list ⇒ Object
Lists all of the services that have “mongrel” in the binary_path_name of the service. This detects the mongrel services.
11 12 13 |
# File 'lib/mongrel_config/win32.rb', line 11 def W32Support.list Win32::Service.services.select {|s| s.binary_path_name =~ /mongrel/ } end |
.start(service_name) ⇒ Object
Starts the requested service and calls a passed in block until the service is done. You should sleep for a short period until it’s done or there’s an exception.
46 47 48 49 50 |
# File 'lib/mongrel_config/win32.rb', line 46 def W32Support.start(service_name) W32Support.do_and_wait(service_name, :start, /running/) do |status| yield status end end |
.status(service_name) ⇒ Object
Returns the current_state field of the service.
63 64 65 |
# File 'lib/mongrel_config/win32.rb', line 63 def W32Support.status(service_name) Win32::Service.status(service_name).current_state end |
.stop(service_name) ⇒ Object
Stops the service. Just like W32Support.start is will call a block while it checks for the service to actually stop.
55 56 57 58 59 |
# File 'lib/mongrel_config/win32.rb', line 55 def W32Support.stop(service_name) W32Support.do_and_wait(service_name, :stop, /stopped/) do |status| yield status end end |