Ruby scripts as Win32-Service


#1

I’ve through together a ruby script as test for a monitoring app for a
few
Win32 user processes I’m stuck with supporting. I’ve gotten most of the
management setup, however, I’m stuck trying to figure out how to run the
script as a service. I tried creating the service manually with
sc.exehttp://support.microsoft.com/?kbid=251192,
with both the script and a call to c:\ruby\bin\rubyw.exe with the
filename
as the argument, but I receive a time-out. I spent some time with
google,
but perhaps I’m missing something silly?

Does win32-service do something special when creating a service that I’m
missing with the manual service creation? I suppose I could always run
it
via the startup folder, but I thought this would be cleaner.

Thanks,

William R.


#2

On 2/17/06, William R. removed_email_address@domain.invalid wrote:

missing with the manual service creation? I suppose I could always run it
via the startup folder, but I thought this would be cleaner.

Thanks,

William R.

You did “install” the service using win3-service right? (just asking)

pth


#3

On 2/17/06, Patrick H. removed_email_address@domain.invalid wrote:

You did “install” the service using win3-service right? (just asking)

Nope, I used the command sc.exe, which allows you to create services. I
didn’t see the need to create an ‘installer’ just for testing purposes.
I
browsed the win32-service documentation and it didn’t appear to do
anything
special with regards to service creation.


#4

On 2/17/06, William R. removed_email_address@domain.invalid wrote:

On 2/17/06, Patrick H. removed_email_address@domain.invalid wrote:

You did “install” the service using win3-service right? (just asking)
Nope, I used the command sc.exe, which allows you to create services. I
didn’t see the need to create an ‘installer’ just for testing purposes. I
browsed the win32-service documentation and it didn’t appear to do anything
special with regards to service creation.

It’s not a traditional installer; it’s registering the service. Look
at what Ruwiki does for service management in its command-line.

-austin


#5

Does win32-service do something special when creating a service that I’m
missing with the manual service creation? I suppose I could always run it
via the startup folder, but I thought this would be cleaner.

Check out the instiki instructions for running a ruby script as a
windows service:

http://instiki.org/show/Running+as+a+Windows+Service

Regards,

Peter


#6

On 2006-02-18, Patrick H. removed_email_address@domain.invalid wrote:

On 2/17/06, William R. removed_email_address@domain.invalid wrote:

… I’m stuck trying to figure out how to run the script as a
service.

I did this at $WORK a while back (with ActivePerl rather than Ruby).
I used SRVANY.EXE (from the Windows NT Resource Kit), which is a
wrapper that turns any executable into a Windows service. You
register SRVANY.EXE as the service, then create Registry keys to tell
it which program to run (RUBY.EXE, I guess), what arguments to give it
(-w my_script.rb) and what directory to run it in. I’m not at work
right now so I’m short of details but IIRC it was quite
straightforward. Googling for SRVANY.EXE turns up
URL:http://www.liutilities.com/products/wintaskspro/processlibrary/srvany,
“srvany.exe is an additional Microsoft Windows application which
allows an executable to be ran as a service.”. Hope this helps.

Cheers,

Jeremy H.


#7

Hi Xavier,

Hey I know practically nothing about Windows. Could I follow those
instructions to have WEBrick always running an easily deploy a simple
management Rails tool for internal usage?

Few comments:

  • It’s very much possible to do so. I personally prefer cygwin’s
    cygrunsrv, but the above instructions work flawlessly.
  • The service created is not a “real” win32 service - it doesn’t
    respond to TERM signals and the only way to stop it is to either kill
    the process or build a stop command in your app.
  • If you’re on windows, why not go with InstantRails?
    (http://instantrails.rubyforge.org/)

Cheers,
Assaph


#8

On Feb 18, 2006, at 13:57, Assaph M. wrote:

respond to TERM signals and the only way to stop it is to either kill
the process or build a stop command in your app.

Nice. I’ll consider this solution.

Because my application uses SQLite. Porting the database is an
option, it’s just a handful of tables, but I am exploring available
solutions for ease (read as trivial as possible) deployment.

– fxn


#9

Because my application uses SQLite. Porting the database is an
option, it’s just a handful of tables, but I am exploring available
solutions for ease (read as trivial as possible) deployment.

I developed something in house that run on WEBrick and SQLite (only
one table :). When it came time to share with others, it was just
easier to use InstantRails with it’s preconfigured everything, then
put up ruby, the web server etc independently. YMMV.

Assaph


#10

On Feb 18, 2006, at 8:25, Peter K. wrote:

Does win32-service do something special when creating a service
that I’m
missing with the manual service creation? I suppose I could always
run it
via the startup folder, but I thought this would be cleaner.

Check out the instiki instructions for running a ruby script as a
windows service:

http://instiki.org/show/Running+as+a+Windows+Service

Hey I know practically nothing about Windows. Could I follow those
instructions to have WEBrick always running an easily deploy a simple
management Rails tool for internal usage?

– fxn