So i am developing and deploying Ruby on Rails applications on Windows. Recently i started experimenting with the newer versions of ruby (mingw32 platform).
One of the side-effects is that the mongrel-service, which i always used to deploy my rails-applications no longer works on mingw32.
And aside of that, i have read on various instances [ref] that thin should be better (more efficient) than mongrel. But i still want to install it as a service.
First off, you need to download and install the Windows Resource Kit. This contains the executables to make a service of any executable or script.
Then create the service running (in the console):
C:\Program Files\Windows Resource Kits\Tools> instsrv "[my_service_name]" "c:\program files\Windows Resource Kits\Tools\srvany.exe" The service was successfuly added! Make sure that you go into the Control Panel and use the Services applet to change the Account Name and Password that this newly installed service will use for its Security Context.
This will add an empty entry in the registry, which actually still does nothing. To get it working, we have to start
regedit, and navigate to the following registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\[my_service_name]
Create a new key (folder) named
Parameters. This will contain the settings of our actual application that will be run as a service. Add the following String Values:
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\[my_service_name]\Parameters] Application=c:\ruby\bin\ruby.exe AppDirectory=[my_ruby_app_folder] AppParameters=c:\ruby\bin\thin start -p 4000 -e production
Assuming that c:\ruby\bin is your ruby folder, and you want your thin to listen to port 4000.
Once that is done, start the service, and your rails application should be up and running :)
… but Windows Server 2008
Unfortunately, to do this on Windows 2008 you need to perform some extra steps. As you can’t install the resource kit on Windows Server 2008R2 for some peculiar reason, and at the time of this posting, i have not found a Windows Server 2008 Resource Kit Tools, so i took the following steps:
- copy the “srvany.exe ” from the “Windows Server 2003 Resource Kit Tools ” to a suitable location on your Win2008 server (e.g. C:\Windows\System32\ )
- use “sc ” to create a new service that launches “srvany ” (e.g. sc create MyService binPath= C:\Windows\System32\srvany.exe DisplayName= “My Custom Service” )
- using RegEdit create a “Parameters ” key for your service as before and fill it with the 3 string values
A bit more work, but not too much.
And just today I discovered an update of mongrel_service was announced, so you can still work using mongrel_service instead of using thin and manually creating the service.
What you need to do:
- install mongrel service: gem install mongrel_service –prerelease
- create the service as before:
mongrel_rails service::install -N myapp -c c:\my\path\to\myapp -p 4000 -e production
That is much easier of course.