0

I have an application (github's Hubot), that was built to run on Heroku - but I want to run it on our internal Windows 2012 server, for reasons.

One requirement of the solution, is I need to be able to read in a .env file filled with env vars before the process starts. It runs fine via foreman start, but it would be desirable to run it as a service that would restart if it crashes.

Currently I'm running it through RunAsService, but this doesn't really have the desired behavior, as it doesn't restart the actual process if it fails. This could perhaps be due to my configuration (listed below), but there doesn't seem to be any other way to run it.

Since this is just a development server, I'm not too concerned about best practices - I just don't want to log into the box every time the bot goes down.

Am I going to have to write my own service, or is there a simpler way? Another answer mentioned using env along with nodemon, but AFAIK this is *nix-centric. Does Windows have a similar method for reading in environment variables?

<service>
  <name>hubot</name>
  <executable>C:\Ruby200-x64\bin\foreman</executable>
  <parameters>start -d C:\node\hubot</parameters>
</service>
Community
  • 1
  • 1
Jon Jaques
  • 4,262
  • 2
  • 23
  • 25

1 Answers1

0

Any service can be configured to restart on failure, it is the Service Configuration Manager job to handle this, not the service itself. So a RunAsService service should restart just as any other service. Use sc.exe failure:

c:\>sc failure hubot reset= 60 actions= restart/500

Note that you can also start and stop the bot remotely, using the same sc.exe, no need to log onto it:

c:\>sc <hostname> start hubot

But to tell you the truth, writing a service is fairly trivial, there are wizards to get the template going in C# or in C++ from Visual Studio. Then you would be lord of the manor, master of your own domain etc etc.

Remus Rusanu
  • 288,378
  • 40
  • 442
  • 569