Ruby as Windows Service

  • Thread starter Mehr, Assaph (Assaph)
  • Start date
M

Mehr, Assaph (Assaph)

Hi All,

I almost got to the point where I can install any ruby program as a
Windows
service. I do this using cygwin. For example to install Instiki as a
service:

$ cygrunsrv --instal Instiki --path c:/ruby/bin/ruby.exe --args
c:/Stuff/instiki-0.9.1/instiki.rb

The executable for the service (--path) is my Win32 (not cygwin's) Ruby
executable. The argument is the name of the ruby script to run.

The service installs and start fine, but cannot be stopped (the process
has
to be manually killed). I have tried specifying various termination
signals
(using --termsig) and using a Kernel#trap to respond to them, but the
trap
is never executed, and the process doesn't stop. E.g.:
trap("TERM") { @server.shutdown; exit(0) }

The only signal that stops the process is SIGSEGV, which isn't very nice
:p.
Besides, even traps for it don't work.

Any clues as to how to fix?


Cheers,
Assaph
 
C

Chad Fowler

Hi All,

I almost got to the point where I can install any ruby program as a
Windows
service. I do this using cygwin. For example to install Instiki as a
service:

$ cygrunsrv --instal Instiki --path c:/ruby/bin/ruby.exe --args
c:/Stuff/instiki-0.9.1/instiki.rb

The executable for the service (--path) is my Win32 (not cygwin's) Ruby
executable. The argument is the name of the ruby script to run.

The service installs and start fine, but cannot be stopped (the process
has
to be manually killed). I have tried specifying various termination
signals
(using --termsig) and using a Kernel#trap to respond to them, but the
trap
is never executed, and the process doesn't stop. E.g.:
trap("TERM") { @server.shutdown; exit(0) }

The only signal that stops the process is SIGSEGV, which isn't very nice
:p.
Besides, even traps for it don't work.

Any clues as to how to fix?

Not exactly what you're asking for, but there used to be a program
that came with the Windows NT resource kit called "srvany.exe". It
does the same thing as the cygwin program, but it doesn't use Cygwin.
I wonder if it would work better for you? It apparently works on all
of the newer versions of Windows, too. I'm not sure where you could
get it now, though.

Chad
International Ruby Conference - http://rubycentral.org/conference
RubyGems! - http://rubygems.rubyforge.org
 
E

Erik Veenstra

Hi All,

The service installs and start fine, but cannot be stopped
(the process has to be manually killed). I have tried
specifying various termination signals (using --termsig) and
using a Kernel#trap to respond to them, but the trap is never
executed, and the process doesn't stop. E.g.: trap("TERM") {
@server.shutdown; exit(0) }

The only signal that stops the process is SIGSEGV, which
isn't very nice :p. Besides, even traps for it don't work.

Any clues as to how to fix?

It's probably due to the fact that the Ruby interpreter
releases control to Windows when it waits for events. So you
have to have an event on a regular basis...

I've had the same problem with a TCPServer and came up with the
following hack:

# The hack...

def self.trap(signal)
Kernel::trap(signal){yield}
Thread.new{loop{sleep 1}} # Stupid Windows...
end

# Doesn't work with Kernel.trap .
# Try it!

trap("INT"){puts "Terminating..." ; exit}

# Just a demo...

require "socket"
puts "Hit ^C..."
TCPServer.new("0.0.0.0", 1234).accept

gegroet,
Erik V.
 
R

Robert Cowham

@au3010avexu1.global.avaya.com:
Hi All,

I almost got to the point where I can install any ruby program as a
Windows
service. I do this using cygwin. For example to install Instiki as a
service:

$ cygrunsrv --instal Instiki --path c:/ruby/bin/ruby.exe --args
c:/Stuff/instiki-0.9.1/instiki.rb

I have successfully used FireDaemon to run things as a service. Free for a
single service, low cost for multiple services.
 
L

Leonid Khachaturov

Robert said:
@au3010avexu1.global.avaya.com:




I have successfully used FireDaemon to run things as a service. Free for a
single service, low cost for multiple services.
I second the recommendation of FireDaemon - been using it for a month to
run Instiki, works like a charm.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,162
Latest member
GertrudeMa
Top