[Win32utils-devel] Issues with win32-service Daemon

win32utils-devel at rubyforge.org win32utils-devel at rubyforge.org
Sat Apr 10 17:45:34 EDT 2004

Hi Dan,

> Hi all,
> I wrote a little echo client to run as a service.  I have a couple of
> problems with this.   First, any time I try to define anything in
> "initialize", the service fails to start.  Any idea why?
> Also, this service runs for a while, then just quits for no reason that I
> can see.  The Event Log merely says, "The Abba service terminated
> unexpectedly".
> Any ideas on either issue?
1. You can solve the problem by breaking off the relation between Daemon
class and Service class.
Modify service.c line 1579
  cDaemon  = rb_define_class_under(mWin32, "Daemon", rb_cService);
  cDaemon  = rb_define_class_under(mWin32, "Daemon", rb_cObject);

2. Try begin ... rescue for exception handling. You will see what cause the

Park Heesob

# myservice.rb
require "socket"
require "win32/service"
include Win32

class MyDaemon < Daemon
def initialize
  @a = "10"

def service_main
  File.open("c:\\test.log","a+"){ |f| f.puts("service_main entered with
#{@a}") }
  s = TCPServer.new(8888)
  while socket = s.accept
   rv = socket.gets.chomp
   File.open("c:\\test.log","a+"){ |f| f.puts "GOT: #{rv}" }
   socket.puts "Thanks!"
  File.open("c:\\test.log","a+") { |f| f.puts("service_main left") }
    rescue StandardError, Interrupt
        File.open("c:\\test.log","a+") { |f| f.puts("Error: #{$!}") }


m = MyDaemon.new

More information about the win32utils-devel mailing list