How to programatically restart server?

In some cases we need to restart server programatically. We use exit(0) to do this.
In a production environment it works perfectly and the server is restarted by docker or systemd.

The question is - is it possible to do this in development environment? In the most cases there is an error:

=> Exited with code: 0
=> Your application is crashing. Waiting for file change.

After that sometimes the server is restarted but in the most cases not.

Is there any solution how to have the server restarted automatically without changing files?

Meteor used to automatically restart the server, but it was removed at some point since it was rarely useful if the server crashed when starting. I’ve been considering re-adding this behavior, with the difference that it only restarts the server if it crashes after the server started.

I’m intrigued, what’s the use case for this in production? Where you want the server to come back up after killing? Is it to handle resource issues?

If a config file is changed the restart of the server is required. There are 2 main reasons why we want to have possibility to restart server in the development environment:

  1. when you start meteor with meteor run it takes much longer than automatic restart
  2. we have a development server in our company with cron that do a git pull if there are any changes. if we restart the server programatically we have to ssh into the server and restart meteor.

I think it should be safe to restart the server if it exits with code 0. Though it should be customizable as some wants to exit process, while others want to restart it. Alternatively, I would be happy to have Meteor.restart() or something.

I was curious as well.

Why these settings only take effect when the server starts again?

There are few reasons. For example, we have been using node-config module. It doesn’t offer auto-reload feature. We keep there settings that usually users don’t change or change just once.

Finally, we decided to use rather bold approach to restart server under dev-environment - we create a temporary js-file and remove it on start… This is far from elegant but works… )