I'm working on a Meteor app (a port from a PHP project) and I need to be able to run commands on my app from the server for various operations like clearing caches, aggregating data, etc. These commands need to be run from shell scripts and crontab. I've seen other people ask this question and apparently there's no official way to do it yet.
I read a suggestion of using Meteor methods and just calling them from the client's JS console with a password. This doesn't solve my problem of running them from the CLI, but it did give me an idea:
Would it be possible to use a headless browser (like PhantomJS) to connect to my app and execute Meteor.call() to simulate a CLI tool with arguments passed to the method? If possible, does anyone know how I might accomplish this?
Thanks!
EDIT: Updated to use Iron Router, the successor to Meteor Router.
There's no need for a headless browser or anything complicated. Use Meteorite to install Iron Router and define a server-side route:
Router.map(function () {
this.route('clearCache', {
where: 'server',
action: function () {
// Your cache-clearing code goes here.
}
});
});
Then have your cronjob trigger an HTTP GET request to that URI:
curl http://yoursite.com/clearCache
When the Meteor server receives the GET request, the router will execute your code.
For a little bit of security, add a check for a password:
Router.map(function () {
this.route('clearCache', {
path: '/clearCache/:password',
where: 'server',
action: function () {
if (this.params.password == '2d1QZuK3R3a7fe46FX8huj517juvzciem73') {
// Your cache-clearing code goes here.
}
}
});
});
And have your cronjob add that password to the URI:
curl http://yoursite.com/clearCache/2d1QZuK3R3a7fe46FX8huj517juvzciem73
Original Post:
There's no need for a headless browser or anything complicated. Use Meteorite to install Meteor Router and define a server-side route:
Meteor.Router.add('/clearCache', function() {
// Your cache-clearing code goes here.
});
Then have your cronjob trigger an HTTP GET request to that URI:
curl http://yoursite.com/clearCache
When the Meteor server receives the GET request, the router will execute your code.
For a little bit of security, add a check for a password:
Meteor.Router.add('/clearCache/:password', function(password) {
if (password == '2d1QZuK3R3a7fe46FX8huj517juvzciem73') {
// Your cache-clearing code goes here.
}
});
And have your cronjob add that password to the URI:
curl http://yoursite.com/clearCache/2d1QZuK3R3a7fe46FX8huj517juvzciem73
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With