Merge "Yardstick GUI & GUI deployment"
[yardstick.git] / yardstick / benchmark / scenarios / availability / ha_tools / fault_lxc_process_kill.bash
1 #!/bin/sh
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 # Stop process by process name
13
14 set -e
15
16 NOVA_API_PROCESS_1="nova-api-os-compute"
17 NOVA_API_PROCESS_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 process_name=$1
22
23 lxc_filter=$(echo "${process_name}" | sed 's/-/_/g')
24
25 if [ "${lxc_filter}" = "glance_api" ]; then
26     lxc_filter="glance"
27 fi
28
29 if [ "${process_name}" = "nova-api" ]; then
30     container_1=$(lxc-ls -1 --filter="${NOVA_API_LXC_FILTER_1}")
31     container_2=$(lxc-ls -1 --filter="${NOVA_API_LXC_FILTER_2}")
32
33     pids_1=$(lxc-attach -n "${container_1}" -- pgrep -f "/openstack/.*/${NOVA_API_PROCESS_1}")
34     for pid in ${pids_1};
35         do
36             lxc-attach -n "${container_1}" -- kill -9 "${pid}"
37         done
38
39     pids_2=$(lxc-attach -n "${container_2}" -- pgrep -f "/openstack/.*/${NOVA_API_PROCESS_2}")
40     for pid in ${pids_2};
41         do
42             lxc-attach -n "${container_2}" -- kill -9 "${pid}"
43         done
44 else
45     container=$(lxc-ls -1 --filter="${lxc_filter}")
46
47     if [ "${process_name}" = "haproxy" ]; then
48         for pid in $(pgrep -cf "/usr/.*/${process_name}");
49             do
50                 kill -9 "${pid}"
51             done
52     elif [ "${process_name}" = "keystone" ]; then
53         pids=$(lxc-attach -n "${container}" -- ps aux | grep "keystone" | grep -iv heartbeat | grep -iv monitor | grep -v grep | grep -v /bin/sh | awk '{print $2}')
54         for pid in ${pids};
55             do
56                 lxc-attach -n "${container}" -- kill -9 "${pid}"
57             done
58     else
59         pids=$(lxc-attach -n "${container}" -- pgrep -f "/openstack/.*/${process_name}")
60         for pid in ${pids};
61             do
62                 lxc-attach -n "${container}" -- kill -9 "${pid}"
63             done
64     fi
65 fi