Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a vps running Windows Server 2008 R2.

I have an executable which always needs to be running. Even if I am not logged in.

Say there is a problem and the server is restarted unexpectedly, I should not have to login for it to start. Is there some way to do this?

In addition, I don't think this could be done but, say the application crashes, is there a way to make the OS close the crashed executable and restart it?

In addition, when I do login as administrator, if I could see it running, that would be awesome too. (wg: visible console window)

Thanks

share|improve this question
2  
which executable is that? maybe you want to wrap it into "service" –  alexus Dec 14 '13 at 15:45
    
@alexus It is the server exe for my game. It's a console application. –  Milo Dec 14 '13 at 15:51
2  
If you created the application then create a Windows Service instead of a console application to host it. You can then create a console application to get connected with the service and se any information you want. –  Peter Kiss Dec 14 '13 at 15:56

1 Answer 1

Since it's your game, meaning you own the code, then that means that you need to rewrite it as a Windows Service. Servers are made to run services. Windows Services are designed to run without user interaction, regardless of whether anyone is logged on or not, and can be started automatically when the machine boots. (Just set your service to Automatic and it starts right after the OS loads.) In addition, you can define advanced recovery options in the service controller, to have Windows automatically restart the service for you if it crashes, or even send you an email notifying you that your service has crashed if you were so inclined.

Recovery Options

You do not interact directly with a Windows Service. Windows Services have no user interface and they don't create a window on a desktop. (They shouldn't.) You will not see a console window for it when you log on. However, you can write a separate application that can interface with your service, to allow a user to configure settings or perform administrative functions on your service. Your administrative application might be used to set and read registry entries or configuration file settings that your service uses, etc.

Basically, anything else that you do besides what I just described above is doing it wrong(TM), IMHO.

But for the sake of completeness, let's explore some of the ways in which you can do it wrong, but could still technically accomplish what you want.

Say there is a problem and the server is restarted unexpectedly, I should not have to login for it to start. Is there some way to do this?

Sure. Make the executable run at startup by putting it in HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run. (Sorry that is for user login.) Or put it in a Scheduled Task that is configured to run at system startup. (Of course if you go the Windows Service route it's simply a matter of setting your service to Automatic in the Service Controller.)

say the application crashes, is there a way to make the OS close the crashed executable and restart it?

This does not make sense. If the process is still running, then it did not crash. If it hung because of something that you did wrong in your code, e.g., lack of exception handling, that is just something you need to fix in your code.

On the other hand, if you wanted to run a script every 5 minutes (through Task Scheduler) that checked if FunGame.exe was running or not, and start it if it wasn't running, then you're free to do so... though I would hate you if you ran something like that on one of my servers.

In addition, when I do login as administrator, if I could see it running, that would be awesome too. (wg: visible console window)

Not going to happen - unless you take my advice about making a separate application that was specifically designed to be an admin/monitoring interface into your service, then you could stick that application in the Administrator's startup folder, etc.

Oh and one last thing... there is also srvany.exe ... it's old and unsupported, but you may want to look into it as a generic service host if you're not going to make your own service.

share|improve this answer

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.