Merge "base: remove redudant ip_to_convert"
[yardstick.git] / yardstick / benchmark / scenarios / availability / ha_tools / start_lxc_service.bash
1 #!/bin/bash
2
3 ##############################################################################
4 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11
12 # Start a service and check the service is started
13
14 set -e
15
16 NOVA_API_SERVICE_1="nova-api-os-compute"
17 NOVA_API_SERVICE_2="nova-api-metadata"
18 NOVA_API_LXC_FILTER_1="nova_api_os_compute"
19 NOVA_API_LXC_FILTER_2="nova_api_metadata"
20
21 service_name=$1
22
23 if [ "${service_name}" = "haproxy" ]; then
24     if which systemctl 2>/dev/null; then
25         systemctl start $service_name
26     else
27         service $service_name start
28     fi
29 else
30     lxc_filter=${service_name//-/_}
31
32     if [ "${lxc_filter}" = "glance_api" ]; then
33         lxc_filter="glance"
34     fi
35
36     if [ "${service_name}" = "nova-api" ]; then
37         container_1=$(lxc-ls -1 --filter="${NOVA_API_LXC_FILTER_1}")
38         container_2=$(lxc-ls -1 --filter="${NOVA_API_LXC_FILTER_2}")
39
40         if lxc-attach -n "${container_1}" -- which systemctl 2>/dev/null; then
41             lxc-attach -n "${container_1}" -- systemctl start "${NOVA_API_SERVICE_1}"
42         else
43             lxc-attach -n "${container_1}" -- service "${NOVA_API_SERVICE_1}" start
44         fi
45
46         if lxc-attach -n "${container_2}" -- which systemctl 2>/dev/null; then
47             lxc-attach -n "${container_2}" -- systemctl start "${NOVA_API_SERVICE_2}"
48         else
49             lxc-attach -n "${container_2}" -- service "${NOVA_API_SERVICE_2}" start
50         fi
51     else
52         container=$(lxc-ls -1 --filter="${lxc_filter}")
53
54         Distributor=$(lxc-attach -n "${container}" -- lsb_release -a | grep "Distributor ID" | awk '{print $3}')
55
56         if [ "${Distributor}" != "Ubuntu" -a "${service_name}" != "keystone" -a "${service_name}" != "neutron-server" ]; then
57             service_name="openstack-"${service_name}
58         elif [ "${Distributor}" = "Ubuntu" -a "${service_name}" = "keystone" ]; then
59             service_name="apache2"
60         elif [ "${service_name}" = "keystone" ]; then
61             service_name="httpd"
62         fi
63
64         if lxc-attach -n "${container}" -- which systemctl 2>/dev/null; then
65             lxc-attach -n "${container}" -- systemctl start "${service_name}"
66         else
67             lxc-attach -n "${container}" -- service "${service_name}" start
68         fi
69     fi
70 fi