[SOLVED] How to shutdown Meteor from `Server Code`?


I’ve switched to needing to load a settings file every time I run meteor - so now, I’m always using “npm start” to run my project.

However, one could still run the server using “meteor” - which breaks my application things just won’t run right.

I’d like to be able to put a check before I start using the settings from the file to say “Hey, if you didn’t npm start, you need to…” and then actually shutdown meteor from the server code. I can’t find any code that does this!?

I’m looking for something like Meteor.shutdown() or Meteor.exit()

Does anyone know how to this?

Alternatively, maybe I could just detect that the settings file wasn’t loaded, and then run some command to attempt to load the settings file? Anyone have suggestions here?



process.exit() should do the trick, never tested it myself: https://nodejs.org/api/process.html


Thanks @nlammertyn,

Here’s what happened. I used this code:

if (Meteor.settings.private === undefined) {
  console.log("You didn't start meteor by using the command \"npm start\".")
  console.log("Please quit meteor and start again using: npm start")

and I get the following output:

I20161101-17:47:02.006(-4)? Meteor.settings.private undefined
I20161101-17:47:02.006(-4)? You didn't start meteor by using the command "npm start".
I20161101-17:47:02.006(-4)? oAuth settings will not be loaded.
I20161101-17:47:02.006(-4)? Please quit meteor and start again using: npm start
=> Exited with code: 1                        
=> Your application is crashing. Waiting for file change.

I chose exit code 1 from reading this page: https://nodejs.org/api/process.html#process_process_kill_pid_signal

If you leave empty like so: process.exit() you get exit code 0 and then meteor tries to restart three times before it stops trying. Using process.exit(1) causes Meteor to just wait for your code to change. EDIT: Either code will cause Meteor to retry three times.

Does anyone know of a way to totally kill meteor and go back to the command line? Using process.kill(process.pid, 'SIGHUP') actually causes the server to “reset” and load all over again.

The nicest solution to this would be able to manually load the settings file, but I figured quitting and warning the user would be the next best solution.

Any more help would be greatly appreciated!