Windows Service

1 view
Skip to first unread message

kallen

unread,
Aug 11, 2008, 3:36:54 PM8/11/08
to Ramaze
I'm trying to get Ramaze to run in a windows service and not having
any luck. Has anyone ever gotten this to work? Here's the daemon code
we've been working with. The ramaze app is just a really simple one
controller deal just to see if this will work.

begin
require 'win32/daemon'
require 'ramaze'

$: << File.expand_path(File.dirname(__FILE__))

require 'test'

include Win32

class DemoDaemon < Daemon
def service_init
open("c:/blah.log", "a") { |f| f << "initing\n" }
Ramaze::Log.loggers << Ramaze::Logging::Logger::Informer.new("C:/
ramaze.log")
Ramaze::Global.run_loose = true
Ramaze.start :adapter => :webrick
end

def service_main(*args)
while running?
open("c:/blah.log", "a") { |f| f << "running\n" }
sleep(3)
end
end

# This event triggers when the service receives a signal to stop.
#
def service_stop
Ramaze::Adapter.shutdown
end
end

DemoDaemon.mainloop
rescue Exception => err
open("c:/blah.log", "a") do |f|
f << err.message + "\n"
f << err.backtrace.join("\n")
end
end

Sorry about the formatting, it's pasted from an email.

kallen

unread,
Aug 11, 2008, 3:46:44 PM8/11/08
to Ramaze
We figured it out. It's because the logger was trying to write to
stdout. This seems to be disallowed in windows services so the whole
thing hangs. Just clear out the Ramaze::Log.loggers array before you
do anything. Now we just have to figure out how to make it stop
right :/

Michael Fellinger

unread,
Aug 12, 2008, 1:13:53 AM8/12/08
to ram...@googlegroups.com

Calling Ramaze::shutdown should do the trick.
Also, you can redirect the logger to a file:
Ramaze::Log.loggers.clear
Ramaze::Log.loggers << Ramaze::Logger::Informer.new('live.log')

I'm sorry, i have no experience with windows services, so I'm afraid I
cannot provide anything more useful.

^ manveru

Reply all
Reply to author
Forward
0 new messages