You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dedaemon.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env node
  2. var syscheck = require("./js/syscheck");
  3. var parseConf = require("./js/parse-conf");
  4. var async = require("./js/async");
  5. var modules = {
  6. // display: require("./modules/display"),
  7. input: require("./modules/input"),
  8. wallpaper: require("./modules/wallpaper"),
  9. process: require("./modules/process"),
  10. };
  11. if (!process.argv[2]) {
  12. console.log("Usage:", process.argv[1], "<config>");
  13. process.exit(1);
  14. }
  15. var config = parseConf(process.argv[2]);
  16. function createLogger(name) {
  17. function log(pre, msg) {
  18. console.error(pre+msg.join(" "));
  19. }
  20. return {
  21. info: (...msg) => log(name+": INFO: ", msg),
  22. warn: (...msg) => log(name+": WARNING: ", msg),
  23. error: (...msg) => log(name+": ERROR: ", msg),
  24. }
  25. }
  26. function startAll() {
  27. Object.keys(modules).forEach(i => {
  28. var mod = modules[i];
  29. var conf = config[i] || {};
  30. if (conf instanceof Array && conf.length === 0)
  31. return;
  32. mod.start(conf, createLogger(i), modules);
  33. });
  34. }
  35. function stopAll(cb) {
  36. var keys = Object.keys(modules);
  37. var next = async(keys.length, cb);
  38. keys.forEach(i => modules[i].stop(next));
  39. }
  40. function onTerm() {
  41. stopAll(() => process.exit(1));
  42. }
  43. syscheck(ok => {
  44. if (ok)
  45. startAll();
  46. else
  47. console.error("Missing binaries, exiting.");
  48. });
  49. process.on("SIGTERM", onTerm);
  50. process.on("SIGINT", onTerm);