maandag 7 mei 2012



Installing ruby or rails as a service on windows 7 


There are a lot of google pages on this subject but a lot of them didn't work with my windows 7 installation. (especially the ones that use the sc command to create a service)
So here is my version that worked to hopefully save you a lot of time :

For installing rails as a service we need 2 executables from the windows 2003 resource kit:  instsrv.exe and svrany.exe
  • instsrv.exe will install the service 
  • svrany.exe is a wrapper program to serve any program as a service

1. download  and install the windows 2003 resource kit tools ( i got some errors when installing but ignored them)

The resource kit should allready be added to the path.
     on 32 bits :C:\Program Files\Windows Resource Kits\Tools   
     on 64 bits system: C:\Program Files (x86)\Windows Resource Kits\Tools

2. now  we need to add srvany.exe  as a service so that we can bind it to our ruby/rails app:
     instsrv <service name> <exe file>  
     Where exe location is the path to srvany.exe (e.g.: C:\Program Files\Windows Resource Kits\Tools )
  
3. The service is  installed and we need bind it to start ruby apps :). We do this in the registry.
     so we go the registry (regedit)
     and browse to key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\<your service name>

4. a sub key(folder) named "Parameters"

5. In this sub key will add 3 string values  named "Application" ,"AppParameters" and "AppDirectory".
     The application wil get a value of the ruby binary e.g.: C:\Ruby193\bin\ruby.exe
     The appParameters will get the the path the script/rails from your rails app including all the startup parameters you want to give it (used forward slashes here)
     for example:  c:/dev/rails/myrailsapp/script/rails server -b 127.0.0.1 -p 8080 -e development
     The appDirectory will contain the root of your rails application.e.g:  c:\dev\rails\myrailsapp\   (note uses backslashes again)

6. No restart is needed so you can now start your service and it should work (don't forget to have a little     patience for a rails app to start)


if you still have some trouble you can debug the svrany.exe . you can always change the registry parameters without a reboot needed .
There is a nice explenation from microsoft on this http://support.microsoft.com/kb/152460
Tip: if you want to debug with an application that is visible on the desktop, then:
  • open the service you created 
  • go to the "log On" tab  and check "Allow service to interact with desktop"

Hope this worked for you,

Maarten Bos

Geen opmerkingen:

Een reactie plaatsen