/service.js

http://github.com/OpenRTMFP/ArcusNode · JavaScript · 78 lines · 49 code · 7 blank · 22 comment · 2 complexity · 55402377f20b1aa2f1701d34ceb9b65b MD5 · raw file

  1. /**
  2. * ArcusNode Service
  3. *
  4. * Copyright 2011 OpenRTMFP
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License received along this program for more
  15. * details (or else see http://www.gnu.org/licenses/).
  16. *
  17. * Author: arcusdev <arcus.node@gmail.com>
  18. *
  19. * This file is a part of ArcusNode.
  20. */
  21. var util = require('util');
  22. var ArcusNode = require('./lib/arcus_node.js');
  23. //Take command line arguments
  24. var settings = {};
  25. process.argv.forEach(function (val, index, array) {
  26. if(index < 2)
  27. return;
  28. var valArr = val.split('=');
  29. switch(valArr[0]){
  30. case 'logLevel':
  31. settings.logLevel = valArr[1];
  32. util.print('Setting logLevel to ' + valArr[1] + '\n');
  33. break;
  34. case 'logFile':
  35. settings.logFile = valArr[1];
  36. util.print('Setting logFile to ' + valArr[1] + '\n');
  37. break;
  38. case '-h':
  39. case '-help':
  40. util.print(
  41. '### USAGE ###\n\n' +
  42. 'node service.js [argument1 argument2 ...]\n\n' +
  43. 'Arguments:\n' +
  44. 'logLevel=[level] [level] can be one of: fatal, error, warn, info, debug' +
  45. 'logFile=[path] [path] The path to a file to log output to' +
  46. '\n\n'
  47. );
  48. process.exit();
  49. break;
  50. default:
  51. util.print('Argument unknown or malformed: ' + val + '\nStopping process.');
  52. process.exit();
  53. }
  54. });
  55. //Startup
  56. util.print(
  57. 'Starting up ArcusNode RTMFP Service.\nCopyright (C) 2011 OpenRTMFP \n' +
  58. 'This program comes with ABSOLUTELY NO WARRANTY.\n' +
  59. 'This is free software, and you are welcome to redistribute it under certain conditions.\n' +
  60. '(For usage help type "node service.js -h")\n'
  61. );
  62. var arc = new ArcusNode(settings);
  63. arc.run();
  64. process.on('SIGINT', function () {
  65. util.print('\033[36mArcusNode shutting down...\033[0m\n');
  66. arc.stop();
  67. });
  68. process.on('exit', function(){
  69. util.print('\033[36mArcusNode stopped.\033[0m\n');
  70. });
  71. util.print('ArcusNode RTMFP Service running at ' + arc.address.address + ((arc.address.port != '') ? ':' + arc.address.port : '') + '\n');