subs.py 782 B

12345678910111213141516171819202122232425262728293031
  1. # -*- coding: utf-8 -*-
  2. """
  3. demeter web
  4. name:sub.py
  5. author:rabin
  6. """
  7. import time
  8. from demeter.core import *
  9. from demeter.mqtt import *
  10. timeSleep = 1000
  11. import random
  12. class Subs(object):
  13. def run(self):
  14. self.handle()
  15. time.sleep(timeSleep)
  16. def handle(self):
  17. topic = Demeter.config['mqtt']['sub'].split('|')
  18. if topic:
  19. mqtt = Demeter.path + 'mqtt.py'
  20. for v in topic:
  21. command = 'python3 ' + mqtt + ' -m sub -t ' + v
  22. check = "ps aux|grep '"+command+"'|grep -v entrypoint|grep -v grep|grep -v process|awk '{print $1}'"
  23. check = Shell.popen(check)
  24. if not check:
  25. Shell.popen(command)
  26. def load(self, topic):
  27. Sub(topic)