-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaliyunService.sh
57 lines (57 loc) · 2.31 KB
/
aliyunService.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
#!/bin/bash
checkAliyunServiceStatus(){
#serviceStatusList=("active (running)" "inactive (dead)")
echo -e "======================================================================================== \n"
echo "check aliyun service status...."
echo "======================================================================================== "
statusCode="36m"
for i in ${checkServiceList[@]}; do
consoleRetTmp=`systemctl status ${i} | grep "Active:"`
consoleStatus=`echo ${consoleRetTmp}|awk '{a=index($0,"Active: ");b=index($0,")");print substr($0,a+8,b-a-7)}'`
if [[ $consoleStatus =~ "running" ]]; then
statusCode="32m"
elif [[ $consoleStatus =~ "dead" ]]; then
statusCode="31m"
fi
echo -e "${i}:\033[${statusCode} ${consoleRetTmp} \033[0m"
done
echo -e "======================================================================================== \n"
}
checkServiceList=("aliyun.service" "aegis.service" "cloudmonitor.service")
checkAliyunServiceStatus
echo -n -e "please enter an integer to operator-> \n"
echo "======================================================================================== "
echo -e "\033[5maliyun service op>>>>\033[0m 0:exit 1:start 2:stop "
echo "======================================================================================== "
read -p ">> " nump
if [[ $nump =~ ^-?[0-2]$ ]]; then
case $nump in
1)
echo "going to start aliyun service"
for i in ${checkServiceList[@]}; do
systemctl start ${i}
done
echo "======================================================================================== "
checkAliyunServiceStatus
;;
2)
echo "going to stop aliyun service"
for i in ${checkServiceList[@]}; do
systemctl stop ${i}
done
echo "======================================================================================== "
checkAliyunServiceStatus
;;
0)
echo "Bye~"
echo "======================================================================================== "
exit
;;
*)
echo "Oh My God!!!"
;;
esac
else
echo "error inputs, please check it and have a try again"
echo "======================================================================================== "
fi