diff --git a/packaging/tools/install.sh b/packaging/tools/install.sh index f646009b21..449f6f6cdb 100755 --- a/packaging/tools/install.sh +++ b/packaging/tools/install.sh @@ -373,7 +373,12 @@ function add_newHostname_to_hosts() { return fi done - ${csudo}echo "127.0.0.1 $1" >>/etc/hosts || : + + if grep -q "127.0.0.1 $1" /etc/hosts; then + return + else + ${csudo}echo "127.0.0.1 $1" >>/etc/hosts + fi } function set_hostname() { @@ -388,28 +393,32 @@ function set_hostname() { fi done - ${csudo}hostname $newHostname || : - retval=$(echo $?) - if [[ $retval != 0 ]]; then - echo - echo "set hostname fail!" - return - fi + # ${csudo}hostname $newHostname || : + # retval=$(echo $?) + # if [[ $retval != 0 ]]; then + # echo + # echo "set hostname fail!" + # return + # fi - #ubuntu/centos /etc/hostname - if [[ -e /etc/hostname ]]; then - ${csudo}echo $newHostname >/etc/hostname || : - fi + # #ubuntu/centos /etc/hostname + # if [[ -e /etc/hostname ]]; then + # ${csudo}echo $newHostname >/etc/hostname || : + # fi - #debian: #HOSTNAME=yourname - if [[ -e /etc/sysconfig/network ]]; then - ${csudo}sed -i -r "s/#*\s*(HOSTNAME=\s*).*/\1$newHostname/" /etc/sysconfig/network || : - fi + # #debian: #HOSTNAME=yourname + # if [[ -e /etc/sysconfig/network ]]; then + # ${csudo}sed -i -r "s/#*\s*(HOSTNAME=\s*).*/\1$newHostname/" /etc/sysconfig/network || : + # fi - ${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$newHostname/" ${cfg_install_dir}/${configFile2} + if [ -f ${cfg_install_dir}/${configFile2} ]; then + ${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$newHostname/" ${cfg_install_dir}/${configFile2} + else + ${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$newHostname/" ${script_dir}/cfg/${configFile2} + fi serverFqdn=$newHostname - if [[ -e /etc/hosts ]]; then + if [[ -e /etc/hosts ]] && [[ ! $newHostname =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then add_newHostname_to_hosts $newHostname fi } @@ -440,7 +449,12 @@ function set_ipAsFqdn() { echo -e -n "${GREEN}Unable to get local ip, use 127.0.0.1${NC}" localFqdn="127.0.0.1" # Write the local FQDN to configuration file - ${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${cfg_install_dir}/${configFile2} + + if [ -f ${cfg_install_dir}/${configFile2} ]; then + ${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${cfg_install_dir}/${configFile2} + else + ${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${script_dir}/cfg/${configFile2} + fi serverFqdn=$localFqdn echo return @@ -461,8 +475,12 @@ function set_ipAsFqdn() { if [[ $retval != 0 ]]; then read -p "Please choose an IP from local IP list:" localFqdn else - # Write the local FQDN to configuration file - ${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${cfg_install_dir}/${configFile2} + # Write the local FQDN to configuration file + if [ -f ${cfg_install_dir}/${configFile2} ]; then + ${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${cfg_install_dir}/${configFile2} + else + ${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${script_dir}/cfg/${configFile2} + fi serverFqdn=$localFqdn break fi @@ -481,6 +499,9 @@ function local_fqdn_check() { } function install_adapter_config() { + if [ -f ${script_dir}/cfg/${adapterName}.toml ]; then + ${csudo}sed -i -r "s/localhost/${serverFqdn}/g" ${script_dir}/cfg/${adapterName}.toml + fi if [ ! -f "${cfg_install_dir}/${adapterName}.toml" ]; then ${csudo}mkdir -p ${cfg_install_dir} [ -f ${script_dir}/cfg/${adapterName}.toml ] && ${csudo}cp ${script_dir}/cfg/${adapterName}.toml ${cfg_install_dir} @@ -536,7 +557,11 @@ function install_config() { read firstEp while true; do if [ ! -z "$firstEp" ]; then - ${csudo}sed -i -r "s/#*\s*(firstEp\s*).*/\1$firstEp/" ${cfg_install_dir}/${configFile2} + if [ -f ${cfg_install_dir}/${configFile2} ]; then + ${csudo}sed -i -r "s/#*\s*(firstEp\s*).*/\1$firstEp/" ${cfg_install_dir}/${configFile2} + else + ${csudo}sed -i -r "s/#*\s*(firstEp\s*).*/\1$firstEp/" ${script_dir}/cfg/${configFile2} + fi break else break @@ -854,7 +879,7 @@ function updateProduct() { tar -zxf ${tarName} install_jemalloc - echo -e "${GREEN}Start to update ${productName2}...${NC}" + echo "Start to update ${productName2}..." # Stop the service if running if ps aux | grep -v grep | grep ${serverName2} &>/dev/null; then if ((${service_mod} == 0)); then @@ -958,7 +983,7 @@ function installProduct() { fi tar -zxf ${tarName} - echo -e "${GREEN}Start to install ${productName2}...${NC}" + echo "Start to install ${productName2}..." install_main_path diff --git a/packaging/tools/remove.sh b/packaging/tools/remove.sh index a32788bbd0..b83e8d74c9 100755 --- a/packaging/tools/remove.sh +++ b/packaging/tools/remove.sh @@ -113,8 +113,10 @@ function clean_bin() { # Remove link ${csudo}rm -f ${bin_link_dir}/${clientName} || : ${csudo}rm -f ${bin_link_dir}/${serverName} || : + echo "${serverName} is removed successfully" ${csudo}rm -f ${bin_link_dir}/udfd || : ${csudo}rm -f ${bin_link_dir}/${adapterName2} || : + echo "${adapterName2} is removed successfully" ${csudo}rm -f ${bin_link_dir}/${benchmarkName2} || : ${csudo}rm -f ${bin_link_dir}/${demoName2} || : ${csudo}rm -f ${bin_link_dir}/${dumpName2} || : @@ -175,7 +177,7 @@ function clean_log() { 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 "${taos_service_name} ${taos_service_name} is running, stopping it..." + echo "${taos_service_name} 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 @@ -183,7 +185,7 @@ function clean_service_on_systemd() { taosadapter_service_config="${service_config_dir}/${clientName2}adapter.service" if systemctl is-active --quiet ${taosadapter_service_name}; then - echo "${productName2} ${clientName2}Adapter is running, stopping it..." + echo "${clientName2}Adapter 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 @@ -200,7 +202,7 @@ function clean_service_on_systemd() { function clean_service_on_sysvinit() { if ps aux | grep -v grep | grep ${serverName} &>/dev/null; then - echo "${productName2} ${serverName2} is running, stopping it..." + echo "${serverName2} is running, stopping it..." ${csudo}service ${serverName} stop || : fi @@ -307,6 +309,71 @@ if [ "$osType" = "Darwin" ]; then ${csudo}rm -rf /Applications/TDengine.app fi +_kill_service_of() { + _service=$1 + pid=$(ps -ef | grep "$_service" | grep -v "grep" | awk '{print $2}') + if [ -n "$pid" ]; then + ${csudo}kill -9 $pid || : + fi +} + +_clean_service_on_systemd_of() { + _service=$1 + _service_config="${service_config_dir}/${_service}.service" + if systemctl is-active --quiet ${_service}; then + echo "taoskeeper is running, stopping it..." + ${csudo}systemctl stop ${_service} &>/dev/null || echo &>/dev/null + fi + ${csudo}systemctl disable ${_service} &>/dev/null || echo &>/dev/null + ${csudo}rm -f ${_service_config} +} +_clean_service_on_sysvinit_of() { + _service=$1 + if pidof ${_service} &>/dev/null; then + echo "${_service} is running, stopping it..." + ${csudo}service ${_service} stop || : + fi + if ((${initd_mod} == 1)); then + if [ -e ${service_config_dir}/${_service} ]; then + ${csudo}chkconfig --del ${_service} || : + fi + elif ((${initd_mod} == 2)); then + if [ -e ${service_config_dir}/${_service} ]; then + ${csudo}insserv -r ${_service} || : + fi + elif ((${initd_mod} == 3)); then + if [ -e ${service_config_dir}/${_service} ]; then + ${csudo}update-rc.d -f ${_service} remove || : + fi + fi + + ${csudo}rm -f ${service_config_dir}/${_service} || : + + if $(which init &>/dev/null); then + ${csudo}init q || : + fi +} + +_clean_service_of() { + _service=$1 + if ((${service_mod} == 0)); then + _clean_service_on_systemd_of $_service + elif ((${service_mod} == 1)); then + _clean_service_on_sysvinit_of $_service + else + _kill_service_of $_service + fi +} + +remove_taoskeeper() { + # remove taoskeeper bin + _clean_service_of taoskeeper + [ -e "${bin_link_dir}/taoskeeper" ] && ${csudo}rm -rf ${bin_link_dir}/taoskeeper + [ -e "${cfg_link_dir}/metrics.toml" ] || ${csudo}rm -rf ${cfg_link_dir}/metrics.toml + echo "taosKeeper is removed successfully!" +} +remove_taoskeeper + if [ "$verMode" == "cluster" ]; then uninstall_taosx fi