preun.sh 3.7 KB
Newer Older
H
hzcheng 已提交
1 2 3 4 5 6 7 8 9 10
#!/bin/bash
#
# Script to stop the service and uninstall TSDB

RED='\033[0;31m'
GREEN='\033[1;32m'
NC='\033[0m'

bin_link_dir="/usr/bin"
lib_link_dir="/usr/lib"
H
Hui Li 已提交
11
lib64_link_dir="/usr/lib64"
H
hzcheng 已提交
12 13 14 15 16 17 18 19 20
inc_link_dir="/usr/include"

data_link_dir="/usr/local/taos/data"
log_link_dir="/usr/local/taos/log"
cfg_link_dir="/usr/local/taos/cfg"

service_config_dir="/etc/systemd/system"
taos_service_name="taosd"

P
plum-lihui 已提交
21 22
csudo=""
if command -v sudo > /dev/null; then
23
    csudo="sudo "
P
plum-lihui 已提交
24 25
fi

H
[NONE]  
huili 已提交
26 27 28 29
initd_mod=0
service_mod=2
if pidof systemd &> /dev/null; then
    service_mod=0
30
elif $(which service &> /dev/null); then
H
[NONE]  
huili 已提交
31
    service_mod=1
32
    service_config_dir="/etc/init.d"
L
lihui 已提交
33
    if $(which chkconfig &> /dev/null); then
34
         initd_mod=1
L
lihui 已提交
35 36 37 38 39 40 41
    elif $(which insserv &> /dev/null); then
        initd_mod=2
    elif $(which update-rc.d &> /dev/null); then
        initd_mod=3
    else
        service_mod=2
    fi
42
else
H
[NONE]  
huili 已提交
43
    service_mod=2
H
hzcheng 已提交
44 45
fi

46 47
function kill_taosadapter() {
  pid=$(ps -ef | grep "taosadapter" | grep -v "grep" | awk '{print $2}')
48
  if [ -n "$pid" ]; then
49
    ${csudo}kill -9 $pid   || :
50 51 52
  fi
}

H
[NONE]  
huili 已提交
53 54
function kill_taosd() {
  pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}')
L
lihui 已提交
55
  if [ -n "$pid" ]; then
56
    ${csudo}kill -9 $pid   || :
L
lihui 已提交
57
  fi
H
[NONE]  
huili 已提交
58 59
}

H
hzcheng 已提交
60
function clean_service_on_systemd() {
61 62 63
    taosadapter_service_config="${service_config_dir}/taosadapter.service"
    if systemctl is-active --quiet taosadapter; then
        echo "taosadapter is running, stopping it..."
64
        ${csudo}systemctl stop taosadapter &> /dev/null || echo &> /dev/null
65 66
    fi

H
hzcheng 已提交
67 68 69 70
    taosd_service_config="${service_config_dir}/${taos_service_name}.service"

    if systemctl is-active --quiet ${taos_service_name}; then
        echo "TDengine taosd is running, stopping it..."
71
        ${csudo}systemctl stop ${taos_service_name} &> /dev/null || echo &> /dev/null
H
hzcheng 已提交
72
    fi
73
    ${csudo}systemctl disable ${taos_service_name} &> /dev/null || echo &> /dev/null
H
hzcheng 已提交
74

75
    ${csudo}rm -f ${taosd_service_config}
76

77
    [ -f ${taosadapter_service_config} ] && ${csudo}rm -f ${taosadapter_service_config}
78

H
hzcheng 已提交
79 80 81
}

function clean_service_on_sysvinit() {
L
lihui 已提交
82
    #restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start"
83
    #${csudo}sed -i "\|${restart_config_str}|d" /etc/inittab || :
84

H
hzcheng 已提交
85
    if pidof taosd &> /dev/null; then
L
lihui 已提交
86
        echo "TDengine taosd is running, stopping it..."
87
        ${csudo}service taosd stop || :
H
hzcheng 已提交
88
    fi
H
[NONE]  
huili 已提交
89 90

    if ((${initd_mod}==1)); then
91
        ${csudo}chkconfig --del taosd || :
H
[NONE]  
huili 已提交
92
    elif ((${initd_mod}==2)); then
93
        ${csudo}insserv -r taosd || :
L
lihui 已提交
94
    elif ((${initd_mod}==3)); then
95
        ${csudo}update-rc.d -f taosd remove || :
L
lihui 已提交
96
    fi
97

98
    ${csudo}rm -f ${service_config_dir}/taosd || :
99

L
lihui 已提交
100
    if $(which init &> /dev/null); then
101
        ${csudo}init q || :
H
[NONE]  
huili 已提交
102
    fi
H
hzcheng 已提交
103 104 105
}

function clean_service() {
H
[NONE]  
huili 已提交
106
    if ((${service_mod}==0)); then
H
hzcheng 已提交
107
        clean_service_on_systemd
H
[NONE]  
huili 已提交
108
    elif ((${service_mod}==1)); then
H
hzcheng 已提交
109
        clean_service_on_sysvinit
H
[NONE]  
huili 已提交
110
    else
L
lihui 已提交
111
        # must manual stop taosd
112
        kill_taosadapter
H
[NONE]  
huili 已提交
113
        kill_taosd
H
hzcheng 已提交
114 115 116 117 118 119 120
    fi
}

# Stop service and disable booting start.
clean_service

# Remove all links
121 122 123 124 125 126 127 128 129 130 131 132 133 134
${csudo}rm -f ${bin_link_dir}/taos       || :
${csudo}rm -f ${bin_link_dir}/taosd      || :
${csudo}rm -f ${bin_link_dir}/taosadapter       || :
${csudo}rm -f ${bin_link_dir}/taosdemo   || :
${csudo}rm -f ${bin_link_dir}/set_core   || :
${csudo}rm -f ${cfg_link_dir}/*.new      || :
${csudo}rm -f ${inc_link_dir}/taos.h     || :
${csudo}rm -f ${inc_link_dir}/taosdef.h  || :
${csudo}rm -f ${inc_link_dir}/taoserror.h || :
${csudo}rm -f ${lib_link_dir}/libtaos.*   || :
${csudo}rm -f ${lib64_link_dir}/libtaos.* || :

${csudo}rm -f ${log_link_dir}            || :
${csudo}rm -f ${data_link_dir}           || :
H
hzcheng 已提交
135

H
[NONE]  
huili 已提交
136
if ((${service_mod}==2)); then
137
    kill_taosadapter
H
[NONE]  
huili 已提交
138 139 140
    kill_taosd
fi

H
Hui Li 已提交
141
echo -e "${GREEN}TDengine is removed successfully!${NC}"