-
Notifications
You must be signed in to change notification settings - Fork 0
/
stop.sh
executable file
·55 lines (51 loc) · 1.48 KB
/
stop.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
#!/bin/bash
:<<EOF
Python program automatic installation script
EOF
# TODO: Function to display message
function echo_blue(){
echo -e "\033[34m$1\033[0m"
}
# green to echo
function echo_green(){
echo -e "\033[32m$1\033[0m"
}
# Error
function echo_red(){
echo -e "\033[31m\033[01m$1\033[0m"
}
# warning
function echo_yellow(){
echo -e "\033[33m\033[01m$1\033[0m"
}
# TODO: Get script name
script_name=`basename $(dirname $(readlink -f $0))`
read -p "Are you sure to stop the script(yes/no)? :" result
if [[ $result == "yes" || $result == "y" ]]; then
echo_green "Start stopping the ${script_name} service."
else
echo_green "Cancel stop service."
exit 0
fi
# TODO: Stop service
echo_blue "$(date "+%Y-%m-%d %H:%M:%S"): Is judging whether the service is exsit."
cmd0=`sudo systemctl status ${script_name}`
if [[ $cmd0 =~ "loaded" ]]; then
echo_green "$(date "+%Y-%m-%d %H:%M:%S"): Service exsit."
else
echo_red "$(date "+%Y-%m-%d %H:%M:%S"): Service not exsit."
exit 1
fi
if [[ $cmd0 =~ "running" ]]; then
echo_green "$(date "+%Y-%m-%d %H:%M:%S"): Stopping service."
sudo systemctl stop ${script_name}
else
echo_green "$(date "+%Y-%m-%d %H:%M:%S"): Service has stopped."
fi
cmd1=`sudo systemctl status ${script_name} | grep "inactive"`
if [[ $cmd1 =~ "inactive" ]]; then
echo_green "$(date "+%Y-%m-%d %H:%M:%S"): [OK] Stop completed."
else
echo_red "$(date "+%Y-%m-%d %H:%M:%S"): [Err] Stop failure, status information is as follows."
sudo systemctl status ${script_name}
fi