Blame view

src/monitoring/start_celery_worker.py 1.09 KB
64a7b593   Quentin Durand   creating start an...
1
2
3
4
5
6
7
8
9
#!/usr/bin/env python3

import os
import platform
import subprocess
from sys import stderr, exit


def ctrl_c_catch(proc):
678d4a06   Etienne Pallier   New (python, mult...
10
11
    print("Ctrl-c caught")
    print("\nKilling process...")
64a7b593   Quentin Durand   creating start an...
12
13
14
15
16
17
18
    proc.kill()
    print("Exiting...")
    exit(0)

def main():
    if platform.system() == 'Darwin':
        p = os.system("brew services list | grep \"rabbitmq started\"")
678d4a06   Etienne Pallier   New (python, mult...
19
        if (p != 0):
64a7b593   Quentin Durand   creating start an...
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
            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__':
678d4a06   Etienne Pallier   New (python, mult...
46
    main()