Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restart Meteor server from within Meteor.js

A project I've made with Meteor has a memory leak that slowly accumulates over the course of a month or two. After sinking days into finding the leak, I'm throwing in the towel in favor of just adding an auto-restart that happens once a month. Yes this is bad practice, etc.

Is there a way to simply restart from within the server's codebase? Ideally this will also trigger a refresh for connected clients (similar to regular deployment updates).

Then I assume this command could just be nested in a good old JS timeout function.

like image 223
miketucker Avatar asked Sep 22 '14 08:09

miketucker


People also ask

How do I reset my meteor server?

You can also use the sudo killall -9 node command to stop all meteor projects and then meteor to start the one you want in your folder of choice.

How do I stop Meteor JS?

On OSX, go back to the term you opened to start meteor, and use CTRL + C to quit the process.

How do I run a meteor server?

meteor run You can use the application by pointing your web browser at localhost:3000. No Internet connection is required. This is the default command. Simply running meteor is the same as meteor run .

How does meteor JS work?

Meteor uses data on the wire, meaning the server sends data, not HTML, and the client renders it. Meteor embraces the ecosystem, bringing the best parts of the extremely active JavaScript community to you in a careful and considered way.


1 Answers

The answer provided by apendua worked. It's a total hack, and not recommended for most cases, but great for long-term memory leaks.

Put this inside your startup script:

var restartFrequency = 1000 * 60 * 24; // 1 day (1000 millsec * 60 min * 24 hour)
setTimeout(function(){
  process.exit();
}, restartFrequency);
like image 128
miketucker Avatar answered Sep 28 '22 21:09

miketucker