run a ruby file as windows service

I have a ruby file called my_program.rb which creates a system tray icon on windows. When I do ruby my_program.rb it works fine. But I would like to make this as a windows service.

Was checking out this guide using win32/daemon and could create a windows service.

I have done everything similar to the above link except the below file :

**service.rb**

require 'rubygems'
require 'win32/daemon'
include Win32

class TestDaemon < Daemon
  def service_main
    `ruby my_program.rb`
  end

  def service_stop
    exit!
  end
end

TestDaemon.mainloop

when I run service.rb it just creates a service by my program is not running. Any Pointers will be helpful.

Thanks in advance.


Source: windows

Leave a Reply