start_celery_worker.py
1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/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()