remove.sh 10.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.* || :
145
  ${csudo}rm -f ${lib_link_dir}/librocksdb.* || :
wafwerar's avatar
wafwerar 已提交
146
  [ -f ${lib_link_dir}/libtaosws.* ] && ${csudo}rm -f ${lib_link_dir}/libtaosws.* || :
147

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

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

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

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

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

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

184
  taosadapter_service_config="${service_config_dir}/${clientName2}adapter.service"
sangshuduo's avatar
sangshuduo 已提交
185
  if systemctl is-active --quiet ${taosadapter_service_name}; then
X
xinsheng Ren 已提交
186
    echo "${productName2}  ${clientName2}Adapter is running, stopping it..."
sangshuduo's avatar
sangshuduo 已提交
187 188 189 190 191 192 193
    ${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 已提交
194
    echo "${productName2} tarbitrator is running, stopping it..."
sangshuduo's avatar
sangshuduo 已提交
195 196 197
    ${csudo}systemctl stop ${tarbitrator_service_name} &>/dev/null || echo &>/dev/null
  fi
  ${csudo}systemctl disable ${tarbitrator_service_name} &>/dev/null || echo &>/dev/null
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218

  x_service_config="${service_config_dir}/${xName2}.service"
  if [ -e "$x_service_config" ]; then
    if systemctl is-active --quiet ${xName2}; then
      echo "${productName2} ${xName2} is running, stopping it..."
      ${csudo}systemctl stop ${xName2} &>/dev/null || echo &>/dev/null
    fi
    ${csudo}systemctl disable ${xName2} &>/dev/null || echo &>/dev/null
    ${csudo}rm -f ${x_service_config}
  fi

  explorer_service_config="${service_config_dir}/${explorerName2}.service"
  if [ -e "$explorer_service_config" ]; then
    if systemctl is-active --quiet ${explorerName2}; then
      echo "${productName2} ${explorerName2} is running, stopping it..."
      ${csudo}systemctl stop ${explorerName2} &>/dev/null || echo &>/dev/null
    fi
    ${csudo}systemctl disable ${explorerName2} &>/dev/null || echo &>/dev/null
    ${csudo}rm -f ${explorer_service_config}
    ${csudo}rm -f /etc/${clientName2}/explorer.toml
  fi
P
plum-lihui 已提交
219 220 221
}

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

wafwerar's avatar
wafwerar 已提交
227
  if ps aux | grep -v grep | grep tarbitrator &>/dev/null; then
X
xinsheng Ren 已提交
228
    echo "${productName2} tarbitrator is running, stopping it..."
sangshuduo's avatar
sangshuduo 已提交
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
    ${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 已提交
261 262
}

wafwerar's avatar
wafwerar 已提交
263 264 265
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 || :
266 267
  ${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 已提交
268 269
}

P
plum-lihui 已提交
270
function clean_service() {
sangshuduo's avatar
sangshuduo 已提交
271 272 273 274 275
  if ((${service_mod} == 0)); then
    clean_service_on_systemd
  elif ((${service_mod} == 1)); then
    clean_service_on_sysvinit
  else
wafwerar's avatar
wafwerar 已提交
276 277 278
    if [ "$osType" = "Darwin" ]; then
      clean_service_on_launchctl
    fi
sangshuduo's avatar
sangshuduo 已提交
279 280 281 282
    kill_taosadapter
    kill_taosd
    kill_tarbitrator
  fi
P
plum-lihui 已提交
283 284 285 286 287 288
}

# Stop service and disable booting start.
clean_service
# Remove binary file and links
clean_bin
sangshuduo's avatar
sangshuduo 已提交
289 290
# Remove links of local bin
clean_local_bin
P
plum-lihui 已提交
291 292 293 294 295 296 297 298 299
# 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 已提交
300
${csudo}rm -rf ${data_link_dir} || :
P
plum-lihui 已提交
301

sangshuduo's avatar
sangshuduo 已提交
302
${csudo}rm -rf ${install_main_dir}
P
plum-lihui 已提交
303 304 305 306 307 308
if [[ -e /etc/os-release ]]; then
  osinfo=$(awk -F= '/^NAME/{print $2}' /etc/os-release)
else
  osinfo=""
fi

sangshuduo's avatar
sangshuduo 已提交
309 310 311 312 313 314 315 316 317 318
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 已提交
319 320 321
if [ "$osType" = "Darwin" ]; then
  ${csudo}rm -rf /Applications/TDengine.app
fi
sangshuduo's avatar
sangshuduo 已提交
322

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