#!/usr/bin/env python3 import os import platform import subprocess from sys import stderr, exit def ctrl_c_catch(proc): print("Ctrl-c caught") print("\nKilling process...") proc.kill() print("Exiting...") exit(0) def main(): if platform.system() == 'Darwin': p = os.system("brew services list | grep \"rabbitmq started\"") if (p != 0): print("RabbitMQ is not started", file=stderr) return False else: print("RabbitMQ started: OK") elif platform.system() == "Linux": output = subprocess.getoutput("ps -A") if "rabbitmq-server" in output: print("RabbitMQ started: OK") else: print("RabbitMQ is not started", file=stderr) return False os.chdir('..') try: process = subprocess.Popen("celery -A pyros worker -Q monitoring_q -n pyros@monitoring -c 1", shell=True) process.wait() print("Celery worker stopped") exit(0) except KeyboardInterrupt: ctrl_c_catch(process) return True if __name__ == '__main__': main()