blob: 4b8a3f1612b3e98e90ae94c55a38cb0063d8e8eb [file] [log] [blame]
S.Çağlar Onura95895d2015-02-09 13:34:11 -05001#! /usr/bin/env python
Scott Bakerbc640cf2013-09-07 17:42:50 -07002
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 Baker32624952013-09-07 17:38:22 -07009import os
10import sys
11import subprocess
12import time
13
14def 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
20libvirt_enabled = os.system("systemctl -q is-enabled libvirtd.service")==0
21nova_compute_enabled = os.system("systemctl -q is-enabled openstack-nova-compute.service")==0
22openvswitch_agent_enabled = os.system("systemctl -q is-enabled quantum-openvswitch-agent.service")==0
23
24print "enabled:"
25print " libvirtd=", libvirt_enabled
26print " openstack-nova-compute=", nova_compute_enabled
27print " quantum-openvswitch-agent=", openvswitch_agent_enabled
28
29if (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
33libvirt_status = get_systemd_status("libvirtd.service")
34nova_compute_status = get_systemd_status("openstack-nova-compute.service")
35openvswitch_agent_status = get_systemd_status("quantum-openvswitch-agent.service")
36
37print "status:"
38print " libvirtd=", libvirt_status
39print " openstack-nova-compute=", nova_compute_status
40print " quantum-openvswitch-agent=", openvswitch_agent_status
41
42if (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