forked from accelazh/ceph-allinone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.sh
executable file
·103 lines (88 loc) · 2.14 KB
/
functions.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
######################################
# Shared functions used across other scipts
######################################
BASEDIR=$(dirname $0)
. ${BASEDIR}/file_path.sh
function common_init(){
# print command trace while executing
set -x
}
# kill -9 all ceph process
function kill_ceph(){
for pid in $(ps -ef | grep ceph | awk '{print $2}'); do
if [ $pid != $$ ]; then
echo "killing process $pid ..."
sudo kill $pid > /dev/null 2>&1
fi
done
}
# kill -9 all ceph monitor process.
# WARNING: kill may cause mon not to finish properly
function kill_mon(){
for pid in $(ps -ef | grep ceph-mon | awk '{print $2}'); do
if [ $pid != $$ ]; then
echo "killing process $pid ..."
sudo kill $pid > /dev/null 2>&1
fi
done
}
# kill -9 all ceph monitor process
# WARNING: kill may cause osd not to finish properly
function kill_osd(){
for pid in $(ps -ef | grep ceph-osd | awk '{print $2}'); do
if [ $pid != $$ ]; then
echo "killing process $pid ..."
sudo kill $pid > /dev/null 2>&1
fi
done
}
function has_log_error(){
err_str="$(grep -ir error ${CEPH_LOG_FOLDER})"
exclude_err_str="$(grep -ir '\.connect error' ${CEPH_LOG_FOLDER})"
if [ -n "$err_str" -a "$err_str" != "$exclude_err_str" ]; then
echo 1
else
echo 0
fi
}
# remove all ceph config files
function purge_ceph_config(){
sudo rm -rf $CONF_FOLDER
}
# remove all ceph data files
function purge_ceph_data(){
sudo rm -rf $TMP_MON_MAP
sudo rm -rf $TMP_MON_KEYRING
sudo rm -rf $VAR_RUN_CEPH
sudo rm -rf $VAR_LIB_CEPH
}
# remove all ceph log
function purge_ceph_log(){
sudo rm -rf $CEPH_LOG_FOLDER
}
# pass into mon name, return mon log file path
function get_mon_log_file(){
echo -n ${CEPH_LOG_FOLDER}/${cluster_name}-mon.${1}.log
}
# pass into osd id, return osd log file path
function get_osd_log_file(){
echo -n ${CEPH_LOG_FOLDER}/${cluster_name}-osd.${1}.log
}
# pass into "a b c", return "a, b, c"
function list_add_comma(){
arr=($1)
last_pos=$(( ${#arr[*]} - 1 ))
ret=""
pos=0
for e in "${arr[@]}"; do
if [[ $pos == $last_pos ]]; then
ret="${ret} $e"
else
ret="${ret} $e,"
fi
pos=$(( $pos + 1 ))
done
echo -n "$ret"
return 0
}