preun.sh 3.8 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 23 24 25
csudo=""
if command -v sudo > /dev/null; then
    csudo="sudo"
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 49 50 51 52
  if [ -n "$pid" ]; then
    ${csudo} kill -9 $pid   || :
  fi
}

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

H
hzcheng 已提交
60
function clean_service_on_systemd() {
61 62 63 64
    taosadapter_service_config="${service_config_dir}/taosadapter.service"
    if systemctl is-active --quiet taosadapter; then
        echo "taosadapter is running, stopping it..."
        ${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..."
P
plum-lihui 已提交
71
        ${csudo} systemctl stop ${taos_service_name} &> /dev/null || echo &> /dev/null
H
hzcheng 已提交
72
    fi
P
plum-lihui 已提交
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 84
    #${csudo} sed -i "\|${restart_config_str}|d" /etc/inittab || :

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

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

L
lihui 已提交
98
    ${csudo} rm -f ${service_config_dir}/taosd || :
99

L
lihui 已提交
100 101
    if $(which init &> /dev/null); then
        ${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
P
plum-lihui 已提交
121 122
${csudo} rm -f ${bin_link_dir}/taos       || :
${csudo} rm -f ${bin_link_dir}/taosd      || :
123
${csudo} rm -f ${bin_link_dir}/taosadapter       || :
S
slguan 已提交
124
${csudo} rm -f ${bin_link_dir}/taosdemo   || :
H
Hui Li 已提交
125
${csudo} rm -f ${bin_link_dir}/set_core   || :
126
${csudo} rm -f ${cfg_link_dir}/*.new      || :
P
plum-lihui 已提交
127
${csudo} rm -f ${inc_link_dir}/taos.h     || :
128
${csudo} rm -f ${inc_link_dir}/taosdef.h  || :
H
Hui Li 已提交
129 130 131
${csudo} rm -f ${inc_link_dir}/taoserror.h || :
${csudo} rm -f ${lib_link_dir}/libtaos.*   || :
${csudo} rm -f ${lib64_link_dir}/libtaos.* || :
P
plum-lihui 已提交
132 133 134

${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}"