S.Çağlar Onur | 3e92b4d | 2015-02-09 13:34:11 -0500 | [diff] [blame] | 1 | #! /usr/bin/env python |
Scott Baker | bc640cf | 2013-09-07 17:42:50 -0700 | [diff] [blame] | 2 | |
| 3 | """ |
| 4 | Check the status of libvirt, openstack-nova-compute, and |
| 5 | quantum-openvswitch-agent. If these services are enabled and have failed, |
| 6 | then restart them. |
| 7 | """ |
| 8 | |
Scott Baker | 3262495 | 2013-09-07 17:38:22 -0700 | [diff] [blame] | 9 | import os |
| 10 | import sys |
| 11 | import subprocess |
| 12 | import time |
| 13 | |
| 14 | def get_systemd_status(service): |
| 15 | p=subprocess.Popen(["/bin/systemctl", "is-active", service], stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 16 | (out, err) = p.communicate() |
| 17 | out = out.strip() |
| 18 | return out |
| 19 | |
| 20 | libvirt_enabled = os.system("systemctl -q is-enabled libvirtd.service")==0 |
| 21 | nova_compute_enabled = os.system("systemctl -q is-enabled openstack-nova-compute.service")==0 |
| 22 | openvswitch_agent_enabled = os.system("systemctl -q is-enabled quantum-openvswitch-agent.service")==0 |
| 23 | |
| 24 | print "enabled:" |
| 25 | print " libvirtd=", libvirt_enabled |
| 26 | print " openstack-nova-compute=", nova_compute_enabled |
| 27 | print " quantum-openvswitch-agent=", openvswitch_agent_enabled |
| 28 | |
| 29 | if (not libvirt_enabled) or (not nova_compute_enabled) or (not openvswitch_agent_enabled): |
| 30 | print "services are not enabled. exiting" |
| 31 | sys.exit(0) |
| 32 | |
| 33 | libvirt_status = get_systemd_status("libvirtd.service") |
| 34 | nova_compute_status = get_systemd_status("openstack-nova-compute.service") |
| 35 | openvswitch_agent_status = get_systemd_status("quantum-openvswitch-agent.service") |
| 36 | |
| 37 | print "status:" |
| 38 | print " libvirtd=", libvirt_status |
| 39 | print " openstack-nova-compute=", nova_compute_status |
| 40 | print " quantum-openvswitch-agent=", openvswitch_agent_status |
| 41 | |
| 42 | if (libvirt_status=="failed") or (nova_compute_status=="failed") or (openvswitch_agent_status=="failed"): |
| 43 | print "services have failed. doing the big restart" |
| 44 | os.system("systemctl stop openstack-nova-compute.service") |
| 45 | os.system("systemctl stop quantum-openvswitch-agent.service") |
| 46 | os.system("systemctl stop libvirtd.service") |
| 47 | time.sleep(5) |
| 48 | os.system("systemctl start libvirtd.service") |
| 49 | time.sleep(5) |
| 50 | os.system("systemctl start quantum-openvswitch-agent.service") |
| 51 | time.sleep(5) |
| 52 | os.system("systemctl start openstack-nova-compute.service") |
| 53 | print "done" |
| 54 | |
| 55 | |
| 56 | |
| 57 | |