How to start a service with the win32-service gem

Discussion in 'Ruby' started by Kai Geng, Dec 12, 2007.

  1. Kai Geng

    Kai Geng Guest

    Hi
    I have install the win32-service 0.6.0 and made some test code just like
    these:

    require 'rubygems'
    require "win32/service"
    require "Win32API"
    include Win32

    begin
    srv = Service.new()
    srv.binary_path_name = "c:/ruby/bin/ruby " + File.expand_path($0)
    srv.create_service{|s|
    s.service_name = "foo"

    s.display_name = "Test_Demo"
    s.service_description = "Greatest Service"
    }
    srv.configure_service{|serv|
    serv.display_name = "My Service"
    serv.start_type = Service::AUTO_START
    serv.service_type = Service::WIN32_OWN_PROCESS
    }
    srv.close
    rescue
    end

    class Daemon
    def service_init
    sleep(200)
    end
    def service_main
    system('notepad')
    while running?
    #puts 'the service in running'
    if state == RUNNING
    system('notepad')
    sleep 5
    end
    end
    end
    d = Daemon.new
    d.mainloop
    end
    the service can be registered but can't to be start.When I try to
    run(start) it in the Management Console that I will get the 1053 error
    with the service.How can I to rescue the problem.
    My OS is Windows XP SP2
    Any help will be very grateful.
    --
    Posted via http://www.ruby-forum.com/.
     
    Kai Geng, Dec 12, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    173
  2. Clifford Heath
    Replies:
    7
    Views:
    334
    Shanti Braford
    Jun 9, 2006
  3. Austin 7873
    Replies:
    5
    Views:
    216
    Eric Hodel
    Jan 27, 2007
  4. Grant Birchmeier
    Replies:
    5
    Views:
    139
    Grant Birchmeier
    May 8, 2009
  5. Daniel Stephens

    win32-service gem

    Daniel Stephens, Jun 16, 2011, in forum: Ruby
    Replies:
    4
    Views:
    698
    Luis Lavena
    Jun 17, 2011
Loading...

Share This Page