check in openstack db cleanup tool
[plstackapi.git] / planetstack / tools / openstack-healthcheck.py
1 #! /usr/bin/python
2 import os
3 import sys
4 import subprocess
5 import time
6
7 def get_systemd_status(service):
8     p=subprocess.Popen(["/bin/systemctl", "is-active", service], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
9     (out, err) = p.communicate()
10     out = out.strip()
11     return out
12
13 libvirt_enabled = os.system("systemctl -q is-enabled libvirtd.service")==0
14 nova_compute_enabled = os.system("systemctl -q is-enabled openstack-nova-compute.service")==0
15 openvswitch_agent_enabled = os.system("systemctl -q is-enabled quantum-openvswitch-agent.service")==0
16
17 print "enabled:"
18 print "  libvirtd=", libvirt_enabled
19 print "  openstack-nova-compute=", nova_compute_enabled
20 print "  quantum-openvswitch-agent=", openvswitch_agent_enabled
21
22 if (not libvirt_enabled) or (not nova_compute_enabled) or (not openvswitch_agent_enabled):
23     print "services are not enabled. exiting"
24     sys.exit(0)
25
26 libvirt_status = get_systemd_status("libvirtd.service")
27 nova_compute_status = get_systemd_status("openstack-nova-compute.service")
28 openvswitch_agent_status = get_systemd_status("quantum-openvswitch-agent.service")
29
30 print "status:"
31 print "  libvirtd=", libvirt_status
32 print "  openstack-nova-compute=", nova_compute_status
33 print "  quantum-openvswitch-agent=", openvswitch_agent_status
34
35 if (libvirt_status=="failed") or (nova_compute_status=="failed") or (openvswitch_agent_status=="failed"):
36     print "services have failed. doing the big restart"
37     os.system("systemctl stop openstack-nova-compute.service")
38     os.system("systemctl stop quantum-openvswitch-agent.service")
39     os.system("systemctl stop libvirtd.service")
40     time.sleep(5)
41     os.system("systemctl start libvirtd.service")
42     time.sleep(5)
43     os.system("systemctl start quantum-openvswitch-agent.service")
44     time.sleep(5)
45     os.system("systemctl start openstack-nova-compute.service")
46     print "done"
47
48
49
50