win32utils-devel@rubyforge.org
2004-Apr-09 00:38 UTC
[Win32utils-devel] Issues with win32-service Daemon
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? Dan # myservice.rb require "socket" require "win32/service" include Win32 class MyDaemon < Daemon def service_main File.open("c:\\test.log","a+"){ |f| f.puts("service_main entered") } 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!" end File.open("c:\\test.log","a+") { |f| f.puts("service_main left") } #s.close end end m = MyDaemon.new m.mainloop # run_service.rb require "win32/service" include Win32 Name = "AbbaSvc" DisplayName = "Abba" file = ''c:\eclipse\workspace\ruby_foo\service_stuff\myservice.rb'' bin = "ruby " + file if Service.exists?(Name) if Service.status(Name).current_state == "running" Service.stop(Name) sleep 3 puts "Stopped service" end n = 3 begin Service.delete(Name) rescue Win32::ServiceError => e puts "Unable to delete: #{e}" if n > 0 puts "Retrying..." sleep 2 n -= 1 retry else STDERR.puts "Unable to delete. Exiting..." exit end end puts "Deleted service" end svc = Service.new svc.create_service{ |s| s.service_name = Name s.display_name = DisplayName s.binary_path_name = ''c:\ruby\bin\ruby '' + file s.dependencies = [] } svc.close puts "Service installed. Attempting to start service" sleep 2 Service.start(Name) sleep 1 puts "Service started..." _________________________________________________________________ Tax headache? MSN Money provides relief with tax tips, tools, IRS forms and more! http://moneycentral.msn.com/tax/workshop/welcome.asp
win32utils-devel@rubyforge.org
2004-Apr-10 04:07 UTC
[Win32utils-devel] Issues with win32-service Daemon
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); with cDaemon = rb_define_class_under(mWin32, "Daemon", rb_cObject); 2. Try begin ... rescue for exception handling. You will see what cause the termination. Park Heesob # myservice.rb require "socket" require "win32/service" include Win32 class MyDaemon < Daemon def initialize @a = "10" end def service_main begin 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!" end File.open("c:\\test.log","a+") { |f| f.puts("service_main left") } #s.close end rescue StandardError, Interrupt File.open("c:\\test.log","a+") { |f| f.puts("Error: #{$!}") } end end m = MyDaemon.new m.mainloop
win32utils-devel@rubyforge.org
2004-Apr-12 11:10 UTC
[Win32utils-devel] Issues with win32-service Daemon
> -----Original Message----- > From: win32utils-devel-bounces@rubyforge.org > [mailto:win32utils-devel-bounces@rubyforge.org] On Behalf Of > win32utils-devel@rubyforge.org > Sent: Saturday, April 10, 2004 1:46 AM > To: win32utils-devel@rubyforge.org > Subject: Re: [Win32utils-devel] Issues with win32-service Daemon > > > 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); with > cDaemon = rb_define_class_under(mWin32, "Daemon", rb_cObject);Perhaps we should do this. I''m trying to remember if we had a good reason for making it a subclass of Service.> > 2. Try begin ... rescue for exception handling. You will see > what cause the termination. > > Park Heesob > > # myservice.rb > require "socket" > require "win32/service" > include Win32 > > class MyDaemon < Daemon > def initialize > @a = "10" > end > > def service_main > begin > 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!" > end > File.open("c:\\test.log","a+") { |f| f.puts("service_main left") } > #s.close > end > rescue StandardError, Interrupt > File.open("c:\\test.log","a+") { |f| f.puts("Error: #{$!}") } > end > > end > > m = MyDaemon.new > m.mainloopActually it doesn''t seem to help - nothing gets logged except in the Event Log. It takes about 10-15 minutes for this to happen, btw. A little Google searching indicates that the SCM is receiving an unexpected exit somehow, so I may slap some extra code in to "watch" the SCM to see what''s going on. Regards, Dan