Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var COMMAND_TO_WATCH = '/home/ec2-user/check.sh 80';
- var POLL_INTERVAL = 1000;
- var USER = "user";
- var PASS = "pass";
- var output = new Meteor.Collection('output');
- output.remove({});
- var id = output.insert({value:'Waiting for data...'})._id;
- if (Meteor.is_client) {
- Meteor.startup(function() {
- Meteor.autosubscribe(function() {
- Session.set('exec_output', output.findOne({}).value);
- });
- document.body.appendChild(Meteor.ui.render(function() {
- Template.exec_output.exec_output = Session.get('exec_output');
- return Template.exec_output();
- }));
- });
- }
- if (Meteor.is_server) {
- var require = __meteor_bootstrap__.require;
- var sys = require('sys');
- var exec = require('child_process').exec;
- var connect = require('connect');
- var shimAuth = function() {
- __meteor_bootstrap__.app.stack.unshift({
- route: '', handle: connect.basicAuth(USER, PASS)
- });
- };
- var updateStoredValue = function (error, stdout, stderr) {
- Fiber(function() {
- output.update({value:{$exists:true}}, {value: stdout + stderr});
- }).run();
- };
- var pollCommand = function() {
- exec(COMMAND_TO_WATCH, updateStoredValue);
- };
- Meteor.startup(shimAuth);
- Meteor.setInterval(pollCommand, POLL_INTERVAL);
- }
Add Comment
Please, Sign In to add comment