Advertisement
Guest User

Untitled

a guest
Jan 7th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. var forever = require('forever-monitor');
  2. var mysql = require('mysql');
  3.  
  4. var pool = mysql.createPool({
  5. connectionLimit : 10,
  6. database: 'csgo',
  7. host: 'localhost',
  8. user: 'root',
  9. password: '-9aB,hz9oChNk_C3'
  10. });
  11.  
  12. query('SELECT * FROM `bots`', function(err, row) {
  13. if((err) || (!row.length)) {
  14. console.log('Failed request or empty bot table');
  15. console.log(err);
  16. return process.exit(0);
  17. }
  18. console.log('List of bots:');
  19. row.forEach(function(itm) {
  20. console.log('Launching bot# '+itm.id);
  21. var bot = new (forever.Monitor)('bot.js', {
  22. args: [itm.id]
  23. });
  24. bot.on('start', function(process, data) {
  25. console.log('Bot with ID '+itm.id+' started');
  26. });
  27. bot.on('exit:code', function(code) {
  28. console.log('Bot stopped with code '+code);
  29. });
  30. bot.on('stdout', function(data) {
  31. console.log(data);
  32. });
  33. bot.start();
  34. });
  35. });
  36.  
  37. function query(sql, callback) {
  38. if (typeof callback === 'undefined') {
  39. callback = function() {};
  40. }
  41. pool.getConnection(function(err, connection) {
  42. if(err) return callback(err);
  43. console.info('Database connection ID: '+connection.threadId);
  44. connection.query(sql, function(err, rows) {
  45. if(err) return callback(err);
  46. connection.release();
  47. return callback(null, rows);
  48. });
  49. });
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement