-
Notifications
You must be signed in to change notification settings - Fork 60
/
stop_uninstall_app.sh
92 lines (82 loc) · 1.72 KB
/
stop_uninstall_app.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
#!/bin/bash
# author: guoqun
# date: 20170410
SETCOLOR_SUCCESS="echo -en \\033[1;32m"
SETCOLOR_FAILURE="echo -en \\033[1;31m"
SETCOLOR_WARNING="echo -en \\033[1;33m"
SETCOLOR_NORMAL="echo -en \\033[0;39m"
# 定义记录日志的函数
LogMsg()
{
time=`date "+%D %T"`
echo "[$time] : INFO : $*"
${SETCOLOR_NORMAL}
}
LogWarnMsg()
{
time=`date "+%D %T"`
${SETCOLOR_WARNING}
echo "[$time] : WARN : $*"
${SETCOLOR_NORMAL}
}
LogSucMsg()
{
time=`date "+%D %T"`
${SETCOLOR_SUCCESS}
echo "[$time] : SUCCESS : $*"
${SETCOLOR_NORMAL}
}
LogErrorMsg()
{
time=`date "+%D %T"`
${SETCOLOR_FAILURE}
echo "[$time] : ERROR : $*"
${SETCOLOR_NORMAL}
}
check_auto_ssh()
{
ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=no ${INSTALL_IP} 'exit'
if [ $? -ne 0 ]
then
LogErrorMsg "can not logon $INSTALL_IP without passwd."
exit 1
fi
}
stop_agent()
{
agent_pid=`ssh ${INSTALL_IP} ps aux | grep "ns_agent.py" | grep -v grep | awk -F " " '{print $2}'`
if [ "$agent_pid" = "" ]
then
echo "没有需要停止的客户端"
else
ssh ${INSTALL_IP} "kill -9 $agent_pid"
fi
}
unset_crond()
{
ssh ${INSTALL_IP} "rm -rf /etc/cron.d/daemon_ns_agent"
ssh ${INSTALL_IP} "service crond restart 1>/dev/null 2>/dev/null"
}
uninstall_to_node()
{
ssh ${INSTALL_IP} "rm -rf ${INSTALL_PATH}"
}
INSTALL_IP=$1
INSTALL_TYPE=$2
INSTALL_PATH="/home/RunTimeNSDash"
APP_TAR_NAME="ns_agent.tar.gz"
LogMsg "校验服务器连通性: ${INSTALL_IP}"
check_auto_ssh
if [ $INSTALL_TYPE = "stop" ]
then
LogMsg "开始停止"
unset_crond
stop_agent
elif [ $INSTALL_TYPE = "uninstall" ]
then
LogMsg "开始停止"
stop_agent
LogMsg "开始卸载"
uninstall_to_node
unset_crond
fi