preun.sh 3.2 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
L
lihui 已提交
30
elif $(which service &> /dev/null); then    
H
[NONE]  
huili 已提交
31
    service_mod=1
L
lihui 已提交
32 33 34 35 36 37 38 39 40 41
    service_config_dir="/etc/init.d" 
    if $(which chkconfig &> /dev/null); then
         initd_mod=1 
    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
H
[NONE]  
huili 已提交
42 43
else 
    service_mod=2
H
hzcheng 已提交
44 45
fi

H
[NONE]  
huili 已提交
46 47
function kill_taosd() {
  pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}')
L
lihui 已提交
48 49 50
  if [ -n "$pid" ]; then
    ${csudo} kill -9 $pid   || :
  fi
H
[NONE]  
huili 已提交
51 52
}

H
hzcheng 已提交
53 54 55 56 57
function clean_service_on_systemd() {
    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 已提交
58
        ${csudo} systemctl stop ${taos_service_name} &> /dev/null || echo &> /dev/null
H
hzcheng 已提交
59
    fi
P
plum-lihui 已提交
60
    ${csudo} systemctl disable ${taos_service_name} &> /dev/null || echo &> /dev/null
H
hzcheng 已提交
61

P
plum-lihui 已提交
62
    ${csudo} rm -f ${taosd_service_config}	
H
hzcheng 已提交
63 64 65
}

function clean_service_on_sysvinit() {
L
lihui 已提交
66 67 68
    #restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start"
    #${csudo} sed -i "\|${restart_config_str}|d" /etc/inittab || :    
    
H
hzcheng 已提交
69
    if pidof taosd &> /dev/null; then
L
lihui 已提交
70
        echo "TDengine taosd is running, stopping it..."
P
plum-lihui 已提交
71
        ${csudo} service taosd stop || :
H
hzcheng 已提交
72
    fi
H
[NONE]  
huili 已提交
73 74

    if ((${initd_mod}==1)); then
L
lihui 已提交
75
        ${csudo} chkconfig --del taosd || :
H
[NONE]  
huili 已提交
76
    elif ((${initd_mod}==2)); then
L
lihui 已提交
77 78 79 80 81 82 83 84 85
        ${csudo} insserv -r taosd || :
    elif ((${initd_mod}==3)); then
        ${csudo} update-rc.d -f taosd remove || :
    fi
    
    ${csudo} rm -f ${service_config_dir}/taosd || :
   
    if $(which init &> /dev/null); then
        ${csudo} init q || :
H
[NONE]  
huili 已提交
86
    fi
H
hzcheng 已提交
87 88 89
}

function clean_service() {
H
[NONE]  
huili 已提交
90
    if ((${service_mod}==0)); then
H
hzcheng 已提交
91
        clean_service_on_systemd
H
[NONE]  
huili 已提交
92
    elif ((${service_mod}==1)); then
H
hzcheng 已提交
93
        clean_service_on_sysvinit
H
[NONE]  
huili 已提交
94
    else
L
lihui 已提交
95
        # must manual stop taosd
H
[NONE]  
huili 已提交
96
        kill_taosd
H
hzcheng 已提交
97 98 99 100 101 102 103
    fi
}

# Stop service and disable booting start.
clean_service

# Remove all links
P
plum-lihui 已提交
104 105
${csudo} rm -f ${bin_link_dir}/taos       || :
${csudo} rm -f ${bin_link_dir}/taosd      || :
S
slguan 已提交
106
${csudo} rm -f ${bin_link_dir}/taosdemo   || :
P
plum-lihui 已提交
107
${csudo} rm -f ${bin_link_dir}/taosdump   || :
H
Hui Li 已提交
108
${csudo} rm -f ${bin_link_dir}/set_core   || :
P
plum-lihui 已提交
109 110
${csudo} rm -f ${cfg_link_dir}/*          || :
${csudo} rm -f ${inc_link_dir}/taos.h     || :
H
Hui Li 已提交
111 112 113
${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 已提交
114 115 116

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

H
[NONE]  
huili 已提交
118 119 120 121
if ((${service_mod}==2)); then
    kill_taosd
fi

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