Guest User

Untitled

a guest
Jul 28th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. var COMMAND_TO_WATCH = '/home/ec2-user/check.sh 80';
  3. var POLL_INTERVAL = 1000;
  4. var USER = "user";
  5. var PASS = "pass";
  6. var output = new Meteor.Collection('output');
  7. output.remove({});
  8. var id = output.insert({value:'Waiting for data...'})._id;
  9.  
  10. if (Meteor.is_client) {
  11.     Meteor.startup(function() {
  12.         Meteor.autosubscribe(function() {
  13.             Session.set('exec_output', output.findOne({}).value);
  14.         });
  15.  
  16.         document.body.appendChild(Meteor.ui.render(function() {
  17.             Template.exec_output.exec_output = Session.get('exec_output');
  18.             return Template.exec_output();
  19.         }));
  20.     });
  21. }
  22.  
  23. if (Meteor.is_server) {
  24.     var require = __meteor_bootstrap__.require;
  25.     var sys = require('sys');
  26.     var exec = require('child_process').exec;
  27.     var connect = require('connect');
  28.  
  29.     var shimAuth = function() {
  30.         __meteor_bootstrap__.app.stack.unshift({
  31.             route: '', handle: connect.basicAuth(USER, PASS)
  32.         });
  33.     };
  34.  
  35.     var updateStoredValue = function (error, stdout, stderr) {
  36.         Fiber(function() {
  37.             output.update({value:{$exists:true}}, {value: stdout + stderr});
  38.         }).run();
  39.     };
  40.  
  41.     var pollCommand = function() {
  42.         exec(COMMAND_TO_WATCH, updateStoredValue);
  43.     };
  44.  
  45.     Meteor.startup(shimAuth);
  46.     Meteor.setInterval(pollCommand, POLL_INTERVAL);
  47. }
Add Comment
Please, Sign In to add comment