Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to run my ruby web server as a Windows XP service.

Somebody can advice how to do that?


I changed (removed the word ruby) the title so more people can find the answer. It will work for any kind of script.

share|improve this question

1 Answer 1

up vote 5 down vote accepted

I am editing a document I created and published to the web for another difficult problem, and adapting it to your question. I cannot be 100% sure that the Resource Kit tools will work with XP, but I believe they probably will.

1) Create a batch file to run your script and start your Ruby server. To be frank, I don't have enough info to tell you how to do that. Copy the batch file to a safe place like c:\windows\system32

2) Download the Windows 2003 Resource kit and install it to a directory with NO spaces, not the default in “C:\Program Files”. Use C:\RESOURCEKIT, as I will use it for the rest of the document. This is very important for some programs, which don't understand the space in “C:\Program Files”, but not for others...to be safe, put it here.

3) Open a command prompt, and change to the directory where you installed the Windows 2003 resource kit, in this case, C:\RESOURCEKIT.

4) From that directory, install the script as a service with the following command “instsrv YourServiceName C:\RESOURCEKIT\srvany.exe.” without the quotes around it. You can name the service any reasonably not-too-long name you like, and this will appear in the Services.msc. This should return “The service was successfully added!” Next we have to configure the new YourServiceName service.

5) Open the Registry editor to the [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\YourServiceName] key.

6) Right-click on the YourServiceName key and do “New>Key” and name it Parameters (case sensitive).

7) Expand the new Parameters key and in the right pane right-click and do “New>String Value” and name it Application (case sensitive).

8) Double-click your new “Application” key and enter c:\windows\system32\YourBatchFileName.bat and save it. The service is now ready to run.

9) Test run it from within the Control Panel>Administrator Tools>Services MMC. You will see the service YourServiceName now listed and you can start it.

Here is a copy of my original article: http://www.eggheadcafe.com/microsoft/Windows-Server-Networking/30399980/solution-to-have-a-persistent-vpn-start-automatically-on-boot.aspx

share|improve this answer
    
Works like a charm. Thank you. Pity I cannot up vote 100x ... –  Radek Jun 24 '11 at 4:35
    
Stopping the service doesn't stop the web server. Can I make it work somehow so the web stops when the service is not running? –  Radek Jun 24 '11 at 4:54
    
@Radek Probably not unless you can program your script to not only start but stop it conditionally. I have never tired it, but if you put conditions in the script to check and see if were stopped, then run the start portion of the script, and if running, then stop it. That issue is common with these types of ad-hock services. –  KCotreau Jun 24 '11 at 4:59
    
In the alternative, you could just create a stop batch file and put it somewhere convenient, like the quick launch, for times you want to stop it in the middle of a session. If you are running XP pro, you could go into gpedit.msc, and you could also put the stop batch file in the system shutdown scripts, so it terminates cleanly on system shutdown. –  KCotreau Jun 24 '11 at 5:01
    
I can use taskkill /f /t /im ruby.exe to stop the server but I do not know how to implement it in relation to to stopping the server from MMC. Do you know what the stop service do? does it run the service again with some parameter or so? –  Radek Jun 24 '11 at 5:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.