Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When trying the Win32Utils one really need to studie the doc and look over the net before finding some simple working example. This seems to work today 2008-10-02:</p> <p>gem install win32-service</p> <p>Update 2012-11-20: According to <a href="https://stackoverflow.com/users/1374569/paul">https://stackoverflow.com/users/1374569/paul</a> the register_bar.rb should now be</p> <pre><code>Service.create( :service_name =&gt; 'some_service', :host =&gt; nil, :service_type =&gt; Service::WIN32_OWN_PROCESS, :description =&gt; 'A custom service I wrote just for fun', :start_type =&gt; Service::AUTO_START, :error_control =&gt; Service::ERROR_NORMAL, :binary_path_name =&gt; 'c:\usr\ruby\bin\rubyw.exe -C c:\tmp\ bar.rb', :load_order_group =&gt; 'Network', :dependencies =&gt; ['W32Time','Schedule'], :display_name =&gt; 'This is some service' ) </code></pre> <hr> <h1>bar.rb</h1> <h1>create the application/daemon</h1> <pre><code>LOG_FILE = 'C:\\test.log' begin require "rubygems" require 'win32/daemon' include Win32 class DemoDaemon &lt; Daemon def service_main while running? sleep 10 File.open("c:\\test.log", "a"){ |f| f.puts "Service is running #{Time.now}" } end end def service_stop File.open("c:\\test.log", "a"){ |f| f.puts "***Service stopped #{Time.now}" } exit! end end DemoDaemon.mainloop rescue Exception =&gt; err File.open(LOG_FILE,'a+'){ |f| f.puts " ***Daemon failure #{Time.now} err=#{err} " } raise end </code></pre> <hr> <p>bar.rb is the service but we must create and register first! this can be done with sc create some_service</p> <h2>but if we are going to use ruby and win32utils we should do a</h2> <h1>register_bar.rb</h1> <pre><code> require "rubygems" require "win32/service" include Win32 # Create a new service Service.create('some_service', nil, :service_type =&gt; Service::WIN32_OWN_PROCESS, :description =&gt; 'A custom service I wrote just for fun', :start_type =&gt; Service::AUTO_START, :error_control =&gt; Service::ERROR_NORMAL, :binary_path_name =&gt; 'c:\usr\ruby\bin\rubyw.exe -C c:\tmp\ bar.rb', :load_order_group =&gt; 'Network', :dependencies =&gt; ['W32Time','Schedule'], :display_name =&gt; 'This is some service' ) </code></pre> <hr> <p>Note, there is a space between c:\tmp\ bar.rb in 'c:\usr\ruby\bin\rubyw.exe -C c:\tmp\ bar.rb'</p> <p>Run <code>ruby register_bar.rb</code> and now one can start the service either from the windows service control panel or </p> <pre><code>sc start some_service </code></pre> <p>and watch c:test.log be filled with Service is running Thu Oct 02 22:06:47 +0200 2008</p> <h2>For the simple of have something to work with it is easier to remove the service register and create a new one instead of modifying a existing one</h2> <h1>unregister_bar.rb</h1> <pre><code> require "rubygems" require "win32/service" include Win32 Service.delete("some_service") </code></pre> <hr> <p>Credits to the people <a href="http://rubypane.blogspot.com/2008/05/windows-service-using-win32-service-and_29.html" rel="nofollow noreferrer">http://rubypane.blogspot.com/2008/05/windows-service-using-win32-service-and_29.html</a></p> <p><a href="http://rubyforge.org/docman/view.php/85/595/service.html" rel="nofollow noreferrer">http://rubyforge.org/docman/view.php/85/595/service.html</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload