remove.sh 8.1 KB
Newer Older
P
plum-lihui 已提交
1 2
#!/bin/bash
#
sangshuduo's avatar
sangshuduo 已提交
3
# Script to stop and uninstall the service, but retain the config, data and log files.
P
plum-lihui 已提交
4 5 6 7 8

set -e
#set -x

verMode=edge
wafwerar's avatar
wafwerar 已提交
9
osType=`uname`
P
plum-lihui 已提交
10 11 12 13 14

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

wafwerar's avatar
wafwerar 已提交
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
if [ "$osType" != "Darwin" ]; then
  installDir="/usr/local/taos"
  bin_link_dir="/usr/bin"
  lib_link_dir="/usr/lib"
  lib64_link_dir="/usr/lib64"
  inc_link_dir="/usr/include"
else
  if [ -d "/usr/local/Cellar/" ];then
    installDir="/usr/local/Cellar/tdengine/${verNumber}"
  elif [ -d "/opt/homebrew/Cellar/" ];then
    installDir="/opt/homebrew/Cellar/tdengine/${verNumber}"
  else
    installDir="/usr/local/taos"
  fi
  bin_link_dir="/usr/local/bin"
  lib_link_dir="/usr/local/lib"
  lib64_link_dir="/usr/local/lib"
  inc_link_dir="/usr/local/include"
fi
sangshuduo's avatar
sangshuduo 已提交
34 35 36 37 38
serverName="taosd"
clientName="taos"
uninstallScript="rmtaos"
productName="TDengine"

P
plum-lihui 已提交
39
#install main path
sangshuduo's avatar
sangshuduo 已提交
40 41 42 43 44
install_main_dir=${installDir}
data_link_dir=${installDir}/data
log_link_dir=${installDir}/log
cfg_link_dir=${installDir}/cfg
local_bin_link_dir="/usr/local/bin"
wafwerar's avatar
wafwerar 已提交
45

P
plum-lihui 已提交
46 47

service_config_dir="/etc/systemd/system"
sangshuduo's avatar
sangshuduo 已提交
48 49 50
taos_service_name=${serverName}
taosadapter_service_name="taosadapter"
tarbitrator_service_name="tarbitratord"
P
plum-lihui 已提交
51
csudo=""
sangshuduo's avatar
sangshuduo 已提交
52 53
if command -v sudo >/dev/null; then
  csudo="sudo "
P
plum-lihui 已提交
54 55 56 57
fi

initd_mod=0
service_mod=2
wafwerar's avatar
wafwerar 已提交
58
if ps aux | grep -v grep | grep systemd &>/dev/null; then
sangshuduo's avatar
sangshuduo 已提交
59 60 61 62 63 64 65 66 67 68 69
  service_mod=0
elif $(which service &>/dev/null); then
  service_mod=1
  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
P
plum-lihui 已提交
70
    service_mod=2
sangshuduo's avatar
sangshuduo 已提交
71 72 73
  fi
else
  service_mod=2
P
plum-lihui 已提交
74 75
fi

sangshuduo's avatar
sangshuduo 已提交
76 77 78 79 80 81
function kill_taosadapter() {
  pid=$(ps -ef | grep "taosadapter" | grep -v "grep" | awk '{print $2}')
  if [ -n "$pid" ]; then
    ${csudo}kill -9 $pid || :
  fi
}
P
plum-lihui 已提交
82 83

function kill_taosd() {
sangshuduo's avatar
sangshuduo 已提交
84
  pid=$(ps -ef | grep ${serverName} | grep -v "grep" | awk '{print $2}')
P
plum-lihui 已提交
85
  if [ -n "$pid" ]; then
sangshuduo's avatar
sangshuduo 已提交
86
    ${csudo}kill -9 $pid || :
P
plum-lihui 已提交
87 88 89
  fi
}

sangshuduo's avatar
sangshuduo 已提交
90 91 92 93 94 95
function kill_tarbitrator() {
  pid=$(ps -ef | grep "tarbitrator" | grep -v "grep" | awk '{print $2}')
  if [ -n "$pid" ]; then
    ${csudo}kill -9 $pid || :
  fi
}
P
plum-lihui 已提交
96 97

function clean_bin() {
sangshuduo's avatar
sangshuduo 已提交
98 99 100
  # Remove link
  ${csudo}rm -f ${bin_link_dir}/${clientName} || :
  ${csudo}rm -f ${bin_link_dir}/${serverName} || :
wafwerar's avatar
wafwerar 已提交
101
  ${csudo}rm -f ${bin_link_dir}/udfd || :
sangshuduo's avatar
sangshuduo 已提交
102 103 104 105 106 107 108 109 110 111 112 113 114
  ${csudo}rm -f ${bin_link_dir}/taosadapter || :
  ${csudo}rm -f ${bin_link_dir}/taosBenchmark || :
  ${csudo}rm -f ${bin_link_dir}/taosdemo || :
  ${csudo}rm -f ${bin_link_dir}/taosdump || :
  ${csudo}rm -f ${bin_link_dir}/${uninstallScript} || :
  ${csudo}rm -f ${bin_link_dir}/tarbitrator || :
  ${csudo}rm -f ${bin_link_dir}/set_core || :
  ${csudo}rm -f ${bin_link_dir}/TDinsight.sh || :
}

function clean_local_bin() {
  ${csudo}rm -f ${local_bin_link_dir}/taosBenchmark || :
  ${csudo}rm -f ${local_bin_link_dir}/taosdemo || :
P
plum-lihui 已提交
115 116 117
}

function clean_lib() {
sangshuduo's avatar
sangshuduo 已提交
118 119
  # Remove link
  ${csudo}rm -f ${lib_link_dir}/libtaos.* || :
wafwerar's avatar
wafwerar 已提交
120
  [ -f ${lib_link_dir}/libtaosws.* ] && ${csudo}rm -f ${lib_link_dir}/libtaosws.* || :
121

sangshuduo's avatar
sangshuduo 已提交
122
  ${csudo}rm -f ${lib64_link_dir}/libtaos.* || :
wafwerar's avatar
wafwerar 已提交
123
  [ -f ${lib64_link_dir}/libtaosws.* ] && ${csudo}rm -f ${lib64_link_dir}/libtaosws.* || :
sangshuduo's avatar
sangshuduo 已提交
124
  #${csudo}rm -rf ${v15_java_app_dir}           || :
P
plum-lihui 已提交
125 126 127
}

function clean_header() {
sangshuduo's avatar
sangshuduo 已提交
128 129 130 131
  # Remove link
  ${csudo}rm -f ${inc_link_dir}/taos.h || :
  ${csudo}rm -f ${inc_link_dir}/taosdef.h || :
  ${csudo}rm -f ${inc_link_dir}/taoserror.h || :
132
  ${csudo}rm -f ${inc_link_dir}/taosudf.h || :
133

134
  [ -f ${inc_link_dir}/taosws.h ] && ${csudo}rm -f ${inc_link_dir}/taosws.h || :
P
plum-lihui 已提交
135 136 137
}

function clean_config() {
sangshuduo's avatar
sangshuduo 已提交
138 139
  # Remove link
  ${csudo}rm -f ${cfg_link_dir}/* || :
P
plum-lihui 已提交
140 141 142
}

function clean_log() {
sangshuduo's avatar
sangshuduo 已提交
143 144
  # Remove link
  ${csudo}rm -rf ${log_link_dir} || :
P
plum-lihui 已提交
145 146 147
}

function clean_service_on_systemd() {
sangshuduo's avatar
sangshuduo 已提交
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
  taosd_service_config="${service_config_dir}/${taos_service_name}.service"
  if systemctl is-active --quiet ${taos_service_name}; then
    echo "${productName} ${serverName} is running, stopping it..."
    ${csudo}systemctl stop ${taos_service_name} &>/dev/null || echo &>/dev/null
  fi
  ${csudo}systemctl disable ${taos_service_name} &>/dev/null || echo &>/dev/null
  ${csudo}rm -f ${taosd_service_config}

  taosadapter_service_config="${service_config_dir}/taosadapter.service"
  if systemctl is-active --quiet ${taosadapter_service_name}; then
    echo "${productName} taosAdapter is running, stopping it..."
    ${csudo}systemctl stop ${taosadapter_service_name} &>/dev/null || echo &>/dev/null
  fi
  ${csudo}systemctl disable ${taosadapter_service_name} &>/dev/null || echo &>/dev/null
  [ -f ${taosadapter_service_config} ] && ${csudo}rm -f ${taosadapter_service_config}

  tarbitratord_service_config="${service_config_dir}/${tarbitrator_service_name}.service"
  if systemctl is-active --quiet ${tarbitrator_service_name}; then
    echo "${productName} tarbitrator is running, stopping it..."
    ${csudo}systemctl stop ${tarbitrator_service_name} &>/dev/null || echo &>/dev/null
  fi
  ${csudo}systemctl disable ${tarbitrator_service_name} &>/dev/null || echo &>/dev/null
  ${csudo}rm -f ${tarbitratord_service_config}
P
plum-lihui 已提交
171 172 173
}

function clean_service_on_sysvinit() {
wafwerar's avatar
wafwerar 已提交
174
  if ps aux | grep -v grep | grep ${serverName} &>/dev/null; then
sangshuduo's avatar
sangshuduo 已提交
175 176 177 178
    echo "${productName} ${serverName} is running, stopping it..."
    ${csudo}service ${serverName} stop || :
  fi

wafwerar's avatar
wafwerar 已提交
179
  if ps aux | grep -v grep | grep tarbitrator &>/dev/null; then
sangshuduo's avatar
sangshuduo 已提交
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
    echo "${productName} tarbitrator is running, stopping it..."
    ${csudo}service tarbitratord stop || :
  fi

  if ((${initd_mod} == 1)); then
    if [ -e ${service_config_dir}/${serverName} ]; then
      ${csudo}chkconfig --del ${serverName} || :
    fi
    if [ -e ${service_config_dir}/tarbitratord ]; then
      ${csudo}chkconfig --del tarbitratord || :
    fi
  elif ((${initd_mod} == 2)); then
    if [ -e ${service_config_dir}/${serverName} ]; then
      ${csudo}insserv -r ${serverName} || :
    fi
    if [ -e ${service_config_dir}/tarbitratord ]; then
      ${csudo}insserv -r tarbitratord || :
    fi
  elif ((${initd_mod} == 3)); then
    if [ -e ${service_config_dir}/${serverName} ]; then
      ${csudo}update-rc.d -f ${serverName} remove || :
    fi
    if [ -e ${service_config_dir}/tarbitratord ]; then
      ${csudo}update-rc.d -f tarbitratord remove || :
    fi
  fi

  ${csudo}rm -f ${service_config_dir}/${serverName} || :
  ${csudo}rm -f ${service_config_dir}/tarbitratord || :

  if $(which init &>/dev/null); then
    ${csudo}init q || :
  fi
P
plum-lihui 已提交
213 214
}

wafwerar's avatar
wafwerar 已提交
215 216 217
function clean_service_on_launchctl() {
  ${csudouser}launchctl unload -w /Library/LaunchDaemons/com.taosdata.taosd.plist > /dev/null 2>&1 || :
  ${csudo}rm /Library/LaunchDaemons/com.taosdata.taosd.plist > /dev/null 2>&1 || :
wafwerar's avatar
wafwerar 已提交
218 219
  ${csudouser}launchctl unload -w /Library/LaunchDaemons/com.taosdata.taosadapter.plist > /dev/null 2>&1 || :
  ${csudo}rm /Library/LaunchDaemons/com.taosdata.taosadapter.plist > /dev/null 2>&1 || :
wafwerar's avatar
wafwerar 已提交
220 221
}

P
plum-lihui 已提交
222
function clean_service() {
sangshuduo's avatar
sangshuduo 已提交
223 224 225 226 227
  if ((${service_mod} == 0)); then
    clean_service_on_systemd
  elif ((${service_mod} == 1)); then
    clean_service_on_sysvinit
  else
wafwerar's avatar
wafwerar 已提交
228 229 230
    if [ "$osType" = "Darwin" ]; then
      clean_service_on_launchctl
    fi
sangshuduo's avatar
sangshuduo 已提交
231 232 233 234
    kill_taosadapter
    kill_taosd
    kill_tarbitrator
  fi
P
plum-lihui 已提交
235 236 237 238 239 240
}

# Stop service and disable booting start.
clean_service
# Remove binary file and links
clean_bin
sangshuduo's avatar
sangshuduo 已提交
241 242
# Remove links of local bin
clean_local_bin
P
plum-lihui 已提交
243 244 245 246 247 248 249 250 251
# Remove header file.
clean_header
# Remove lib file
clean_lib
# Remove link log directory
clean_log
# Remove link configuration file
clean_config
# Remove data link directory
sangshuduo's avatar
sangshuduo 已提交
252
${csudo}rm -rf ${data_link_dir} || :
P
plum-lihui 已提交
253

sangshuduo's avatar
sangshuduo 已提交
254
${csudo}rm -rf ${install_main_dir}
P
plum-lihui 已提交
255 256 257 258 259 260
if [[ -e /etc/os-release ]]; then
  osinfo=$(awk -F= '/^NAME/{print $2}' /etc/os-release)
else
  osinfo=""
fi

sangshuduo's avatar
sangshuduo 已提交
261 262 263 264 265 266 267 268 269 270
if echo $osinfo | grep -qwi "ubuntu"; then
  #  echo "this is ubuntu system"
  ${csudo}dpkg --force-all -P tdengine >/dev/null 2>&1 || :
elif echo $osinfo | grep -qwi "debian"; then
  #  echo "this is debian system"
  ${csudo}dpkg --force-all -P tdengine >/dev/null 2>&1 || :
elif echo $osinfo | grep -qwi "centos"; then
  #  echo "this is centos system"
  ${csudo}rpm -e --noscripts tdengine >/dev/null 2>&1 || :
fi
wafwerar's avatar
wafwerar 已提交
271 272 273
if [ "$osType" = "Darwin" ]; then
  ${csudo}rm -rf /Applications/TDengine.app
fi
sangshuduo's avatar
sangshuduo 已提交
274 275

echo -e "${GREEN}${productName} is removed successfully!${NC}"
P
plum-lihui 已提交
276
echo