remove.sh 9.0 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"

X
xinsheng Ren 已提交
39 40 41 42
serverName2="taosd"
clientName2="taos"
productName2="TDengine"

43 44
adapterName2="${clientName2}adapter"
demoName2="${clientName2}demo"
X
xinsheng Ren 已提交
45 46
benchmarkName2="${clientName2}Benchmark"
dumpName2="${clientName2}dump"
47 48 49
keeperName2="${clientName2}keeper"
xName2="${clientName2}x"
explorerName2="${clientName2}-explorer"
X
xinsheng Ren 已提交
50 51
uninstallScript2="rm${clientName2}"

52
installDir="/usr/local/${clientName2}"
X
xinsheng Ren 已提交
53

P
plum-lihui 已提交
54
#install main path
sangshuduo's avatar
sangshuduo 已提交
55 56 57 58 59
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 已提交
60

P
plum-lihui 已提交
61 62

service_config_dir="/etc/systemd/system"
63 64
taos_service_name=${serverName2}
taosadapter_service_name="${clientName2}adapter"
sangshuduo's avatar
sangshuduo 已提交
65
tarbitrator_service_name="tarbitratord"
P
plum-lihui 已提交
66
csudo=""
sangshuduo's avatar
sangshuduo 已提交
67 68
if command -v sudo >/dev/null; then
  csudo="sudo "
P
plum-lihui 已提交
69 70 71 72
fi

initd_mod=0
service_mod=2
wafwerar's avatar
wafwerar 已提交
73
if ps aux | grep -v grep | grep systemd &>/dev/null; then
sangshuduo's avatar
sangshuduo 已提交
74 75 76 77 78 79 80 81 82 83 84
  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 已提交
85
    service_mod=2
sangshuduo's avatar
sangshuduo 已提交
86 87 88
  fi
else
  service_mod=2
P
plum-lihui 已提交
89 90
fi

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

function kill_taosd() {
99
  pid=$(ps -ef | grep ${serverName2} | grep -v "grep" | awk '{print $2}')
P
plum-lihui 已提交
100
  if [ -n "$pid" ]; then
sangshuduo's avatar
sangshuduo 已提交
101
    ${csudo}kill -9 $pid || :
P
plum-lihui 已提交
102 103 104
  fi
}

sangshuduo's avatar
sangshuduo 已提交
105 106 107 108 109 110
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 已提交
111 112

function clean_bin() {
sangshuduo's avatar
sangshuduo 已提交
113 114 115
  # Remove link
  ${csudo}rm -f ${bin_link_dir}/${clientName} || :
  ${csudo}rm -f ${bin_link_dir}/${serverName} || :
wafwerar's avatar
wafwerar 已提交
116
  ${csudo}rm -f ${bin_link_dir}/udfd || :
117 118 119 120 121
  ${csudo}rm -f ${bin_link_dir}/${adapterName2}     || :
  ${csudo}rm -f ${bin_link_dir}/${benchmarkName2}   || :
  ${csudo}rm -f ${bin_link_dir}/${demoName2}        || :
  ${csudo}rm -f ${bin_link_dir}/${dumpName2}        || :
  ${csudo}rm -f ${bin_link_dir}/${uninstallScript}  || :
sangshuduo's avatar
sangshuduo 已提交
122 123 124
  ${csudo}rm -f ${bin_link_dir}/tarbitrator || :
  ${csudo}rm -f ${bin_link_dir}/set_core || :
  ${csudo}rm -f ${bin_link_dir}/TDinsight.sh || :
125 126 127
  ${csudo}rm -f ${bin_link_dir}/${keeperName2}      || :
  ${csudo}rm -f ${bin_link_dir}/${xName2}           || :
  ${csudo}rm -f ${bin_link_dir}/${explorerName2}    || :
X
xinsheng Ren 已提交
128 129 130 131 132 133 134

  if [ "$verMode" == "cluster" ] && [ "$clientName" != "$clientName2" ]; then
    ${csudo}rm -f ${bin_link_dir}/${clientName2} || :
    ${csudo}rm -f ${bin_link_dir}/${benchmarkName2} || :
    ${csudo}rm -f ${bin_link_dir}/${dumpName2} || :
    ${csudo}rm -f ${bin_link_dir}/${uninstallScript2} || :
  fi
sangshuduo's avatar
sangshuduo 已提交
135 136 137
}

function clean_local_bin() {
138 139
  ${csudo}rm -f ${local_bin_link_dir}/${benchmarkName2} || :
  ${csudo}rm -f ${local_bin_link_dir}/${demoName2}      || :
P
plum-lihui 已提交
140 141 142
}

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

sangshuduo's avatar
sangshuduo 已提交
147
  ${csudo}rm -f ${lib64_link_dir}/libtaos.* || :
wafwerar's avatar
wafwerar 已提交
148
  [ -f ${lib64_link_dir}/libtaosws.* ] && ${csudo}rm -f ${lib64_link_dir}/libtaosws.* || :
sangshuduo's avatar
sangshuduo 已提交
149
  #${csudo}rm -rf ${v15_java_app_dir}           || :
P
plum-lihui 已提交
150 151 152
}

function clean_header() {
sangshuduo's avatar
sangshuduo 已提交
153 154 155 156
  # 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 || :
157
  ${csudo}rm -f ${inc_link_dir}/taosudf.h || :
158

159
  [ -f ${inc_link_dir}/taosws.h ] && ${csudo}rm -f ${inc_link_dir}/taosws.h || :
P
plum-lihui 已提交
160 161 162
}

function clean_config() {
sangshuduo's avatar
sangshuduo 已提交
163 164
  # Remove link
  ${csudo}rm -f ${cfg_link_dir}/* || :
P
plum-lihui 已提交
165 166 167
}

function clean_log() {
sangshuduo's avatar
sangshuduo 已提交
168 169
  # Remove link
  ${csudo}rm -rf ${log_link_dir} || :
P
plum-lihui 已提交
170 171 172
}

function clean_service_on_systemd() {
sangshuduo's avatar
sangshuduo 已提交
173 174
  taosd_service_config="${service_config_dir}/${taos_service_name}.service"
  if systemctl is-active --quiet ${taos_service_name}; then
X
xinsheng Ren 已提交
175
    echo "${productName2} ${serverName2} is running, stopping it..."
sangshuduo's avatar
sangshuduo 已提交
176 177 178 179 180
    ${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}

181
  taosadapter_service_config="${service_config_dir}/${clientName2}adapter.service"
sangshuduo's avatar
sangshuduo 已提交
182
  if systemctl is-active --quiet ${taosadapter_service_name}; then
X
xinsheng Ren 已提交
183
    echo "${productName2}  ${clientName2}Adapter is running, stopping it..."
sangshuduo's avatar
sangshuduo 已提交
184 185 186 187 188 189 190
    ${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
X
xinsheng Ren 已提交
191
    echo "${productName2} tarbitrator is running, stopping it..."
sangshuduo's avatar
sangshuduo 已提交
192 193 194 195
    ${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 已提交
196 197 198
}

function clean_service_on_sysvinit() {
wafwerar's avatar
wafwerar 已提交
199
  if ps aux | grep -v grep | grep ${serverName} &>/dev/null; then
X
xinsheng Ren 已提交
200
    echo "${productName2} ${serverName2} is running, stopping it..."
sangshuduo's avatar
sangshuduo 已提交
201 202 203
    ${csudo}service ${serverName} stop || :
  fi

wafwerar's avatar
wafwerar 已提交
204
  if ps aux | grep -v grep | grep tarbitrator &>/dev/null; then
X
xinsheng Ren 已提交
205
    echo "${productName2} tarbitrator is running, stopping it..."
sangshuduo's avatar
sangshuduo 已提交
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
    ${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 已提交
238 239
}

wafwerar's avatar
wafwerar 已提交
240 241 242
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 || :
243 244
  ${csudouser}launchctl unload -w /Library/LaunchDaemons/com.taosdata.${clientName2}adapter.plist > /dev/null 2>&1 || :
  ${csudo}rm /Library/LaunchDaemons/com.taosdata.${clientName2}adapter.plist > /dev/null 2>&1 || :
wafwerar's avatar
wafwerar 已提交
245 246
}

P
plum-lihui 已提交
247
function clean_service() {
sangshuduo's avatar
sangshuduo 已提交
248 249 250 251 252
  if ((${service_mod} == 0)); then
    clean_service_on_systemd
  elif ((${service_mod} == 1)); then
    clean_service_on_sysvinit
  else
wafwerar's avatar
wafwerar 已提交
253 254 255
    if [ "$osType" = "Darwin" ]; then
      clean_service_on_launchctl
    fi
sangshuduo's avatar
sangshuduo 已提交
256 257 258 259
    kill_taosadapter
    kill_taosd
    kill_tarbitrator
  fi
P
plum-lihui 已提交
260 261 262 263 264 265
}

# Stop service and disable booting start.
clean_service
# Remove binary file and links
clean_bin
sangshuduo's avatar
sangshuduo 已提交
266 267
# Remove links of local bin
clean_local_bin
P
plum-lihui 已提交
268 269 270 271 272 273 274 275 276
# 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 已提交
277
${csudo}rm -rf ${data_link_dir} || :
P
plum-lihui 已提交
278

sangshuduo's avatar
sangshuduo 已提交
279
${csudo}rm -rf ${install_main_dir}
P
plum-lihui 已提交
280 281 282 283 284 285
if [[ -e /etc/os-release ]]; then
  osinfo=$(awk -F= '/^NAME/{print $2}' /etc/os-release)
else
  osinfo=""
fi

sangshuduo's avatar
sangshuduo 已提交
286 287 288 289 290 291 292 293 294 295
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 已提交
296 297 298
if [ "$osType" = "Darwin" ]; then
  ${csudo}rm -rf /Applications/TDengine.app
fi
sangshuduo's avatar
sangshuduo 已提交
299

X
xinsheng Ren 已提交
300
echo -e "${GREEN}${productName2} is removed successfully!${NC}"
P
plum-lihui 已提交
301
echo