diff --git a/Jenkinsfile b/Jenkinsfile index 9d131d0ca500ef248740b5ce31fd92ce197b32f8..f2e3c1c4f6c3754f33f56575c4f6b89170e36948 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -450,7 +450,7 @@ pipeline { stage('test_b1_s2') { agent{label " slave2 || slave12 "} steps { - timeout(time: 55, unit: 'MINUTES'){ + timeout(time: 105, unit: 'MINUTES'){ pre_test() sh ''' rm -rf /var/lib/taos/* diff --git a/deps/jemalloc b/deps/jemalloc index ea6b3e973b477b8061e0076bb257dbd7f3faa756..9015e129bd7de389afa4196495451669700904d0 160000 --- a/deps/jemalloc +++ b/deps/jemalloc @@ -1 +1 @@ -Subproject commit ea6b3e973b477b8061e0076bb257dbd7f3faa756 +Subproject commit 9015e129bd7de389afa4196495451669700904d0 diff --git a/documentation20/cn/00.index/docs.md b/documentation20/cn/00.index/docs.md index d94a58eebb129e84137a8c55b1ca07be37ec15af..da990323cebd81feb089c354395af3ee90ee599a 100644 --- a/documentation20/cn/00.index/docs.md +++ b/documentation20/cn/00.index/docs.md @@ -83,9 +83,10 @@ TDengine是一个高效的存储、查询、分析时序大数据的平台,专 * [Windows客户端](https://www.taosdata.com/blog/2019/07/26/514.html):自行编译windows客户端,Windows环境的各种连接器都需要它 * [Rust Connector](/connector/rust): Rust语言下通过libtaos客户端或RESTful接口,连接TDengine服务器。 -## [TDengine 组件与工具](/tools/adapter) +## [TDengine 组件与工具](/cn/documentation/) -* [taosAdapter用户手册](/tools/adapter) +* [taosAdapter 用户手册](/tools/adapter) +* [TDinsight 用户手册](/tools/insight) ## [与其他工具的连接](/connections) diff --git a/documentation20/cn/09.connections/docs.md b/documentation20/cn/09.connections/docs.md index bc3259365d0b658184318e994ffd31a9e4ffee90..e2f921cc973c28f16f491705800012e1f6a6f074 100644 --- a/documentation20/cn/09.connections/docs.md +++ b/documentation20/cn/09.connections/docs.md @@ -14,7 +14,7 @@ TDengine 能够与开源数据可视化系统 [Grafana](https://www.grafana.com/ TDengine 的 Grafana 插件请从 下载。 ```bash -GF_VERSION=3.1.1 +GF_VERSION=3.1.3 wget https://github.com/taosdata/grafanaplugin/releases/download/v$GF_VERSION/tdengine-datasource-$GF_VERSION.zip ``` @@ -75,15 +75,7 @@ allow_loading_unsigned_plugins = tdengine-datasource #### 导入 Dashboard -我们提供一个 TDengine Dashboard 可以作为 TDengine 集群的监控可视化工具使用,见 [Grafana Dashboard 15146](https://grafana.com/grafana/dashboards/15146)。 - -点击左侧 `Import` 按钮,选择 **Grafana.com Dashboard**,j将id `15146` 填入并加载: - -![img](../images/connections/import_dashboard1.jpg) - -导入完成之后可看到如下效果: - -![img](../images/connections/dashboard-15146.png) +在 2.3.3.0 及以上版本,您可以导入 TDinsight Dashboard (Grafana Dashboard ID: [15167](https://grafana.com/grafana/dashboards/15167)) 作为 TDengine 集群的监控可视化工具。安装和使用说明请见 [TDinsight 用户手册](https://www.taosdata.com/cn/documentation/tools/insight)。 ## MATLAB diff --git a/documentation20/en/00.index/docs.md b/documentation20/en/00.index/docs.md index 28905c340a99223e480603ca3ba6151772bada47..ff494a2bd6f3dd63dc9926e3200c1f6214ca9ae1 100644 --- a/documentation20/en/00.index/docs.md +++ b/documentation20/en/00.index/docs.md @@ -79,9 +79,10 @@ TDengine is a highly efficient platform to store, query, and analyze time-series - [Windows Client](https://www.taosdata.com/blog/2019/07/26/514.html): compile your own Windows client, which is required by various connectors on the Windows environment - [Rust Connector](/connector/rust): A taosc/RESTful API based TDengine client for Rust -## [Components and Tools](/tools/adapter) +## [Components and Tools](/cn/documentation/) -* [taosAdapter](/tools/adapter) +* [taosAdapter User Manual](/tools/adapter) +* [TDinsight User Manual](/tools/insight) ## [Connections with Other Tools](/connections) diff --git a/documentation20/en/09.connections/docs.md b/documentation20/en/09.connections/docs.md index b56458d351d23a2b61f88cfdf7dc64dc8043a295..f5af01d9b189d20facdd3c0702d72f256a2b4d8e 100644 --- a/documentation20/en/09.connections/docs.md +++ b/documentation20/en/09.connections/docs.md @@ -15,7 +15,7 @@ https://grafana.com/grafana/download. Download grafana plugin from . ```bash -GF_VERSION=3.1.1 +GF_VERSION=3.1.3 wget https://github.com/taosdata/grafanaplugin/releases/download/v$GF_VERSION/tdengine-datasource-$GF_VERSION.zip ``` @@ -69,15 +69,7 @@ According to the default prompt, query the average system memory usage at the sp #### Import Dashboard -We provide an example dashboard [Grafana Dashboard 15146](https://grafana.com/grafana/dashboards/15146)。 - -Click the `Import` button on the left panel and load the grafana id: - -![img](../images/connections/import_dashboard1.jpg) - -You can see as follows after Dashboard imported. - -![img](../images/connections/dashboard-15146.png) +We provide a TDinsight dashboard (via Grafana dashboard id: [15167](https://grafana.com/grafana/dashboards/15167)) for TDengine cluster monitoring since TDengine 2.3.3.x . Please refer to [TDinsight User Manual](https://www.taosdata.com/en/documentation/tools/insight) for the details. ## MATLAB diff --git a/packaging/check_package.sh b/packaging/check_package.sh index e625f90912825f30ba279ecf6dbe59ff7dade97f..81abff57a586d116ead0137f96697ece04250d6b 100755 --- a/packaging/check_package.sh +++ b/packaging/check_package.sh @@ -50,7 +50,7 @@ NC='\033[0m' csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi # ============================= get input parameters ================================================= @@ -85,7 +85,7 @@ done function kill_process() { pid=$(ps -ef | grep "$1" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } diff --git a/packaging/deb/DEBIAN/postinst b/packaging/deb/DEBIAN/postinst index 556e757c2bfced34c43283c0de39baaacb95003f..2638f096250b8fa52277573f14a6f0f07b335b32 100644 --- a/packaging/deb/DEBIAN/postinst +++ b/packaging/deb/DEBIAN/postinst @@ -5,9 +5,9 @@ insmetaPath="/usr/local/taos/script" csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi -${csudo} chmod -R 744 ${insmetaPath} +${csudo}chmod -R 744 ${insmetaPath} cd ${insmetaPath} -${csudo} ./post.sh +${csudo}./post.sh diff --git a/packaging/deb/DEBIAN/preinst b/packaging/deb/DEBIAN/preinst index 4b8b72e9abd9e12d9f669cf5658be2468ebab40b..5217a8229571bf993c6c3df8f82beb1ed67c3e96 100644 --- a/packaging/deb/DEBIAN/preinst +++ b/packaging/deb/DEBIAN/preinst @@ -2,19 +2,19 @@ csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi # Stop the service if running if pidof taosd &> /dev/null; then if pidof systemd &> /dev/null; then - ${csudo} systemctl stop taosd || : + ${csudo}systemctl stop taosd || : elif $(which service &> /dev/null); then - ${csudo} service taosd stop || : + ${csudo}service taosd stop || : else pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi fi echo "Stop taosd service success!" @@ -25,16 +25,16 @@ fi cfg_install_dir="/etc/taos" install_main_dir="/usr/local/taos" if [ -f "${install_main_dir}/taos.cfg" ]; then - ${csudo} rm -f ${install_main_dir}/cfg/taos.cfg || : + ${csudo}rm -f ${install_main_dir}/cfg/taos.cfg || : fi if [ -f "${install_main_dir}/taosadapter.toml" ]; then - ${csudo} rm -f ${install_main_dir}/cfg/taosadapter.toml || : + ${csudo}rm -f ${install_main_dir}/cfg/taosadapter.toml || : fi if [ -f "${install_main_dir}/taosadapter.service" ]; then - ${csudo} rm -f ${install_main_dir}/cfg/taosadapter.service || : + ${csudo}rm -f ${install_main_dir}/cfg/taosadapter.service || : fi # there can not libtaos.so*, otherwise ln -s error -${csudo} rm -f ${install_main_dir}/driver/libtaos* || : +${csudo}rm -f ${install_main_dir}/driver/libtaos* || : diff --git a/packaging/deb/DEBIAN/prerm b/packaging/deb/DEBIAN/prerm index b6979cf26435e4c4b0d19f5c93bb92cda988b3bf..c01db74701f99e52cc45b589d8fe7b07c4c8afe1 100644 --- a/packaging/deb/DEBIAN/prerm +++ b/packaging/deb/DEBIAN/prerm @@ -4,15 +4,15 @@ insmetaPath="/usr/local/taos/script" csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi -${csudo} chmod -R 744 ${insmetaPath} || : +${csudo}chmod -R 744 ${insmetaPath} || : #cd ${insmetaPath} -#${csudo} ./preun.sh +#${csudo}./preun.sh if [ -f ${insmetaPath}/preun.sh ]; then cd ${insmetaPath} - ${csudo} ./preun.sh + ${csudo}./preun.sh else bin_link_dir="/usr/bin" lib_link_dir="/usr/lib" @@ -23,20 +23,20 @@ else cfg_link_dir="/usr/local/taos/cfg" # Remove all links - ${csudo} rm -f ${bin_link_dir}/taos || : - ${csudo} rm -f ${bin_link_dir}/taosd || : - ${csudo} rm -f ${bin_link_dir}/taosadapter || : - ${csudo} rm -f ${bin_link_dir}/taosdemo || : - ${csudo} rm -f ${cfg_link_dir}/* || : - ${csudo} rm -f ${inc_link_dir}/taos.h || : - ${csudo} rm -f ${lib_link_dir}/libtaos.* || : + ${csudo}rm -f ${bin_link_dir}/taos || : + ${csudo}rm -f ${bin_link_dir}/taosd || : + ${csudo}rm -f ${bin_link_dir}/taosadapter || : + ${csudo}rm -f ${bin_link_dir}/taosdemo || : + ${csudo}rm -f ${cfg_link_dir}/* || : + ${csudo}rm -f ${inc_link_dir}/taos.h || : + ${csudo}rm -f ${lib_link_dir}/libtaos.* || : - ${csudo} rm -f ${log_link_dir} || : - ${csudo} rm -f ${data_link_dir} || : + ${csudo}rm -f ${log_link_dir} || : + ${csudo}rm -f ${data_link_dir} || : pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi fi diff --git a/packaging/release.sh b/packaging/release.sh index ca8715f68430fc08b86f008936ddfc9409ae58a8..fd2266792ebf9ed419ef3dee1ee6e146e4e9534f 100755 --- a/packaging/release.sh +++ b/packaging/release.sh @@ -113,7 +113,7 @@ fi csudo="" #if command -v sudo > /dev/null; then -# csudo="sudo" +# csudo="sudo " #fi function is_valid_version() { @@ -183,11 +183,11 @@ cd ${curr_dir} # 2. cmake executable file compile_dir="${top_dir}/debug" if [ -d ${compile_dir} ]; then - ${csudo} rm -rf ${compile_dir} + ${csudo}rm -rf ${compile_dir} fi if [ "$osType" != "Darwin" ]; then - ${csudo} mkdir -p ${compile_dir} + ${csudo}mkdir -p ${compile_dir} else mkdir -p ${compile_dir} fi @@ -496,9 +496,9 @@ fi if [[ "$allocator" == "jemalloc" ]]; then # jemalloc need compile first, so disable parallel build - make -j 8 && ${csudo} make install + make -j 8 && ${csudo}make install else - make -j 8 && ${csudo} make install + make -j 8 && ${csudo}make install fi cd ${curr_dir} @@ -512,11 +512,11 @@ if [ "$osType" != "Darwin" ]; then echo "====do deb package for the ubuntu system====" output_dir="${top_dir}/debs" if [ -d ${output_dir} ]; then - ${csudo} rm -rf ${output_dir} + ${csudo}rm -rf ${output_dir} fi - ${csudo} mkdir -p ${output_dir} + ${csudo}mkdir -p ${output_dir} cd ${script_dir}/deb - ${csudo} ./makedeb.sh ${compile_dir} ${output_dir} ${verNumber} ${cpuType} ${osType} ${verMode} ${verType} + ${csudo}./makedeb.sh ${compile_dir} ${output_dir} ${verNumber} ${cpuType} ${osType} ${verMode} ${verType} if [[ "$pagMode" == "full" ]]; then if [ -d ${top_dir}/src/kit/taos-tools/packaging/deb ]; then @@ -524,7 +524,7 @@ if [ "$osType" != "Darwin" ]; then [ -z "$taos_tools_ver" ] && taos_tools_ver="0.1.0" taos_tools_ver=$(git describe --tags|sed -e 's/ver-//g'|awk -F '-' '{print $1}') - ${csudo} ./make-taos-tools-deb.sh ${top_dir} \ + ${csudo}./make-taos-tools-deb.sh ${top_dir} \ ${compile_dir} ${output_dir} ${taos_tools_ver} ${cpuType} ${osType} ${verMode} ${verType} fi fi @@ -537,11 +537,11 @@ if [ "$osType" != "Darwin" ]; then echo "====do rpm package for the centos system====" output_dir="${top_dir}/rpms" if [ -d ${output_dir} ]; then - ${csudo} rm -rf ${output_dir} + ${csudo}rm -rf ${output_dir} fi - ${csudo} mkdir -p ${output_dir} + ${csudo}mkdir -p ${output_dir} cd ${script_dir}/rpm - ${csudo} ./makerpm.sh ${compile_dir} ${output_dir} ${verNumber} ${cpuType} ${osType} ${verMode} ${verType} + ${csudo}./makerpm.sh ${compile_dir} ${output_dir} ${verNumber} ${cpuType} ${osType} ${verMode} ${verType} if [[ "$pagMode" == "full" ]]; then if [ -d ${top_dir}/src/kit/taos-tools/packaging/rpm ]; then @@ -549,7 +549,7 @@ if [ "$osType" != "Darwin" ]; then [ -z "$taos_tools_ver" ] && taos_tools_ver="0.1.0" taos_tools_ver=$(git describe --tags|sed -e 's/ver-//g'|awk -F '-' '{print $1}'|sed -e 's/-/_/g') - ${csudo} ./make-taos-tools-rpm.sh ${top_dir} \ + ${csudo}./make-taos-tools-rpm.sh ${top_dir} \ ${compile_dir} ${output_dir} ${taos_tools_ver} ${cpuType} ${osType} ${verMode} ${verType} fi fi @@ -562,29 +562,29 @@ if [ "$osType" != "Darwin" ]; then cd ${script_dir}/tools if [[ "$dbName" == "taos" ]]; then - ${csudo} ./makepkg.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${verNumberComp} - ${csudo} ./makeclient.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} - ${csudo} ./makearbi.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} + ${csudo}./makepkg.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${verNumberComp} + ${csudo}./makeclient.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} + ${csudo}./makearbi.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} elif [[ "$dbName" == "tq" ]]; then - ${csudo} ./makepkg_tq.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${dbName} ${verNumberComp} - ${csudo} ./makeclient_tq.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${dbName} - ${csudo} ./makearbi_tq.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} + ${csudo}./makepkg_tq.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${dbName} ${verNumberComp} + ${csudo}./makeclient_tq.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${dbName} + ${csudo}./makearbi_tq.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} elif [[ "$dbName" == "pro" ]]; then - ${csudo} ./makepkg_pro.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${dbName} ${verNumberComp} - ${csudo} ./makeclient_pro.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${dbName} - ${csudo} ./makearbi_pro.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} + ${csudo}./makepkg_pro.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${dbName} ${verNumberComp} + ${csudo}./makeclient_pro.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${dbName} + ${csudo}./makearbi_pro.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} elif [[ "$dbName" == "kh" ]]; then - ${csudo} ./makepkg_kh.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${dbName} ${verNumberComp} - ${csudo} ./makeclient_kh.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${dbName} - ${csudo} ./makearbi_kh.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} + ${csudo}./makepkg_kh.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${dbName} ${verNumberComp} + ${csudo}./makeclient_kh.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${dbName} + ${csudo}./makearbi_kh.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} elif [[ "$dbName" == "jh" ]]; then - ${csudo} ./makepkg_jh.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${dbName} ${verNumberComp} - ${csudo} ./makeclient_jh.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${dbName} - ${csudo} ./makearbi_jh.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} + ${csudo}./makepkg_jh.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${dbName} ${verNumberComp} + ${csudo}./makeclient_jh.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${dbName} + ${csudo}./makearbi_jh.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} else - ${csudo} ./makepkg_power.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${dbName} ${verNumberComp} - ${csudo} ./makeclient_power.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${dbName} - ${csudo} ./makearbi_power.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} + ${csudo}./makepkg_power.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${dbName} ${verNumberComp} + ${csudo}./makeclient_power.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${dbName} + ${csudo}./makearbi_power.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} fi else # only make client for Darwin diff --git a/packaging/rpm/makerpm.sh b/packaging/rpm/makerpm.sh index b4cf3d1450619f6a43a5303afa45f71c4402c2e7..4ac67ec754ce230f9a777570c42a9300c757978d 100755 --- a/packaging/rpm/makerpm.sh +++ b/packaging/rpm/makerpm.sh @@ -28,7 +28,7 @@ echo "spec_file: ${spec_file}" csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi function cp_rpm_package() { @@ -49,17 +49,17 @@ function cp_rpm_package() { } if [ -d ${pkg_dir} ]; then - ${csudo} rm -rf ${pkg_dir} + ${csudo}rm -rf ${pkg_dir} fi -${csudo} mkdir -p ${pkg_dir} +${csudo}mkdir -p ${pkg_dir} cd ${pkg_dir} -${csudo} mkdir -p BUILD BUILDROOT RPMS SOURCES SPECS SRPMS +${csudo}mkdir -p BUILD BUILDROOT RPMS SOURCES SPECS SRPMS -${csudo} rpmbuild --define="_version ${tdengine_ver}" --define="_topdir ${pkg_dir}" --define="_compiledir ${compile_dir}" -bb ${spec_file} +${csudo}rpmbuild --define="_version ${tdengine_ver}" --define="_topdir ${pkg_dir}" --define="_compiledir ${compile_dir}" -bb ${spec_file} # copy rpm package to output_dir, and modify package name, then clean temp dir -#${csudo} cp -rf RPMS/* ${output_dir} +#${csudo}cp -rf RPMS/* ${output_dir} cp_rpm_package ${pkg_dir}/RPMS @@ -84,4 +84,4 @@ fi mv ${output_dir}/TDengine-${tdengine_ver}.rpm ${output_dir}/${rpmname} cd .. -${csudo} rm -rf ${pkg_dir} +${csudo}rm -rf ${pkg_dir} diff --git a/packaging/rpm/tdengine.spec b/packaging/rpm/tdengine.spec index e1a8a9f9f6aee3ebe7fbcdacd579235cde7165e8..3a8153ff2bf791d0660cd81c2081af829a79e751 100644 --- a/packaging/rpm/tdengine.spec +++ b/packaging/rpm/tdengine.spec @@ -128,19 +128,19 @@ fi %pre csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi # Stop the service if running if pidof taosd &> /dev/null; then if pidof systemd &> /dev/null; then - ${csudo} systemctl stop taosd || : + ${csudo}systemctl stop taosd || : elif $(which service &> /dev/null); then - ${csudo} service taosd stop || : + ${csudo}service taosd stop || : else pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi fi echo "Stop taosd service success!" @@ -148,40 +148,40 @@ if pidof taosd &> /dev/null; then fi # if taos.cfg already exist, remove it if [ -f %{cfg_install_dir}/taos.cfg ]; then - ${csudo} rm -f %{cfg_install_dir}/cfg/taos.cfg || : + ${csudo}rm -f %{cfg_install_dir}/cfg/taos.cfg || : fi # if taosadapter.toml already exist, remove it if [ -f %{cfg_install_dir}/taosadapter.toml ]; then - ${csudo} rm -f %{cfg_install_dir}/cfg/taosadapter.toml || : + ${csudo}rm -f %{cfg_install_dir}/cfg/taosadapter.toml || : fi # there can not libtaos.so*, otherwise ln -s error -${csudo} rm -f %{homepath}/driver/libtaos* || : +${csudo}rm -f %{homepath}/driver/libtaos* || : #Scripts executed after installation %post csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi cd %{homepath}/script -${csudo} ./post.sh +${csudo}./post.sh # Scripts executed before uninstall %preun csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi # only remove package to call preun.sh, not but update(2) if [ $1 -eq 0 ];then #cd %{homepath}/script - #${csudo} ./preun.sh + #${csudo}./preun.sh if [ -f %{homepath}/script/preun.sh ]; then cd %{homepath}/script - ${csudo} ./preun.sh + ${csudo}./preun.sh else bin_link_dir="/usr/bin" lib_link_dir="/usr/lib" @@ -192,21 +192,21 @@ if [ $1 -eq 0 ];then cfg_link_dir="/usr/local/taos/cfg" # Remove all links - ${csudo} rm -f ${bin_link_dir}/taos || : - ${csudo} rm -f ${bin_link_dir}/taosd || : - ${csudo} rm -f ${bin_link_dir}/taosadapter || : - ${csudo} rm -f ${cfg_link_dir}/* || : - ${csudo} rm -f ${inc_link_dir}/taos.h || : - ${csudo} rm -f ${inc_link_dir}/taosdef.h || : - ${csudo} rm -f ${inc_link_dir}/taoserror.h || : - ${csudo} rm -f ${lib_link_dir}/libtaos.* || : - - ${csudo} rm -f ${log_link_dir} || : - ${csudo} rm -f ${data_link_dir} || : + ${csudo}rm -f ${bin_link_dir}/taos || : + ${csudo}rm -f ${bin_link_dir}/taosd || : + ${csudo}rm -f ${bin_link_dir}/taosadapter || : + ${csudo}rm -f ${cfg_link_dir}/* || : + ${csudo}rm -f ${inc_link_dir}/taos.h || : + ${csudo}rm -f ${inc_link_dir}/taosdef.h || : + ${csudo}rm -f ${inc_link_dir}/taoserror.h || : + ${csudo}rm -f ${lib_link_dir}/libtaos.* || : + + ${csudo}rm -f ${log_link_dir} || : + ${csudo}rm -f ${data_link_dir} || : pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi fi fi @@ -218,9 +218,9 @@ fi %clean csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi -${csudo} rm -rf %{buildroot} +${csudo}rm -rf %{buildroot} #Specify the files to be packaged %files diff --git a/packaging/tools/install.sh b/packaging/tools/install.sh index 6d007c0dd1527c281b09bf1f3623eab873b235d6..511b3003e857ca410e0f91bf4af4d268a32adace 100755 --- a/packaging/tools/install.sh +++ b/packaging/tools/install.sh @@ -50,7 +50,7 @@ NC='\033[0m' csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi update_flag=0 @@ -157,103 +157,103 @@ done function kill_process() { pid=$(ps -ef | grep "$1" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function install_main_path() { #create install main dir and all sub dir - ${csudo} rm -rf ${install_main_dir} || : - ${csudo} mkdir -p ${install_main_dir} - ${csudo} mkdir -p ${install_main_dir}/cfg - ${csudo} mkdir -p ${install_main_dir}/bin - ${csudo} mkdir -p ${install_main_dir}/connector - ${csudo} mkdir -p ${install_main_dir}/driver - ${csudo} mkdir -p ${install_main_dir}/examples - ${csudo} mkdir -p ${install_main_dir}/include - ${csudo} mkdir -p ${install_main_dir}/init.d + ${csudo}rm -rf ${install_main_dir} || : + ${csudo}mkdir -p ${install_main_dir} + ${csudo}mkdir -p ${install_main_dir}/cfg + ${csudo}mkdir -p ${install_main_dir}/bin + ${csudo}mkdir -p ${install_main_dir}/connector + ${csudo}mkdir -p ${install_main_dir}/driver + ${csudo}mkdir -p ${install_main_dir}/examples + ${csudo}mkdir -p ${install_main_dir}/include + ${csudo}mkdir -p ${install_main_dir}/init.d if [ "$verMode" == "cluster" ]; then - ${csudo} mkdir -p ${nginx_dir} + ${csudo}mkdir -p ${nginx_dir} fi if [[ -e ${script_dir}/email ]]; then - ${csudo} cp ${script_dir}/email ${install_main_dir}/ ||: + ${csudo}cp ${script_dir}/email ${install_main_dir}/ ||: fi } function install_bin() { # Remove links - ${csudo} rm -f ${bin_link_dir}/taos || : - ${csudo} rm -f ${bin_link_dir}/taosd || : - ${csudo} rm -f ${bin_link_dir}/taosadapter || : - ${csudo} rm -f ${bin_link_dir}/taosdemo || : - ${csudo} rm -f ${bin_link_dir}/taosdump || : - ${csudo} rm -f ${bin_link_dir}/rmtaos || : - ${csudo} rm -f ${bin_link_dir}/tarbitrator || : - ${csudo} rm -f ${bin_link_dir}/set_core || : - ${csudo} rm -f ${bin_link_dir}/run_taosd.sh || : - - ${csudo} cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo} chmod 0555 ${install_main_dir}/bin/* + ${csudo}rm -f ${bin_link_dir}/taos || : + ${csudo}rm -f ${bin_link_dir}/taosd || : + ${csudo}rm -f ${bin_link_dir}/taosadapter || : + ${csudo}rm -f ${bin_link_dir}/taosdemo || : + ${csudo}rm -f ${bin_link_dir}/taosdump || : + ${csudo}rm -f ${bin_link_dir}/rmtaos || : + ${csudo}rm -f ${bin_link_dir}/tarbitrator || : + ${csudo}rm -f ${bin_link_dir}/set_core || : + ${csudo}rm -f ${bin_link_dir}/run_taosd.sh || : + + ${csudo}cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo}chmod 0555 ${install_main_dir}/bin/* #Make link - [ -x ${install_main_dir}/bin/taos ] && ${csudo} ln -s ${install_main_dir}/bin/taos ${bin_link_dir}/taos || : - [ -x ${install_main_dir}/bin/taosd ] && ${csudo} ln -s ${install_main_dir}/bin/taosd ${bin_link_dir}/taosd || : - [ -x ${install_main_dir}/bin/taosadapter ] && ${csudo} ln -s ${install_main_dir}/bin/taosadapter ${bin_link_dir}/taosadapter || : - [ -x ${install_main_dir}/bin/taosdemo ] && ${csudo} ln -s ${install_main_dir}/bin/taosdemo ${bin_link_dir}/taosdemo || : - [ -x ${install_main_dir}/bin/taosdump ] && ${csudo} ln -s ${install_main_dir}/bin/taosdump ${bin_link_dir}/taosdump || : - [ -x ${install_main_dir}/bin/remove.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove.sh ${bin_link_dir}/rmtaos || : - [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo} ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : - [ -x ${install_main_dir}/bin/run_taosd.sh ] && ${csudo} ln -s ${install_main_dir}/bin/run_taosd.sh ${bin_link_dir}/run_taosd.sh || : - [ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo} ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || : + [ -x ${install_main_dir}/bin/taos ] && ${csudo}ln -s ${install_main_dir}/bin/taos ${bin_link_dir}/taos || : + [ -x ${install_main_dir}/bin/taosd ] && ${csudo}ln -s ${install_main_dir}/bin/taosd ${bin_link_dir}/taosd || : + [ -x ${install_main_dir}/bin/taosadapter ] && ${csudo}ln -s ${install_main_dir}/bin/taosadapter ${bin_link_dir}/taosadapter || : + [ -x ${install_main_dir}/bin/taosdemo ] && ${csudo}ln -s ${install_main_dir}/bin/taosdemo ${bin_link_dir}/taosdemo || : + [ -x ${install_main_dir}/bin/taosdump ] && ${csudo}ln -s ${install_main_dir}/bin/taosdump ${bin_link_dir}/taosdump || : + [ -x ${install_main_dir}/bin/remove.sh ] && ${csudo}ln -s ${install_main_dir}/bin/remove.sh ${bin_link_dir}/rmtaos || : + [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo}ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : + [ -x ${install_main_dir}/bin/run_taosd.sh ] && ${csudo}ln -s ${install_main_dir}/bin/run_taosd.sh ${bin_link_dir}/run_taosd.sh || : + [ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo}ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || : if [ "$verMode" == "cluster" ]; then - ${csudo} cp -r ${script_dir}/nginxd/* ${nginx_dir} && ${csudo} chmod 0555 ${nginx_dir}/* - ${csudo} mkdir -p ${nginx_dir}/logs - ${csudo} chmod 777 ${nginx_dir}/sbin/nginx + ${csudo}cp -r ${script_dir}/nginxd/* ${nginx_dir} && ${csudo}chmod 0555 ${nginx_dir}/* + ${csudo}mkdir -p ${nginx_dir}/logs + ${csudo}chmod 777 ${nginx_dir}/sbin/nginx fi } function install_lib() { # Remove links - ${csudo} rm -f ${lib_link_dir}/libtaos.* || : - ${csudo} rm -f ${lib64_link_dir}/libtaos.* || : - #${csudo} rm -rf ${v15_java_app_dir} || : - ${csudo} cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo} chmod 777 ${install_main_dir}/driver/* + ${csudo}rm -f ${lib_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : + #${csudo}rm -rf ${v15_java_app_dir} || : + ${csudo}cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo}chmod 777 ${install_main_dir}/driver/* - ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 - ${csudo} ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so + ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 + ${csudo}ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so if [[ -d ${lib64_link_dir} && ! -e ${lib64_link_dir}/libtaos.so ]]; then - ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 || : - ${csudo} ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || : + ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 || : + ${csudo}ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || : fi #if [ "$verMode" == "cluster" ]; then # # Compatible with version 1.5 - # ${csudo} mkdir -p ${v15_java_app_dir} - # ${csudo} ln -s ${install_main_dir}/connector/taos-jdbcdriver-1.0.2-dist.jar ${v15_java_app_dir}/JDBCDriver-1.0.2-dist.jar - # ${csudo} chmod 777 ${v15_java_app_dir} || : + # ${csudo}mkdir -p ${v15_java_app_dir} + # ${csudo}ln -s ${install_main_dir}/connector/taos-jdbcdriver-1.0.2-dist.jar ${v15_java_app_dir}/JDBCDriver-1.0.2-dist.jar + # ${csudo}chmod 777 ${v15_java_app_dir} || : #fi - ${csudo} ldconfig + ${csudo}ldconfig } function install_avro() { if [ "$osType" != "Darwin" ]; then avro_dir=${script_dir}/avro if [ -f "${avro_dir}/lib/libavro.so.23.0.0" ] && [ -d /usr/local/$1 ]; then - ${csudo} /usr/bin/install -c -d /usr/local/$1 - ${csudo} /usr/bin/install -c -m 755 ${avro_dir}/lib/libavro.so.23.0.0 /usr/local/$1 - ${csudo} ln -sf /usr/local/$1/libavro.so.23.0.0 /usr/local/$1/libavro.so.23 - ${csudo} ln -sf /usr/local/$1/libavro.so.23 /usr/local/$1/libavro.so + ${csudo}/usr/bin/install -c -d /usr/local/$1 + ${csudo}/usr/bin/install -c -m 755 ${avro_dir}/lib/libavro.so.23.0.0 /usr/local/$1 + ${csudo}ln -sf /usr/local/$1/libavro.so.23.0.0 /usr/local/$1/libavro.so.23 + ${csudo}ln -sf /usr/local/$1/libavro.so.23 /usr/local/$1/libavro.so - ${csudo} /usr/bin/install -c -d /usr/local/$1 + ${csudo}/usr/bin/install -c -d /usr/local/$1 [ -f ${avro_dir}/lib/libavro.a ] && - ${csudo} /usr/bin/install -c -m 755 ${avro_dir}/lib/libavro.a /usr/local/$1 + ${csudo}/usr/bin/install -c -m 755 ${avro_dir}/lib/libavro.a /usr/local/$1 if [ -d /etc/ld.so.conf.d ]; then - echo "/usr/local/$1" | ${csudo} tee /etc/ld.so.conf.d/libavro.conf > /dev/null || echo -e "failed to write /etc/ld.so.conf.d/libavro.conf" - ${csudo} ldconfig + echo "/usr/local/$1" | ${csudo}tee /etc/ld.so.conf.d/libavro.conf > /dev/null || echo -e "failed to write /etc/ld.so.conf.d/libavro.conf" + ${csudo}ldconfig else echo "/etc/ld.so.conf.d not found!" fi @@ -265,49 +265,49 @@ function install_jemalloc() { jemalloc_dir=${script_dir}/jemalloc if [ -d ${jemalloc_dir} ]; then - ${csudo} /usr/bin/install -c -d /usr/local/bin + ${csudo}/usr/bin/install -c -d /usr/local/bin if [ -f ${jemalloc_dir}/bin/jemalloc-config ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc-config /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc-config /usr/local/bin fi if [ -f ${jemalloc_dir}/bin/jemalloc.sh ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc.sh /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc.sh /usr/local/bin fi if [ -f ${jemalloc_dir}/bin/jeprof ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jeprof /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jeprof /usr/local/bin fi if [ -f ${jemalloc_dir}/include/jemalloc/jemalloc.h ]; then - ${csudo} /usr/bin/install -c -d /usr/local/include/jemalloc - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/include/jemalloc/jemalloc.h /usr/local/include/jemalloc + ${csudo}/usr/bin/install -c -d /usr/local/include/jemalloc + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/include/jemalloc/jemalloc.h /usr/local/include/jemalloc fi if [ -f ${jemalloc_dir}/lib/libjemalloc.so.2 ]; then - ${csudo} /usr/bin/install -c -d /usr/local/lib - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.so.2 /usr/local/lib - ${csudo} ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so - ${csudo} /usr/bin/install -c -d /usr/local/lib + ${csudo}/usr/bin/install -c -d /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.so.2 /usr/local/lib + ${csudo}ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so + ${csudo}/usr/bin/install -c -d /usr/local/lib if [ -f ${jemalloc_dir}/lib/libjemalloc.a ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.a /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.a /usr/local/lib fi if [ -f ${jemalloc_dir}/lib/libjemalloc_pic.a ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc_pic.a /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc_pic.a /usr/local/lib fi if [ -f ${jemalloc_dir}/lib/libjemalloc_pic.a ]; then - ${csudo} /usr/bin/install -c -d /usr/local/lib/pkgconfig - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/lib/pkgconfig/jemalloc.pc /usr/local/lib/pkgconfig + ${csudo}/usr/bin/install -c -d /usr/local/lib/pkgconfig + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/lib/pkgconfig/jemalloc.pc /usr/local/lib/pkgconfig fi fi if [ -f ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html ]; then - ${csudo} /usr/bin/install -c -d /usr/local/share/doc/jemalloc - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html /usr/local/share/doc/jemalloc + ${csudo}/usr/bin/install -c -d /usr/local/share/doc/jemalloc + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html /usr/local/share/doc/jemalloc fi if [ -f ${jemalloc_dir}/share/man/man3/jemalloc.3 ]; then - ${csudo} /usr/bin/install -c -d /usr/local/share/man/man3 - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/share/man/man3/jemalloc.3 /usr/local/share/man/man3 + ${csudo}/usr/bin/install -c -d /usr/local/share/man/man3 + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/share/man/man3/jemalloc.3 /usr/local/share/man/man3 fi if [ -d /etc/ld.so.conf.d ]; then - echo "/usr/local/lib" | ${csudo} tee /etc/ld.so.conf.d/jemalloc.conf > /dev/null || echo -e "failed to write /etc/ld.so.conf.d/jemalloc.conf" - ${csudo} ldconfig + echo "/usr/local/lib" | ${csudo}tee /etc/ld.so.conf.d/jemalloc.conf > /dev/null || echo -e "failed to write /etc/ld.so.conf.d/jemalloc.conf" + ${csudo}ldconfig else echo "/etc/ld.so.conf.d not found!" fi @@ -315,11 +315,11 @@ function install_jemalloc() { } function install_header() { - ${csudo} rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h || : - ${csudo} cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo} chmod 644 ${install_main_dir}/include/* - ${csudo} ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h - ${csudo} ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h - ${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h + ${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h || : + ${csudo}cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo}chmod 644 ${install_main_dir}/include/* + ${csudo}ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h + ${csudo}ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h + ${csudo}ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h } function add_newHostname_to_hosts() { @@ -335,7 +335,7 @@ function add_newHostname_to_hosts() { return fi done - ${csudo} echo "127.0.0.1 $1" >> /etc/hosts ||: + ${csudo}echo "127.0.0.1 $1" >> /etc/hosts ||: } function set_hostname() { @@ -349,7 +349,7 @@ function set_hostname() { fi done - ${csudo} hostname $newHostname ||: + ${csudo}hostname $newHostname ||: retval=`echo $?` if [[ $retval != 0 ]]; then echo @@ -362,15 +362,15 @@ function set_hostname() { #ubuntu/centos /etc/hostname if [[ -e /etc/hostname ]]; then - ${csudo} echo $newHostname > /etc/hostname ||: + ${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 ||: + ${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}/taos.cfg + ${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$newHostname/" ${cfg_install_dir}/taos.cfg serverFqdn=$newHostname if [[ -e /etc/hosts ]]; then @@ -405,7 +405,7 @@ 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}/taos.cfg + ${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${cfg_install_dir}/taos.cfg serverFqdn=$localFqdn echo return @@ -427,7 +427,7 @@ function set_ipAsFqdn() { 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}/taos.cfg + ${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${cfg_install_dir}/taos.cfg serverFqdn=$localFqdn break fi @@ -475,32 +475,32 @@ function local_fqdn_check() { function install_taosadapter_config() { if [ ! -f "${cfg_install_dir}/taosadapter.toml" ]; then - ${csudo} mkdir -p ${cfg_install_dir} - [ -f ${script_dir}/cfg/taosadapter.toml ] && ${csudo} cp ${script_dir}/cfg/taosadapter.toml ${cfg_install_dir} - [ -f ${cfg_install_dir}/taosadapter.toml ] && ${csudo} chmod 644 ${cfg_install_dir}/taosadapter.toml + ${csudo}mkdir -p ${cfg_install_dir} + [ -f ${script_dir}/cfg/taosadapter.toml ] && ${csudo}cp ${script_dir}/cfg/taosadapter.toml ${cfg_install_dir} + [ -f ${cfg_install_dir}/taosadapter.toml ] && ${csudo}chmod 644 ${cfg_install_dir}/taosadapter.toml fi [ -f ${script_dir}/cfg/taosadapter.toml ] && - ${csudo} cp -f ${script_dir}/cfg/taosadapter.toml ${cfg_install_dir}/taosadapter.toml.new + ${csudo}cp -f ${script_dir}/cfg/taosadapter.toml ${cfg_install_dir}/taosadapter.toml.new [ -f ${cfg_install_dir}/taosadapter.toml ] && - ${csudo} ln -s ${cfg_install_dir}/taosadapter.toml ${install_main_dir}/cfg/taosadapter.toml + ${csudo}ln -s ${cfg_install_dir}/taosadapter.toml ${install_main_dir}/cfg/taosadapter.toml [ ! -z $1 ] && return 0 || : # only install client } function install_config() { - #${csudo} rm -f ${install_main_dir}/cfg/taos.cfg || : + #${csudo}rm -f ${install_main_dir}/cfg/taos.cfg || : if [ ! -f "${cfg_install_dir}/taos.cfg" ]; then - ${csudo} mkdir -p ${cfg_install_dir} - [ -f ${script_dir}/cfg/taos.cfg ] && ${csudo} cp ${script_dir}/cfg/taos.cfg ${cfg_install_dir} - ${csudo} chmod 644 ${cfg_install_dir}/* + ${csudo}mkdir -p ${cfg_install_dir} + [ -f ${script_dir}/cfg/taos.cfg ] && ${csudo}cp ${script_dir}/cfg/taos.cfg ${cfg_install_dir} + ${csudo}chmod 644 ${cfg_install_dir}/* fi - ${csudo} cp -f ${script_dir}/cfg/taos.cfg ${cfg_install_dir}/taos.cfg.new - ${csudo} ln -s ${cfg_install_dir}/taos.cfg ${install_main_dir}/cfg + ${csudo}cp -f ${script_dir}/cfg/taos.cfg ${cfg_install_dir}/taos.cfg.new + ${csudo}ln -s ${cfg_install_dir}/taos.cfg ${install_main_dir}/cfg [ ! -z $1 ] && return 0 || : # only install client @@ -530,7 +530,7 @@ function install_config() { # check the format of the firstEp #if [[ $firstEp == $FQDN_PATTERN ]]; then # Write the first FQDN to configuration file - ${csudo} sed -i -r "s/#*\s*(firstEp\s*).*/\1$firstEp/" ${cfg_install_dir}/taos.cfg + ${csudo}sed -i -r "s/#*\s*(firstEp\s*).*/\1$firstEp/" ${cfg_install_dir}/taos.cfg break #else # read -p "Please enter the correct FQDN:port: " firstEp @@ -553,7 +553,7 @@ function install_config() { #if [[ "$emailAddr" =~ $EMAIL_PATTERN ]]; then # Write the email address to temp file email_file="${install_main_dir}/email" - ${csudo} bash -c "echo $emailAddr > ${email_file}" + ${csudo}bash -c "echo $emailAddr > ${email_file}" break #else # read -p "Please enter the correct email address: " emailAddr @@ -566,69 +566,69 @@ function install_config() { function install_log() { - ${csudo} rm -rf ${log_dir} || : - ${csudo} mkdir -p ${log_dir} && ${csudo} chmod 777 ${log_dir} + ${csudo}rm -rf ${log_dir} || : + ${csudo}mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir} - ${csudo} ln -s ${log_dir} ${install_main_dir}/log + ${csudo}ln -s ${log_dir} ${install_main_dir}/log } function install_data() { - ${csudo} mkdir -p ${data_dir} + ${csudo}mkdir -p ${data_dir} - ${csudo} ln -s ${data_dir} ${install_main_dir}/data + ${csudo}ln -s ${data_dir} ${install_main_dir}/data } function install_connector() { - ${csudo} cp -rf ${script_dir}/connector/ ${install_main_dir}/ + ${csudo}cp -rf ${script_dir}/connector/ ${install_main_dir}/ } function install_examples() { if [ -d ${script_dir}/examples ]; then - ${csudo} cp -rf ${script_dir}/examples/* ${install_main_dir}/examples + ${csudo}cp -rf ${script_dir}/examples/* ${install_main_dir}/examples fi } function clean_service_on_sysvinit() { #restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" - #${csudo} sed -i "\|${restart_config_str}|d" /etc/inittab || : + #${csudo}sed -i "\|${restart_config_str}|d" /etc/inittab || : if pidof taosd &> /dev/null; then - ${csudo} service taosd stop || : + ${csudo}service taosd stop || : fi if pidof tarbitrator &> /dev/null; then - ${csudo} service tarbitratord stop || : + ${csudo}service tarbitratord stop || : fi if ((${initd_mod}==1)); then if [ -e ${service_config_dir}/taosd ]; then - ${csudo} chkconfig --del taosd || : + ${csudo}chkconfig --del taosd || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} chkconfig --del tarbitratord || : + ${csudo}chkconfig --del tarbitratord || : fi elif ((${initd_mod}==2)); then if [ -e ${service_config_dir}/taosd ]; then - ${csudo} insserv -r taosd || : + ${csudo}insserv -r taosd || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} insserv -r tarbitratord || : + ${csudo}insserv -r tarbitratord || : fi elif ((${initd_mod}==3)); then if [ -e ${service_config_dir}/taosd ]; then - ${csudo} update-rc.d -f taosd remove || : + ${csudo}update-rc.d -f taosd remove || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} update-rc.d -f tarbitratord remove || : + ${csudo}update-rc.d -f tarbitratord remove || : fi fi - ${csudo} rm -f ${service_config_dir}/taosd || : - ${csudo} rm -f ${service_config_dir}/tarbitratord || : + ${csudo}rm -f ${service_config_dir}/taosd || : + ${csudo}rm -f ${service_config_dir}/tarbitratord || : if $(which init &> /dev/null); then - ${csudo} init q || : + ${csudo}init q || : fi } @@ -639,33 +639,33 @@ function install_service_on_sysvinit() { # Install taosd service if ((${os_type}==1)); then - ${csudo} cp -f ${script_dir}/init.d/taosd.deb ${install_main_dir}/init.d/taosd - ${csudo} cp ${script_dir}/init.d/taosd.deb ${service_config_dir}/taosd && ${csudo} chmod a+x ${service_config_dir}/taosd - ${csudo} cp -f ${script_dir}/init.d/tarbitratord.deb ${install_main_dir}/init.d/tarbitratord - ${csudo} cp ${script_dir}/init.d/tarbitratord.deb ${service_config_dir}/tarbitratord && ${csudo} chmod a+x ${service_config_dir}/tarbitratord + ${csudo}cp -f ${script_dir}/init.d/taosd.deb ${install_main_dir}/init.d/taosd + ${csudo}cp ${script_dir}/init.d/taosd.deb ${service_config_dir}/taosd && ${csudo}chmod a+x ${service_config_dir}/taosd + ${csudo}cp -f ${script_dir}/init.d/tarbitratord.deb ${install_main_dir}/init.d/tarbitratord + ${csudo}cp ${script_dir}/init.d/tarbitratord.deb ${service_config_dir}/tarbitratord && ${csudo}chmod a+x ${service_config_dir}/tarbitratord elif ((${os_type}==2)); then - ${csudo} cp -f ${script_dir}/init.d/taosd.rpm ${install_main_dir}/init.d/taosd - ${csudo} cp ${script_dir}/init.d/taosd.rpm ${service_config_dir}/taosd && ${csudo} chmod a+x ${service_config_dir}/taosd - ${csudo} cp -f ${script_dir}/init.d/tarbitratord.rpm ${install_main_dir}/init.d/tarbitratord - ${csudo} cp ${script_dir}/init.d/tarbitratord.rpm ${service_config_dir}/tarbitratord && ${csudo} chmod a+x ${service_config_dir}/tarbitratord + ${csudo}cp -f ${script_dir}/init.d/taosd.rpm ${install_main_dir}/init.d/taosd + ${csudo}cp ${script_dir}/init.d/taosd.rpm ${service_config_dir}/taosd && ${csudo}chmod a+x ${service_config_dir}/taosd + ${csudo}cp -f ${script_dir}/init.d/tarbitratord.rpm ${install_main_dir}/init.d/tarbitratord + ${csudo}cp ${script_dir}/init.d/tarbitratord.rpm ${service_config_dir}/tarbitratord && ${csudo}chmod a+x ${service_config_dir}/tarbitratord fi #restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" - #${csudo} grep -q -F "$restart_config_str" /etc/inittab || ${csudo} bash -c "echo '${restart_config_str}' >> /etc/inittab" + #${csudo}grep -q -F "$restart_config_str" /etc/inittab || ${csudo}bash -c "echo '${restart_config_str}' >> /etc/inittab" if ((${initd_mod}==1)); then - ${csudo} chkconfig --add taosd || : - ${csudo} chkconfig --level 2345 taosd on || : - ${csudo} chkconfig --add tarbitratord || : - ${csudo} chkconfig --level 2345 tarbitratord on || : + ${csudo}chkconfig --add taosd || : + ${csudo}chkconfig --level 2345 taosd on || : + ${csudo}chkconfig --add tarbitratord || : + ${csudo}chkconfig --level 2345 tarbitratord on || : elif ((${initd_mod}==2)); then - ${csudo} insserv taosd || : - ${csudo} insserv -d taosd || : - ${csudo} insserv tarbitratord || : - ${csudo} insserv -d tarbitratord || : + ${csudo}insserv taosd || : + ${csudo}insserv -d taosd || : + ${csudo}insserv tarbitratord || : + ${csudo}insserv -d tarbitratord || : elif ((${initd_mod}==3)); then - ${csudo} update-rc.d taosd defaults || : - ${csudo} update-rc.d tarbitratord defaults || : + ${csudo}update-rc.d taosd defaults || : + ${csudo}update-rc.d tarbitratord defaults || : fi } @@ -673,27 +673,27 @@ function clean_service_on_systemd() { taosd_service_config="${service_config_dir}/taosd.service" if systemctl is-active --quiet taosd; then echo "TDengine is running, stopping it..." - ${csudo} systemctl stop taosd &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop taosd &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable taosd &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${taosd_service_config} + ${csudo}systemctl disable taosd &> /dev/null || echo &> /dev/null + ${csudo}rm -f ${taosd_service_config} tarbitratord_service_config="${service_config_dir}/tarbitratord.service" if systemctl is-active --quiet tarbitratord; then echo "tarbitrator is running, stopping it..." - ${csudo} systemctl stop tarbitratord &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop tarbitratord &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable tarbitratord &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${tarbitratord_service_config} + ${csudo}systemctl disable tarbitratord &> /dev/null || echo &> /dev/null + ${csudo}rm -f ${tarbitratord_service_config} if [ "$verMode" == "cluster" ]; then nginx_service_config="${service_config_dir}/nginxd.service" if systemctl is-active --quiet nginxd; then echo "Nginx for TDengine is running, stopping it..." - ${csudo} systemctl stop nginxd &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop nginxd &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable nginxd &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${nginx_service_config} + ${csudo}systemctl disable nginxd &> /dev/null || echo &> /dev/null + ${csudo}rm -f ${nginx_service_config} fi } @@ -703,106 +703,106 @@ function install_service_on_systemd() { clean_service_on_systemd [ -f ${script_dir}/cfg/taosd.service ] &&\ - ${csudo} cp ${script_dir}/cfg/taosd.service \ + ${csudo}cp ${script_dir}/cfg/taosd.service \ ${service_config_dir}/ || : - ${csudo} systemctl daemon-reload + ${csudo}systemctl daemon-reload #taosd_service_config="${service_config_dir}/taosd.service" - #${csudo} bash -c "echo '[Unit]' >> ${taosd_service_config}" - #${csudo} bash -c "echo 'Description=TDengine server service' >> ${taosd_service_config}" - #${csudo} bash -c "echo 'After=network-online.target taosadapter.service' >> ${taosd_service_config}" - #${csudo} bash -c "echo 'Wants=network-online.target taosadapter.service' >> ${taosd_service_config}" - #${csudo} bash -c "echo >> ${taosd_service_config}" - #${csudo} bash -c "echo '[Service]' >> ${taosd_service_config}" - #${csudo} bash -c "echo 'Type=simple' >> ${taosd_service_config}" - #${csudo} bash -c "echo 'ExecStart=/usr/bin/taosd' >> ${taosd_service_config}" - #${csudo} bash -c "echo 'ExecStartPre=/usr/local/taos/bin/startPre.sh' >> ${taosd_service_config}" - #${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${taosd_service_config}" - #${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${taosd_service_config}" - #${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${taosd_service_config}" - #${csudo} bash -c "echo 'LimitCORE=infinity' >> ${taosd_service_config}" - #${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${taosd_service_config}" - #${csudo} bash -c "echo 'StandardOutput=null' >> ${taosd_service_config}" - #${csudo} bash -c "echo 'Restart=always' >> ${taosd_service_config}" - #${csudo} bash -c "echo 'StartLimitBurst=3' >> ${taosd_service_config}" - #${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${taosd_service_config}" - ##${csudo} bash -c "echo 'StartLimitIntervalSec=60s' >> ${taosd_service_config}" - #${csudo} bash -c "echo >> ${taosd_service_config}" - #${csudo} bash -c "echo '[Install]' >> ${taosd_service_config}" - #${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${taosd_service_config}" - ${csudo} systemctl enable taosd + #${csudo}bash -c "echo '[Unit]' >> ${taosd_service_config}" + #${csudo}bash -c "echo 'Description=TDengine server service' >> ${taosd_service_config}" + #${csudo}bash -c "echo 'After=network-online.target taosadapter.service' >> ${taosd_service_config}" + #${csudo}bash -c "echo 'Wants=network-online.target taosadapter.service' >> ${taosd_service_config}" + #${csudo}bash -c "echo >> ${taosd_service_config}" + #${csudo}bash -c "echo '[Service]' >> ${taosd_service_config}" + #${csudo}bash -c "echo 'Type=simple' >> ${taosd_service_config}" + #${csudo}bash -c "echo 'ExecStart=/usr/bin/taosd' >> ${taosd_service_config}" + #${csudo}bash -c "echo 'ExecStartPre=/usr/local/taos/bin/startPre.sh' >> ${taosd_service_config}" + #${csudo}bash -c "echo 'TimeoutStopSec=1000000s' >> ${taosd_service_config}" + #${csudo}bash -c "echo 'LimitNOFILE=infinity' >> ${taosd_service_config}" + #${csudo}bash -c "echo 'LimitNPROC=infinity' >> ${taosd_service_config}" + #${csudo}bash -c "echo 'LimitCORE=infinity' >> ${taosd_service_config}" + #${csudo}bash -c "echo 'TimeoutStartSec=0' >> ${taosd_service_config}" + #${csudo}bash -c "echo 'StandardOutput=null' >> ${taosd_service_config}" + #${csudo}bash -c "echo 'Restart=always' >> ${taosd_service_config}" + #${csudo}bash -c "echo 'StartLimitBurst=3' >> ${taosd_service_config}" + #${csudo}bash -c "echo 'StartLimitInterval=60s' >> ${taosd_service_config}" + ##${csudo}bash -c "echo 'StartLimitIntervalSec=60s' >> ${taosd_service_config}" + #${csudo}bash -c "echo >> ${taosd_service_config}" + #${csudo}bash -c "echo '[Install]' >> ${taosd_service_config}" + #${csudo}bash -c "echo 'WantedBy=multi-user.target' >> ${taosd_service_config}" + ${csudo}systemctl enable taosd [ -f ${script_dir}/cfg/tarbitratord.service ] &&\ - ${csudo} cp ${script_dir}/cfg/tarbitratord.service \ + ${csudo}cp ${script_dir}/cfg/tarbitratord.service \ ${service_config_dir}/ || : - ${csudo} systemctl daemon-reload + ${csudo}systemctl daemon-reload #tarbitratord_service_config="${service_config_dir}/tarbitratord.service" - #${csudo} bash -c "echo '[Unit]' >> ${tarbitratord_service_config}" - #${csudo} bash -c "echo 'Description=TDengine arbitrator service' >> ${tarbitratord_service_config}" - #${csudo} bash -c "echo 'After=network-online.target' >> ${tarbitratord_service_config}" - #${csudo} bash -c "echo 'Wants=network-online.target' >> ${tarbitratord_service_config}" - #${csudo} bash -c "echo >> ${tarbitratord_service_config}" - #${csudo} bash -c "echo '[Service]' >> ${tarbitratord_service_config}" - #${csudo} bash -c "echo 'Type=simple' >> ${tarbitratord_service_config}" - #${csudo} bash -c "echo 'ExecStart=/usr/bin/tarbitrator' >> ${tarbitratord_service_config}" - #${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${tarbitratord_service_config}" - #${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${tarbitratord_service_config}" - #${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${tarbitratord_service_config}" - #${csudo} bash -c "echo 'LimitCORE=infinity' >> ${tarbitratord_service_config}" - #${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${tarbitratord_service_config}" - #${csudo} bash -c "echo 'StandardOutput=null' >> ${tarbitratord_service_config}" - #${csudo} bash -c "echo 'Restart=always' >> ${tarbitratord_service_config}" - #${csudo} bash -c "echo 'StartLimitBurst=3' >> ${tarbitratord_service_config}" - #${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${tarbitratord_service_config}" - #${csudo} bash -c "echo >> ${tarbitratord_service_config}" - #${csudo} bash -c "echo '[Install]' >> ${tarbitratord_service_config}" - #${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${tarbitratord_service_config}" - #${csudo} systemctl enable tarbitratord + #${csudo}bash -c "echo '[Unit]' >> ${tarbitratord_service_config}" + #${csudo}bash -c "echo 'Description=TDengine arbitrator service' >> ${tarbitratord_service_config}" + #${csudo}bash -c "echo 'After=network-online.target' >> ${tarbitratord_service_config}" + #${csudo}bash -c "echo 'Wants=network-online.target' >> ${tarbitratord_service_config}" + #${csudo}bash -c "echo >> ${tarbitratord_service_config}" + #${csudo}bash -c "echo '[Service]' >> ${tarbitratord_service_config}" + #${csudo}bash -c "echo 'Type=simple' >> ${tarbitratord_service_config}" + #${csudo}bash -c "echo 'ExecStart=/usr/bin/tarbitrator' >> ${tarbitratord_service_config}" + #${csudo}bash -c "echo 'TimeoutStopSec=1000000s' >> ${tarbitratord_service_config}" + #${csudo}bash -c "echo 'LimitNOFILE=infinity' >> ${tarbitratord_service_config}" + #${csudo}bash -c "echo 'LimitNPROC=infinity' >> ${tarbitratord_service_config}" + #${csudo}bash -c "echo 'LimitCORE=infinity' >> ${tarbitratord_service_config}" + #${csudo}bash -c "echo 'TimeoutStartSec=0' >> ${tarbitratord_service_config}" + #${csudo}bash -c "echo 'StandardOutput=null' >> ${tarbitratord_service_config}" + #${csudo}bash -c "echo 'Restart=always' >> ${tarbitratord_service_config}" + #${csudo}bash -c "echo 'StartLimitBurst=3' >> ${tarbitratord_service_config}" + #${csudo}bash -c "echo 'StartLimitInterval=60s' >> ${tarbitratord_service_config}" + #${csudo}bash -c "echo >> ${tarbitratord_service_config}" + #${csudo}bash -c "echo '[Install]' >> ${tarbitratord_service_config}" + #${csudo}bash -c "echo 'WantedBy=multi-user.target' >> ${tarbitratord_service_config}" + #${csudo}systemctl enable tarbitratord if [ "$verMode" == "cluster" ]; then [ -f ${script_dir}/cfg/nginxd.service ] &&\ - ${csudo} cp ${script_dir}/cfg/nginxd.service \ + ${csudo}cp ${script_dir}/cfg/nginxd.service \ ${service_config_dir}/ || : - ${csudo} systemctl daemon-reload + ${csudo}systemctl daemon-reload #nginx_service_config="${service_config_dir}/nginxd.service" - #${csudo} bash -c "echo '[Unit]' >> ${nginx_service_config}" - #${csudo} bash -c "echo 'Description=Nginx For TDengine Service' >> ${nginx_service_config}" - #${csudo} bash -c "echo 'After=network-online.target' >> ${nginx_service_config}" - #${csudo} bash -c "echo 'Wants=network-online.target' >> ${nginx_service_config}" - #${csudo} bash -c "echo >> ${nginx_service_config}" - #${csudo} bash -c "echo '[Service]' >> ${nginx_service_config}" - #${csudo} bash -c "echo 'Type=forking' >> ${nginx_service_config}" - #${csudo} bash -c "echo 'PIDFile=/usr/local/nginxd/logs/nginx.pid' >> ${nginx_service_config}" - #${csudo} bash -c "echo 'ExecStart=/usr/local/nginxd/sbin/nginx' >> ${nginx_service_config}" - #${csudo} bash -c "echo 'ExecStop=/usr/local/nginxd/sbin/nginx -s stop' >> ${nginx_service_config}" - #${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${nginx_service_config}" - #${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${nginx_service_config}" - #${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${nginx_service_config}" - #${csudo} bash -c "echo 'LimitCORE=infinity' >> ${nginx_service_config}" - #${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${nginx_service_config}" - #${csudo} bash -c "echo 'StandardOutput=null' >> ${nginx_service_config}" - #${csudo} bash -c "echo 'Restart=always' >> ${nginx_service_config}" - #${csudo} bash -c "echo 'StartLimitBurst=3' >> ${nginx_service_config}" - #${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${nginx_service_config}" - #${csudo} bash -c "echo >> ${nginx_service_config}" - #${csudo} bash -c "echo '[Install]' >> ${nginx_service_config}" - #${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${nginx_service_config}" - if ! ${csudo} systemctl enable nginxd &> /dev/null; then - ${csudo} systemctl daemon-reexec - ${csudo} systemctl enable nginxd + #${csudo}bash -c "echo '[Unit]' >> ${nginx_service_config}" + #${csudo}bash -c "echo 'Description=Nginx For TDengine Service' >> ${nginx_service_config}" + #${csudo}bash -c "echo 'After=network-online.target' >> ${nginx_service_config}" + #${csudo}bash -c "echo 'Wants=network-online.target' >> ${nginx_service_config}" + #${csudo}bash -c "echo >> ${nginx_service_config}" + #${csudo}bash -c "echo '[Service]' >> ${nginx_service_config}" + #${csudo}bash -c "echo 'Type=forking' >> ${nginx_service_config}" + #${csudo}bash -c "echo 'PIDFile=/usr/local/nginxd/logs/nginx.pid' >> ${nginx_service_config}" + #${csudo}bash -c "echo 'ExecStart=/usr/local/nginxd/sbin/nginx' >> ${nginx_service_config}" + #${csudo}bash -c "echo 'ExecStop=/usr/local/nginxd/sbin/nginx -s stop' >> ${nginx_service_config}" + #${csudo}bash -c "echo 'TimeoutStopSec=1000000s' >> ${nginx_service_config}" + #${csudo}bash -c "echo 'LimitNOFILE=infinity' >> ${nginx_service_config}" + #${csudo}bash -c "echo 'LimitNPROC=infinity' >> ${nginx_service_config}" + #${csudo}bash -c "echo 'LimitCORE=infinity' >> ${nginx_service_config}" + #${csudo}bash -c "echo 'TimeoutStartSec=0' >> ${nginx_service_config}" + #${csudo}bash -c "echo 'StandardOutput=null' >> ${nginx_service_config}" + #${csudo}bash -c "echo 'Restart=always' >> ${nginx_service_config}" + #${csudo}bash -c "echo 'StartLimitBurst=3' >> ${nginx_service_config}" + #${csudo}bash -c "echo 'StartLimitInterval=60s' >> ${nginx_service_config}" + #${csudo}bash -c "echo >> ${nginx_service_config}" + #${csudo}bash -c "echo '[Install]' >> ${nginx_service_config}" + #${csudo}bash -c "echo 'WantedBy=multi-user.target' >> ${nginx_service_config}" + if ! ${csudo}systemctl enable nginxd &> /dev/null; then + ${csudo}systemctl daemon-reexec + ${csudo}systemctl enable nginxd fi - ${csudo} systemctl start nginxd + ${csudo}systemctl start nginxd fi } function install_taosadapter_service() { if ((${service_mod}==0)); then [ -f ${script_dir}/cfg/taosadapter.service ] &&\ - ${csudo} cp ${script_dir}/cfg/taosadapter.service \ + ${csudo}cp ${script_dir}/cfg/taosadapter.service \ ${service_config_dir}/ || : - ${csudo} systemctl daemon-reload + ${csudo}systemctl daemon-reload fi } @@ -896,9 +896,9 @@ function update_TDengine() { # Stop the service if running if pidof taosd &> /dev/null; then if ((${service_mod}==0)); then - ${csudo} systemctl stop taosd || : + ${csudo}systemctl stop taosd || : elif ((${service_mod}==1)); then - ${csudo} service taosd stop || : + ${csudo}service taosd stop || : else kill_process taosd fi @@ -908,9 +908,9 @@ function update_TDengine() { if [ "$verMode" == "cluster" ]; then if pidof nginx &> /dev/null; then if ((${service_mod}==0)); then - ${csudo} systemctl stop nginxd || : + ${csudo}systemctl stop nginxd || : elif ((${service_mod}==1)); then - ${csudo} service nginxd stop || : + ${csudo}service nginxd stop || : else kill_process nginx fi @@ -952,11 +952,13 @@ function update_TDengine() { #echo -e "\033[44;32;1mTDengine is updated successfully!${NC}" echo echo -e "${GREEN_DARK}To configure TDengine ${NC}: edit /etc/taos/taos.cfg" + echo -e "${GREEN_DARK}To configure Taos Adapter (if has) ${NC}: edit /etc/taos/taosadapter.toml" if ((${service_mod}==0)); then - echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} systemctl start taosd${NC}" + echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo}systemctl start taosd${NC}" elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} service taosd start${NC}" + echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo}service taosd start${NC}" else + echo -e "${GREEN_DARK}To start Taos Adapter (if has)${NC}: taosadapter &${NC}" echo -e "${GREEN_DARK}To start TDengine ${NC}: ./taosd${NC}" fi @@ -1037,11 +1039,13 @@ function install_TDengine() { #echo -e "\033[44;32;1mTDengine is installed successfully!${NC}" echo echo -e "${GREEN_DARK}To configure TDengine ${NC}: edit /etc/taos/taos.cfg" + echo -e "${GREEN_DARK}To configure taosadapter (if has) ${NC}: edit /etc/taos/taosadapter.toml" if ((${service_mod}==0)); then - echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} systemctl start taosd${NC}" + echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo}systemctl start taosd${NC}" elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} service taosd start${NC}" + echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo}service taosd start${NC}" else + echo -e "${GREEN_DARK}To start Taos Adapter (if has)${NC}: taosadapter &${NC}" echo -e "${GREEN_DARK}To start TDengine ${NC}: taosd${NC}" fi diff --git a/packaging/tools/install_arbi.sh b/packaging/tools/install_arbi.sh index 33896a08b3f653dbddc1ad480ddab3bf73a513ef..a582e0322aa025a69690a4041afd2fa24cc20a62 100755 --- a/packaging/tools/install_arbi.sh +++ b/packaging/tools/install_arbi.sh @@ -29,7 +29,7 @@ NC='\033[0m' csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi update_flag=0 @@ -91,85 +91,85 @@ fi function kill_tarbitrator() { pid=$(ps -ef | grep "tarbitrator" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function install_main_path() { #create install main dir and all sub dir - ${csudo} rm -rf ${install_main_dir} || : - ${csudo} mkdir -p ${install_main_dir} - ${csudo} mkdir -p ${install_main_dir}/bin - #${csudo} mkdir -p ${install_main_dir}/include - ${csudo} mkdir -p ${install_main_dir}/init.d + ${csudo}rm -rf ${install_main_dir} || : + ${csudo}mkdir -p ${install_main_dir} + ${csudo}mkdir -p ${install_main_dir}/bin + #${csudo}mkdir -p ${install_main_dir}/include + ${csudo}mkdir -p ${install_main_dir}/init.d } function install_bin() { # Remove links - ${csudo} rm -f ${bin_link_dir}/rmtarbitrator || : - ${csudo} rm -f ${bin_link_dir}/tarbitrator || : - ${csudo} cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo} chmod 0555 ${install_main_dir}/bin/* + ${csudo}rm -f ${bin_link_dir}/rmtarbitrator || : + ${csudo}rm -f ${bin_link_dir}/tarbitrator || : + ${csudo}cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo}chmod 0555 ${install_main_dir}/bin/* #Make link - [ -x ${install_main_dir}/bin/remove_arbi.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove_arbi.sh ${bin_link_dir}/rmtarbitrator || : - [ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo} ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || : + [ -x ${install_main_dir}/bin/remove_arbi.sh ] && ${csudo}ln -s ${install_main_dir}/bin/remove_arbi.sh ${bin_link_dir}/rmtarbitrator || : + [ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo}ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || : } function install_header() { - ${csudo} rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h || : - ${csudo} cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo} chmod 644 ${install_main_dir}/include/* - ${csudo} ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h - ${csudo} ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h - ${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h + ${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h || : + ${csudo}cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo}chmod 644 ${install_main_dir}/include/* + ${csudo}ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h + ${csudo}ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h + ${csudo}ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h } function install_jemalloc() { jemalloc_dir=${script_dir}/jemalloc if [ -d ${jemalloc_dir} ]; then - ${csudo} /usr/bin/install -c -d /usr/local/bin + ${csudo}/usr/bin/install -c -d /usr/local/bin if [ -f ${jemalloc_dir}/bin/jemalloc-config ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc-config /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc-config /usr/local/bin fi if [ -f ${jemalloc_dir}/bin/jemalloc.sh ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc.sh /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc.sh /usr/local/bin fi if [ -f ${jemalloc_dir}/bin/jeprof ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jeprof /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jeprof /usr/local/bin fi if [ -f ${jemalloc_dir}/include/jemalloc/jemalloc.h ]; then - ${csudo} /usr/bin/install -c -d /usr/local/include/jemalloc - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/include/jemalloc/jemalloc.h /usr/local/include/jemalloc + ${csudo}/usr/bin/install -c -d /usr/local/include/jemalloc + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/include/jemalloc/jemalloc.h /usr/local/include/jemalloc fi if [ -f ${jemalloc_dir}/lib/libjemalloc.so.2 ]; then - ${csudo} /usr/bin/install -c -d /usr/local/lib - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.so.2 /usr/local/lib - ${csudo} ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so - ${csudo} /usr/bin/install -c -d /usr/local/lib + ${csudo}/usr/bin/install -c -d /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.so.2 /usr/local/lib + ${csudo}ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so + ${csudo}/usr/bin/install -c -d /usr/local/lib if [ -f ${jemalloc_dir}/lib/libjemalloc.a ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.a /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.a /usr/local/lib fi if [ -f ${jemalloc_dir}/lib/libjemalloc_pic.a ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc_pic.a /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc_pic.a /usr/local/lib fi if [ -f ${jemalloc_dir}/lib/libjemalloc_pic.a ]; then - ${csudo} /usr/bin/install -c -d /usr/local/lib/pkgconfig - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/lib/pkgconfig/jemalloc.pc /usr/local/lib/pkgconfig + ${csudo}/usr/bin/install -c -d /usr/local/lib/pkgconfig + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/lib/pkgconfig/jemalloc.pc /usr/local/lib/pkgconfig fi fi if [ -f ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html ]; then - ${csudo} /usr/bin/install -c -d /usr/local/share/doc/jemalloc - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html /usr/local/share/doc/jemalloc + ${csudo}/usr/bin/install -c -d /usr/local/share/doc/jemalloc + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html /usr/local/share/doc/jemalloc fi if [ -f ${jemalloc_dir}/share/man/man3/jemalloc.3 ]; then - ${csudo} /usr/bin/install -c -d /usr/local/share/man/man3 - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/share/man/man3/jemalloc.3 /usr/local/share/man/man3 + ${csudo}/usr/bin/install -c -d /usr/local/share/man/man3 + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/share/man/man3/jemalloc.3 /usr/local/share/man/man3 fi if [ -d /etc/ld.so.conf.d ]; then - echo "/usr/local/lib" | ${csudo} tee /etc/ld.so.conf.d/jemalloc.conf > /dev/null || echo -e "failed to write /etc/ld.so.conf.d/jemalloc.conf" - ${csudo} ldconfig + echo "/usr/local/lib" | ${csudo}tee /etc/ld.so.conf.d/jemalloc.conf > /dev/null || echo -e "failed to write /etc/ld.so.conf.d/jemalloc.conf" + ${csudo}ldconfig else echo "/etc/ld.so.conf.d not found!" fi @@ -178,30 +178,30 @@ function install_jemalloc() { function clean_service_on_sysvinit() { #restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" - #${csudo} sed -i "\|${restart_config_str}|d" /etc/inittab || : + #${csudo}sed -i "\|${restart_config_str}|d" /etc/inittab || : if pidof tarbitrator &> /dev/null; then - ${csudo} service tarbitratord stop || : + ${csudo}service tarbitratord stop || : fi if ((${initd_mod}==1)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} chkconfig --del tarbitratord || : + ${csudo}chkconfig --del tarbitratord || : fi elif ((${initd_mod}==2)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} insserv -r tarbitratord || : + ${csudo}insserv -r tarbitratord || : fi elif ((${initd_mod}==3)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} update-rc.d -f tarbitratord remove || : + ${csudo}update-rc.d -f tarbitratord remove || : fi fi - ${csudo} rm -f ${service_config_dir}/tarbitratord || : + ${csudo}rm -f ${service_config_dir}/tarbitratord || : if $(which init &> /dev/null); then - ${csudo} init q || : + ${csudo}init q || : fi } @@ -212,24 +212,24 @@ function install_service_on_sysvinit() { # Install taosd service if ((${os_type}==1)); then - ${csudo} cp -f ${script_dir}/init.d/tarbitratord.deb ${install_main_dir}/init.d/tarbitratord - ${csudo} cp ${script_dir}/init.d/tarbitratord.deb ${service_config_dir}/tarbitratord && ${csudo} chmod a+x ${service_config_dir}/tarbitratord + ${csudo}cp -f ${script_dir}/init.d/tarbitratord.deb ${install_main_dir}/init.d/tarbitratord + ${csudo}cp ${script_dir}/init.d/tarbitratord.deb ${service_config_dir}/tarbitratord && ${csudo}chmod a+x ${service_config_dir}/tarbitratord elif ((${os_type}==2)); then - ${csudo} cp -f ${script_dir}/init.d/tarbitratord.rpm ${install_main_dir}/init.d/tarbitratord - ${csudo} cp ${script_dir}/init.d/tarbitratord.rpm ${service_config_dir}/tarbitratord && ${csudo} chmod a+x ${service_config_dir}/tarbitratord + ${csudo}cp -f ${script_dir}/init.d/tarbitratord.rpm ${install_main_dir}/init.d/tarbitratord + ${csudo}cp ${script_dir}/init.d/tarbitratord.rpm ${service_config_dir}/tarbitratord && ${csudo}chmod a+x ${service_config_dir}/tarbitratord fi #restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" - #${csudo} grep -q -F "$restart_config_str" /etc/inittab || ${csudo} bash -c "echo '${restart_config_str}' >> /etc/inittab" + #${csudo}grep -q -F "$restart_config_str" /etc/inittab || ${csudo}bash -c "echo '${restart_config_str}' >> /etc/inittab" if ((${initd_mod}==1)); then - ${csudo} chkconfig --add tarbitratord || : - ${csudo} chkconfig --level 2345 tarbitratord on || : + ${csudo}chkconfig --add tarbitratord || : + ${csudo}chkconfig --level 2345 tarbitratord on || : elif ((${initd_mod}==2)); then - ${csudo} insserv tarbitratord || : - ${csudo} insserv -d tarbitratord || : + ${csudo}insserv tarbitratord || : + ${csudo}insserv -d tarbitratord || : elif ((${initd_mod}==3)); then - ${csudo} update-rc.d tarbitratord defaults || : + ${csudo}update-rc.d tarbitratord defaults || : fi } @@ -237,11 +237,11 @@ function clean_service_on_systemd() { tarbitratord_service_config="${service_config_dir}/tarbitratord.service" if systemctl is-active --quiet tarbitratord; then echo "tarbitrator is running, stopping it..." - ${csudo} systemctl stop tarbitratord &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop tarbitratord &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable tarbitratord &> /dev/null || echo &> /dev/null + ${csudo}systemctl disable tarbitratord &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${tarbitratord_service_config} + ${csudo}rm -f ${tarbitratord_service_config} } # taos:2345:respawn:/etc/init.d/tarbitratord start @@ -251,27 +251,27 @@ function install_service_on_systemd() { tarbitratord_service_config="${service_config_dir}/tarbitratord.service" - ${csudo} bash -c "echo '[Unit]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Description=TDengine arbitrator service' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'After=network-online.target' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Wants=network-online.target' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo '[Service]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Type=simple' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'ExecStart=/usr/bin/tarbitrator' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitCORE=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StandardOutput=null' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Restart=always' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StartLimitBurst=3' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo '[Install]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${tarbitratord_service_config}" - ${csudo} systemctl enable tarbitratord + ${csudo}bash -c "echo '[Unit]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Description=TDengine arbitrator service' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'After=network-online.target' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Wants=network-online.target' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo '[Service]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Type=simple' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'ExecStart=/usr/bin/tarbitrator' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'TimeoutStopSec=1000000s' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitNOFILE=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitNPROC=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitCORE=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'TimeoutStartSec=0' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StandardOutput=null' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Restart=always' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StartLimitBurst=3' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StartLimitInterval=60s' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo '[Install]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'WantedBy=multi-user.target' >> ${tarbitratord_service_config}" + ${csudo}systemctl enable tarbitratord } function install_service() { @@ -291,9 +291,9 @@ function update_TDengine() { # Stop the service if running if pidof tarbitrator &> /dev/null; then if ((${service_mod}==0)); then - ${csudo} systemctl stop tarbitratord || : + ${csudo}systemctl stop tarbitratord || : elif ((${service_mod}==1)); then - ${csudo} service tarbitratord stop || : + ${csudo}service tarbitratord stop || : else kill_tarbitrator fi @@ -309,9 +309,9 @@ function update_TDengine() { echo #echo -e "${GREEN_DARK}To configure TDengine ${NC}: edit /etc/taos/taos.cfg" if ((${service_mod}==0)); then - echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo} systemctl start tarbitratord${NC}" + echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo}systemctl start tarbitratord${NC}" elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo} service tarbitratord start${NC}" + echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo}service tarbitratord start${NC}" else echo -e "${GREEN_DARK}To start arbitrator ${NC}: ./tarbitrator${NC}" fi @@ -332,9 +332,9 @@ function install_TDengine() { echo #echo -e "${GREEN_DARK}To configure TDengine ${NC}: edit /etc/taos/taos.cfg" if ((${service_mod}==0)); then - echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo} systemctl start tarbitratord${NC}" + echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo}systemctl start tarbitratord${NC}" elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo} service tarbitratord start${NC}" + echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo}service tarbitratord start${NC}" else echo -e "${GREEN_DARK}To start arbitrator ${NC}: tarbitrator${NC}" fi diff --git a/packaging/tools/install_arbi_jh.sh b/packaging/tools/install_arbi_jh.sh index 2403f8fbd79abf4324577fe3dca3a8e0eac8ed01..3b0d050c2c1c395b197ed040ce20c86f512cad2b 100755 --- a/packaging/tools/install_arbi_jh.sh +++ b/packaging/tools/install_arbi_jh.sh @@ -29,7 +29,7 @@ NC='\033[0m' csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi update_flag=0 @@ -91,60 +91,60 @@ fi function kill_tarbitrator() { pid=$(ps -ef | grep "tarbitrator" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function install_main_path() { #create install main dir and all sub dir - ${csudo} rm -rf ${install_main_dir} || : - ${csudo} mkdir -p ${install_main_dir} - ${csudo} mkdir -p ${install_main_dir}/bin - #${csudo} mkdir -p ${install_main_dir}/include - ${csudo} mkdir -p ${install_main_dir}/init.d + ${csudo}rm -rf ${install_main_dir} || : + ${csudo}mkdir -p ${install_main_dir} + ${csudo}mkdir -p ${install_main_dir}/bin + #${csudo}mkdir -p ${install_main_dir}/include + ${csudo}mkdir -p ${install_main_dir}/init.d } function install_bin() { # Remove links - ${csudo} rm -f ${bin_link_dir}/rmtarbitrator || : - ${csudo} rm -f ${bin_link_dir}/tarbitrator || : - ${csudo} cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo} chmod 0555 ${install_main_dir}/bin/* + ${csudo}rm -f ${bin_link_dir}/rmtarbitrator || : + ${csudo}rm -f ${bin_link_dir}/tarbitrator || : + ${csudo}cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo}chmod 0555 ${install_main_dir}/bin/* #Make link - [ -x ${install_main_dir}/bin/remove_arbi_jh.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove_arbi_jh.sh ${bin_link_dir}/rmtarbitrator || : - [ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo} ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || : + [ -x ${install_main_dir}/bin/remove_arbi_jh.sh ] && ${csudo}ln -s ${install_main_dir}/bin/remove_arbi_jh.sh ${bin_link_dir}/rmtarbitrator || : + [ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo}ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || : } function install_header() { - ${csudo} rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taoserror.h || : - ${csudo} cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo} chmod 644 ${install_main_dir}/include/* - ${csudo} ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h - ${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h + ${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taoserror.h || : + ${csudo}cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo}chmod 644 ${install_main_dir}/include/* + ${csudo}ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h + ${csudo}ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h } function clean_service_on_sysvinit() { if pidof tarbitrator &> /dev/null; then - ${csudo} service tarbitratord stop || : + ${csudo}service tarbitratord stop || : fi if ((${initd_mod}==1)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} chkconfig --del tarbitratord || : + ${csudo}chkconfig --del tarbitratord || : fi elif ((${initd_mod}==2)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} insserv -r tarbitratord || : + ${csudo}insserv -r tarbitratord || : fi elif ((${initd_mod}==3)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} update-rc.d -f tarbitratord remove || : + ${csudo}update-rc.d -f tarbitratord remove || : fi fi - ${csudo} rm -f ${service_config_dir}/tarbitratord || : + ${csudo}rm -f ${service_config_dir}/tarbitratord || : if $(which init &> /dev/null); then - ${csudo} init q || : + ${csudo}init q || : fi } @@ -154,21 +154,21 @@ function install_service_on_sysvinit() { # Install server service if ((${os_type}==1)); then - ${csudo} cp -f ${script_dir}/init.d/tarbitratord.deb ${install_main_dir}/init.d/tarbitratord - ${csudo} cp ${script_dir}/init.d/tarbitratord.deb ${service_config_dir}/tarbitratord && ${csudo} chmod a+x ${service_config_dir}/tarbitratord + ${csudo}cp -f ${script_dir}/init.d/tarbitratord.deb ${install_main_dir}/init.d/tarbitratord + ${csudo}cp ${script_dir}/init.d/tarbitratord.deb ${service_config_dir}/tarbitratord && ${csudo}chmod a+x ${service_config_dir}/tarbitratord elif ((${os_type}==2)); then - ${csudo} cp -f ${script_dir}/init.d/tarbitratord.rpm ${install_main_dir}/init.d/tarbitratord - ${csudo} cp ${script_dir}/init.d/tarbitratord.rpm ${service_config_dir}/tarbitratord && ${csudo} chmod a+x ${service_config_dir}/tarbitratord + ${csudo}cp -f ${script_dir}/init.d/tarbitratord.rpm ${install_main_dir}/init.d/tarbitratord + ${csudo}cp ${script_dir}/init.d/tarbitratord.rpm ${service_config_dir}/tarbitratord && ${csudo}chmod a+x ${service_config_dir}/tarbitratord fi if ((${initd_mod}==1)); then - ${csudo} chkconfig --add tarbitratord || : - ${csudo} chkconfig --level 2345 tarbitratord on || : + ${csudo}chkconfig --add tarbitratord || : + ${csudo}chkconfig --level 2345 tarbitratord on || : elif ((${initd_mod}==2)); then - ${csudo} insserv tarbitratord || : - ${csudo} insserv -d tarbitratord || : + ${csudo}insserv tarbitratord || : + ${csudo}insserv -d tarbitratord || : elif ((${initd_mod}==3)); then - ${csudo} update-rc.d tarbitratord defaults || : + ${csudo}update-rc.d tarbitratord defaults || : fi } @@ -176,11 +176,11 @@ function clean_service_on_systemd() { tarbitratord_service_config="${service_config_dir}/tarbitratord.service" if systemctl is-active --quiet tarbitratord; then echo "tarbitrator is running, stopping it..." - ${csudo} systemctl stop tarbitratord &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop tarbitratord &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable tarbitratord &> /dev/null || echo &> /dev/null + ${csudo}systemctl disable tarbitratord &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${tarbitratord_service_config} + ${csudo}rm -f ${tarbitratord_service_config} } function install_service_on_systemd() { @@ -188,27 +188,27 @@ function install_service_on_systemd() { tarbitratord_service_config="${service_config_dir}/tarbitratord.service" - ${csudo} bash -c "echo '[Unit]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Description=jh_iot arbitrator service' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'After=network-online.target' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Wants=network-online.target' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo '[Service]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Type=simple' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'ExecStart=/usr/bin/tarbitrator' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitCORE=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StandardOutput=null' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Restart=always' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StartLimitBurst=3' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo '[Install]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${tarbitratord_service_config}" - ${csudo} systemctl enable tarbitratord + ${csudo}bash -c "echo '[Unit]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Description=jh_iot arbitrator service' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'After=network-online.target' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Wants=network-online.target' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo '[Service]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Type=simple' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'ExecStart=/usr/bin/tarbitrator' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'TimeoutStopSec=1000000s' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitNOFILE=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitNPROC=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitCORE=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'TimeoutStartSec=0' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StandardOutput=null' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Restart=always' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StartLimitBurst=3' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StartLimitInterval=60s' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo '[Install]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'WantedBy=multi-user.target' >> ${tarbitratord_service_config}" + ${csudo}systemctl enable tarbitratord } function install_service() { @@ -227,9 +227,9 @@ function update() { # Stop the service if running if pidof tarbitrator &> /dev/null; then if ((${service_mod}==0)); then - ${csudo} systemctl stop tarbitratord || : + ${csudo}systemctl stop tarbitratord || : elif ((${service_mod}==1)); then - ${csudo} service tarbitratord stop || : + ${csudo}service tarbitratord stop || : else kill_tarbitrator fi @@ -243,9 +243,9 @@ function update() { echo if ((${service_mod}==0)); then - echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo} systemctl start tarbitratord${NC}" + echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo}systemctl start tarbitratord${NC}" elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo} service tarbitratord start${NC}" + echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo}service tarbitratord start${NC}" else echo -e "${GREEN_DARK}To start arbitrator ${NC}: ./tarbitrator${NC}" fi @@ -263,9 +263,9 @@ function install() { install_service echo if ((${service_mod}==0)); then - echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo} systemctl start tarbitratord${NC}" + echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo}systemctl start tarbitratord${NC}" elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo} service tarbitratord start${NC}" + echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo}service tarbitratord start${NC}" else echo -e "${GREEN_DARK}To start arbitrator ${NC}: tarbitrator${NC}" fi diff --git a/packaging/tools/install_arbi_kh.sh b/packaging/tools/install_arbi_kh.sh index 9a2542936d935b70b762702f0f2f6ff92b51a4f3..3c95639d181b6796128315fc9afb8bfa586c6dc3 100755 --- a/packaging/tools/install_arbi_kh.sh +++ b/packaging/tools/install_arbi_kh.sh @@ -29,7 +29,7 @@ NC='\033[0m' csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi update_flag=0 @@ -91,60 +91,60 @@ fi function kill_tarbitrator() { pid=$(ps -ef | grep "tarbitrator" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function install_main_path() { #create install main dir and all sub dir - ${csudo} rm -rf ${install_main_dir} || : - ${csudo} mkdir -p ${install_main_dir} - ${csudo} mkdir -p ${install_main_dir}/bin - #${csudo} mkdir -p ${install_main_dir}/include - ${csudo} mkdir -p ${install_main_dir}/init.d + ${csudo}rm -rf ${install_main_dir} || : + ${csudo}mkdir -p ${install_main_dir} + ${csudo}mkdir -p ${install_main_dir}/bin + #${csudo}mkdir -p ${install_main_dir}/include + ${csudo}mkdir -p ${install_main_dir}/init.d } function install_bin() { # Remove links - ${csudo} rm -f ${bin_link_dir}/rmtarbitrator || : - ${csudo} rm -f ${bin_link_dir}/tarbitrator || : - ${csudo} cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo} chmod 0555 ${install_main_dir}/bin/* + ${csudo}rm -f ${bin_link_dir}/rmtarbitrator || : + ${csudo}rm -f ${bin_link_dir}/tarbitrator || : + ${csudo}cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo}chmod 0555 ${install_main_dir}/bin/* #Make link - [ -x ${install_main_dir}/bin/remove_arbi_kh.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove_arbi_kh.sh ${bin_link_dir}/rmtarbitrator || : - [ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo} ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || : + [ -x ${install_main_dir}/bin/remove_arbi_kh.sh ] && ${csudo}ln -s ${install_main_dir}/bin/remove_arbi_kh.sh ${bin_link_dir}/rmtarbitrator || : + [ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo}ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || : } function install_header() { - ${csudo} rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taoserror.h || : - ${csudo} cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo} chmod 644 ${install_main_dir}/include/* - ${csudo} ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h - ${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h + ${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taoserror.h || : + ${csudo}cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo}chmod 644 ${install_main_dir}/include/* + ${csudo}ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h + ${csudo}ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h } function clean_service_on_sysvinit() { if pidof tarbitrator &> /dev/null; then - ${csudo} service tarbitratord stop || : + ${csudo}service tarbitratord stop || : fi if ((${initd_mod}==1)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} chkconfig --del tarbitratord || : + ${csudo}chkconfig --del tarbitratord || : fi elif ((${initd_mod}==2)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} insserv -r tarbitratord || : + ${csudo}insserv -r tarbitratord || : fi elif ((${initd_mod}==3)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} update-rc.d -f tarbitratord remove || : + ${csudo}update-rc.d -f tarbitratord remove || : fi fi - ${csudo} rm -f ${service_config_dir}/tarbitratord || : + ${csudo}rm -f ${service_config_dir}/tarbitratord || : if $(which init &> /dev/null); then - ${csudo} init q || : + ${csudo}init q || : fi } @@ -154,21 +154,21 @@ function install_service_on_sysvinit() { # Install khserver service if ((${os_type}==1)); then - ${csudo} cp -f ${script_dir}/init.d/tarbitratord.deb ${install_main_dir}/init.d/tarbitratord - ${csudo} cp ${script_dir}/init.d/tarbitratord.deb ${service_config_dir}/tarbitratord && ${csudo} chmod a+x ${service_config_dir}/tarbitratord + ${csudo}cp -f ${script_dir}/init.d/tarbitratord.deb ${install_main_dir}/init.d/tarbitratord + ${csudo}cp ${script_dir}/init.d/tarbitratord.deb ${service_config_dir}/tarbitratord && ${csudo}chmod a+x ${service_config_dir}/tarbitratord elif ((${os_type}==2)); then - ${csudo} cp -f ${script_dir}/init.d/tarbitratord.rpm ${install_main_dir}/init.d/tarbitratord - ${csudo} cp ${script_dir}/init.d/tarbitratord.rpm ${service_config_dir}/tarbitratord && ${csudo} chmod a+x ${service_config_dir}/tarbitratord + ${csudo}cp -f ${script_dir}/init.d/tarbitratord.rpm ${install_main_dir}/init.d/tarbitratord + ${csudo}cp ${script_dir}/init.d/tarbitratord.rpm ${service_config_dir}/tarbitratord && ${csudo}chmod a+x ${service_config_dir}/tarbitratord fi if ((${initd_mod}==1)); then - ${csudo} chkconfig --add tarbitratord || : - ${csudo} chkconfig --level 2345 tarbitratord on || : + ${csudo}chkconfig --add tarbitratord || : + ${csudo}chkconfig --level 2345 tarbitratord on || : elif ((${initd_mod}==2)); then - ${csudo} insserv tarbitratord || : - ${csudo} insserv -d tarbitratord || : + ${csudo}insserv tarbitratord || : + ${csudo}insserv -d tarbitratord || : elif ((${initd_mod}==3)); then - ${csudo} update-rc.d tarbitratord defaults || : + ${csudo}update-rc.d tarbitratord defaults || : fi } @@ -176,11 +176,11 @@ function clean_service_on_systemd() { tarbitratord_service_config="${service_config_dir}/tarbitratord.service" if systemctl is-active --quiet tarbitratord; then echo "tarbitrator is running, stopping it..." - ${csudo} systemctl stop tarbitratord &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop tarbitratord &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable tarbitratord &> /dev/null || echo &> /dev/null + ${csudo}systemctl disable tarbitratord &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${tarbitratord_service_config} + ${csudo}rm -f ${tarbitratord_service_config} } function install_service_on_systemd() { @@ -188,27 +188,27 @@ function install_service_on_systemd() { tarbitratord_service_config="${service_config_dir}/tarbitratord.service" - ${csudo} bash -c "echo '[Unit]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Description=KingHistorian arbitrator service' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'After=network-online.target' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Wants=network-online.target' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo '[Service]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Type=simple' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'ExecStart=/usr/bin/tarbitrator' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitCORE=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StandardOutput=null' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Restart=always' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StartLimitBurst=3' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo '[Install]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${tarbitratord_service_config}" - ${csudo} systemctl enable tarbitratord + ${csudo}bash -c "echo '[Unit]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Description=KingHistorian arbitrator service' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'After=network-online.target' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Wants=network-online.target' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo '[Service]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Type=simple' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'ExecStart=/usr/bin/tarbitrator' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'TimeoutStopSec=1000000s' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitNOFILE=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitNPROC=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitCORE=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'TimeoutStartSec=0' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StandardOutput=null' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Restart=always' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StartLimitBurst=3' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StartLimitInterval=60s' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo '[Install]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'WantedBy=multi-user.target' >> ${tarbitratord_service_config}" + ${csudo}systemctl enable tarbitratord } function install_service() { @@ -227,9 +227,9 @@ function update() { # Stop the service if running if pidof tarbitrator &> /dev/null; then if ((${service_mod}==0)); then - ${csudo} systemctl stop tarbitratord || : + ${csudo}systemctl stop tarbitratord || : elif ((${service_mod}==1)); then - ${csudo} service tarbitratord stop || : + ${csudo}service tarbitratord stop || : else kill_tarbitrator fi @@ -243,9 +243,9 @@ function update() { echo if ((${service_mod}==0)); then - echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo} systemctl start tarbitratord${NC}" + echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo}systemctl start tarbitratord${NC}" elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo} service tarbitratord start${NC}" + echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo}service tarbitratord start${NC}" else echo -e "${GREEN_DARK}To start arbitrator ${NC}: ./tarbitrator${NC}" fi @@ -263,9 +263,9 @@ function install() { install_service echo if ((${service_mod}==0)); then - echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo} systemctl start tarbitratord${NC}" + echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo}systemctl start tarbitratord${NC}" elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo} service tarbitratord start${NC}" + echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo}service tarbitratord start${NC}" else echo -e "${GREEN_DARK}To start arbitrator ${NC}: tarbitrator${NC}" fi diff --git a/packaging/tools/install_arbi_power.sh b/packaging/tools/install_arbi_power.sh index 755684d1bdb1ea02781518e9a78ccf1d881fb271..94f1b7fc538874d8c03aa1ecffce4bee528e8c0c 100755 --- a/packaging/tools/install_arbi_power.sh +++ b/packaging/tools/install_arbi_power.sh @@ -29,7 +29,7 @@ NC='\033[0m' csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi update_flag=0 @@ -91,77 +91,77 @@ fi function kill_tarbitrator() { pid=$(ps -ef | grep "tarbitrator" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function install_main_path() { #create install main dir and all sub dir - ${csudo} rm -rf ${install_main_dir} || : - ${csudo} mkdir -p ${install_main_dir} - ${csudo} mkdir -p ${install_main_dir}/bin - #${csudo} mkdir -p ${install_main_dir}/include - ${csudo} mkdir -p ${install_main_dir}/init.d + ${csudo}rm -rf ${install_main_dir} || : + ${csudo}mkdir -p ${install_main_dir} + ${csudo}mkdir -p ${install_main_dir}/bin + #${csudo}mkdir -p ${install_main_dir}/include + ${csudo}mkdir -p ${install_main_dir}/init.d } function install_bin() { # Remove links - ${csudo} rm -f ${bin_link_dir}/rmtarbitrator || : - ${csudo} rm -f ${bin_link_dir}/tarbitrator || : - ${csudo} cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo} chmod 0555 ${install_main_dir}/bin/* + ${csudo}rm -f ${bin_link_dir}/rmtarbitrator || : + ${csudo}rm -f ${bin_link_dir}/tarbitrator || : + ${csudo}cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo}chmod 0555 ${install_main_dir}/bin/* #Make link - [ -x ${install_main_dir}/bin/remove_arbi_power.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove_arbi_power.sh ${bin_link_dir}/rmtarbitrator || : - [ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo} ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || : + [ -x ${install_main_dir}/bin/remove_arbi_power.sh ] && ${csudo}ln -s ${install_main_dir}/bin/remove_arbi_power.sh ${bin_link_dir}/rmtarbitrator || : + [ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo}ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || : } function install_jemalloc() { jemalloc_dir=${script_dir}/jemalloc if [ -d ${jemalloc_dir} ]; then - ${csudo} /usr/bin/install -c -d /usr/local/bin + ${csudo}/usr/bin/install -c -d /usr/local/bin if [ -f ${jemalloc_dir}/bin/jemalloc-config ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc-config /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc-config /usr/local/bin fi if [ -f ${jemalloc_dir}/bin/jemalloc.sh ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc.sh /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc.sh /usr/local/bin fi if [ -f ${jemalloc_dir}/bin/jeprof ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jeprof /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jeprof /usr/local/bin fi if [ -f ${jemalloc_dir}/include/jemalloc/jemalloc.h ]; then - ${csudo} /usr/bin/install -c -d /usr/local/include/jemalloc - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/include/jemalloc/jemalloc.h /usr/local/include/jemalloc + ${csudo}/usr/bin/install -c -d /usr/local/include/jemalloc + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/include/jemalloc/jemalloc.h /usr/local/include/jemalloc fi if [ -f ${jemalloc_dir}/lib/libjemalloc.so.2 ]; then - ${csudo} /usr/bin/install -c -d /usr/local/lib - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.so.2 /usr/local/lib - ${csudo} ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so - ${csudo} /usr/bin/install -c -d /usr/local/lib + ${csudo}/usr/bin/install -c -d /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.so.2 /usr/local/lib + ${csudo}ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so + ${csudo}/usr/bin/install -c -d /usr/local/lib if [ -f ${jemalloc_dir}/lib/libjemalloc.a ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.a /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.a /usr/local/lib fi if [ -f ${jemalloc_dir}/lib/libjemalloc_pic.a ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc_pic.a /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc_pic.a /usr/local/lib fi if [ -f ${jemalloc_dir}/lib/libjemalloc_pic.a ]; then - ${csudo} /usr/bin/install -c -d /usr/local/lib/pkgconfig - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/lib/pkgconfig/jemalloc.pc /usr/local/lib/pkgconfig + ${csudo}/usr/bin/install -c -d /usr/local/lib/pkgconfig + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/lib/pkgconfig/jemalloc.pc /usr/local/lib/pkgconfig fi fi if [ -f ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html ]; then - ${csudo} /usr/bin/install -c -d /usr/local/share/doc/jemalloc - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html /usr/local/share/doc/jemalloc + ${csudo}/usr/bin/install -c -d /usr/local/share/doc/jemalloc + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html /usr/local/share/doc/jemalloc fi if [ -f ${jemalloc_dir}/share/man/man3/jemalloc.3 ]; then - ${csudo} /usr/bin/install -c -d /usr/local/share/man/man3 - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/share/man/man3/jemalloc.3 /usr/local/share/man/man3 + ${csudo}/usr/bin/install -c -d /usr/local/share/man/man3 + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/share/man/man3/jemalloc.3 /usr/local/share/man/man3 fi if [ -d /etc/ld.so.conf.d ]; then - echo "/usr/local/lib" | ${csudo} tee /etc/ld.so.conf.d/jemalloc.conf > /dev/null || echo -e "failed to write /etc/ld.so.conf.d/jemalloc.conf" - ${csudo} ldconfig + echo "/usr/local/lib" | ${csudo}tee /etc/ld.so.conf.d/jemalloc.conf > /dev/null || echo -e "failed to write /etc/ld.so.conf.d/jemalloc.conf" + ${csudo}ldconfig else echo "/etc/ld.so.conf.d not found!" fi @@ -169,36 +169,36 @@ function install_jemalloc() { } function install_header() { - ${csudo} rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h || : - ${csudo} cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo} chmod 644 ${install_main_dir}/include/* - ${csudo} ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h - ${csudo} ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h - ${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h + ${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h || : + ${csudo}cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo}chmod 644 ${install_main_dir}/include/* + ${csudo}ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h + ${csudo}ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h + ${csudo}ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h } function clean_service_on_sysvinit() { if pidof tarbitrator &> /dev/null; then - ${csudo} service tarbitratord stop || : + ${csudo}service tarbitratord stop || : fi if ((${initd_mod}==1)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} chkconfig --del tarbitratord || : + ${csudo}chkconfig --del tarbitratord || : fi elif ((${initd_mod}==2)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} insserv -r tarbitratord || : + ${csudo}insserv -r tarbitratord || : fi elif ((${initd_mod}==3)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} update-rc.d -f tarbitratord remove || : + ${csudo}update-rc.d -f tarbitratord remove || : fi fi - ${csudo} rm -f ${service_config_dir}/tarbitratord || : + ${csudo}rm -f ${service_config_dir}/tarbitratord || : if $(which init &> /dev/null); then - ${csudo} init q || : + ${csudo}init q || : fi } @@ -209,24 +209,24 @@ function install_service_on_sysvinit() { # Install powerd service if ((${os_type}==1)); then - ${csudo} cp -f ${script_dir}/init.d/tarbitratord.deb ${install_main_dir}/init.d/tarbitratord - ${csudo} cp ${script_dir}/init.d/tarbitratord.deb ${service_config_dir}/tarbitratord && ${csudo} chmod a+x ${service_config_dir}/tarbitratord + ${csudo}cp -f ${script_dir}/init.d/tarbitratord.deb ${install_main_dir}/init.d/tarbitratord + ${csudo}cp ${script_dir}/init.d/tarbitratord.deb ${service_config_dir}/tarbitratord && ${csudo}chmod a+x ${service_config_dir}/tarbitratord elif ((${os_type}==2)); then - ${csudo} cp -f ${script_dir}/init.d/tarbitratord.rpm ${install_main_dir}/init.d/tarbitratord - ${csudo} cp ${script_dir}/init.d/tarbitratord.rpm ${service_config_dir}/tarbitratord && ${csudo} chmod a+x ${service_config_dir}/tarbitratord + ${csudo}cp -f ${script_dir}/init.d/tarbitratord.rpm ${install_main_dir}/init.d/tarbitratord + ${csudo}cp ${script_dir}/init.d/tarbitratord.rpm ${service_config_dir}/tarbitratord && ${csudo}chmod a+x ${service_config_dir}/tarbitratord fi #restart_config_str="power:2345:respawn:${service_config_dir}/powerd start" - #${csudo} grep -q -F "$restart_config_str" /etc/inittab || ${csudo} bash -c "echo '${restart_config_str}' >> /etc/inittab" + #${csudo}grep -q -F "$restart_config_str" /etc/inittab || ${csudo}bash -c "echo '${restart_config_str}' >> /etc/inittab" if ((${initd_mod}==1)); then - ${csudo} chkconfig --add tarbitratord || : - ${csudo} chkconfig --level 2345 tarbitratord on || : + ${csudo}chkconfig --add tarbitratord || : + ${csudo}chkconfig --level 2345 tarbitratord on || : elif ((${initd_mod}==2)); then - ${csudo} insserv tarbitratord || : - ${csudo} insserv -d tarbitratord || : + ${csudo}insserv tarbitratord || : + ${csudo}insserv -d tarbitratord || : elif ((${initd_mod}==3)); then - ${csudo} update-rc.d tarbitratord defaults || : + ${csudo}update-rc.d tarbitratord defaults || : fi } @@ -234,11 +234,11 @@ function clean_service_on_systemd() { tarbitratord_service_config="${service_config_dir}/tarbitratord.service" if systemctl is-active --quiet tarbitratord; then echo "tarbitrator is running, stopping it..." - ${csudo} systemctl stop tarbitratord &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop tarbitratord &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable tarbitratord &> /dev/null || echo &> /dev/null + ${csudo}systemctl disable tarbitratord &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${tarbitratord_service_config} + ${csudo}rm -f ${tarbitratord_service_config} } # power:2345:respawn:/etc/init.d/tarbitratord start @@ -248,27 +248,27 @@ function install_service_on_systemd() { tarbitratord_service_config="${service_config_dir}/tarbitratord.service" - ${csudo} bash -c "echo '[Unit]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Description=PowerDB arbitrator service' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'After=network-online.target' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Wants=network-online.target' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo '[Service]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Type=simple' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'ExecStart=/usr/bin/tarbitrator' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitCORE=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StandardOutput=null' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Restart=always' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StartLimitBurst=3' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo '[Install]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${tarbitratord_service_config}" - ${csudo} systemctl enable tarbitratord + ${csudo}bash -c "echo '[Unit]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Description=PowerDB arbitrator service' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'After=network-online.target' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Wants=network-online.target' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo '[Service]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Type=simple' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'ExecStart=/usr/bin/tarbitrator' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'TimeoutStopSec=1000000s' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitNOFILE=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitNPROC=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitCORE=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'TimeoutStartSec=0' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StandardOutput=null' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Restart=always' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StartLimitBurst=3' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StartLimitInterval=60s' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo '[Install]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'WantedBy=multi-user.target' >> ${tarbitratord_service_config}" + ${csudo}systemctl enable tarbitratord } function install_service() { @@ -287,9 +287,9 @@ function update_PowerDB() { # Stop the service if running if pidof tarbitrator &> /dev/null; then if ((${service_mod}==0)); then - ${csudo} systemctl stop tarbitratord || : + ${csudo}systemctl stop tarbitratord || : elif ((${service_mod}==1)); then - ${csudo} service tarbitratord stop || : + ${csudo}service tarbitratord stop || : else kill_tarbitrator fi @@ -304,9 +304,9 @@ function update_PowerDB() { echo if ((${service_mod}==0)); then - echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo} systemctl start tarbitratord${NC}" + echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo}systemctl start tarbitratord${NC}" elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo} service tarbitratord start${NC}" + echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo}service tarbitratord start${NC}" else echo -e "${GREEN_DARK}To start arbitrator ${NC}: ./tarbitrator${NC}" fi @@ -326,9 +326,9 @@ function install_PowerDB() { echo if ((${service_mod}==0)); then - echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo} systemctl start tarbitratord${NC}" + echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo}systemctl start tarbitratord${NC}" elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo} service tarbitratord start${NC}" + echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo}service tarbitratord start${NC}" else echo -e "${GREEN_DARK}To start arbitrator ${NC}: tarbitrator${NC}" fi diff --git a/packaging/tools/install_arbi_pro.sh b/packaging/tools/install_arbi_pro.sh index 3e80ad8215e3ec709c17a6a46e34f5bd6cf7ac6c..5c5fa485b8852ea87fdbd58cc76a6b4b6b4377de 100755 --- a/packaging/tools/install_arbi_pro.sh +++ b/packaging/tools/install_arbi_pro.sh @@ -29,7 +29,7 @@ NC='\033[0m' csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi update_flag=0 @@ -91,61 +91,61 @@ fi function kill_tarbitrator() { pid=$(ps -ef | grep "tarbitrator" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function install_main_path() { #create install main dir and all sub dir - ${csudo} rm -rf ${install_main_dir} || : - ${csudo} mkdir -p ${install_main_dir} - ${csudo} mkdir -p ${install_main_dir}/bin - #${csudo} mkdir -p ${install_main_dir}/include - ${csudo} mkdir -p ${install_main_dir}/init.d + ${csudo}rm -rf ${install_main_dir} || : + ${csudo}mkdir -p ${install_main_dir} + ${csudo}mkdir -p ${install_main_dir}/bin + #${csudo}mkdir -p ${install_main_dir}/include + ${csudo}mkdir -p ${install_main_dir}/init.d } function install_bin() { # Remove links - ${csudo} rm -f ${bin_link_dir}/rmtarbitrator || : - ${csudo} rm -f ${bin_link_dir}/tarbitrator || : - ${csudo} cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo} chmod 0555 ${install_main_dir}/bin/* + ${csudo}rm -f ${bin_link_dir}/rmtarbitrator || : + ${csudo}rm -f ${bin_link_dir}/tarbitrator || : + ${csudo}cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo}chmod 0555 ${install_main_dir}/bin/* #Make link - [ -x ${install_main_dir}/bin/remove_arbi_prodb.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove_arbi_prodb.sh ${bin_link_dir}/rmtarbitrator || : - [ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo} ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || : + [ -x ${install_main_dir}/bin/remove_arbi_prodb.sh ] && ${csudo}ln -s ${install_main_dir}/bin/remove_arbi_prodb.sh ${bin_link_dir}/rmtarbitrator || : + [ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo}ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || : } function install_header() { - ${csudo} rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h || : - ${csudo} cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo} chmod 644 ${install_main_dir}/include/* - ${csudo} ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h - ${csudo} ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h - ${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h + ${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h || : + ${csudo}cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo}chmod 644 ${install_main_dir}/include/* + ${csudo}ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h + ${csudo}ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h + ${csudo}ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h } function clean_service_on_sysvinit() { if pidof tarbitrator &> /dev/null; then - ${csudo} service tarbitratord stop || : + ${csudo}service tarbitratord stop || : fi if ((${initd_mod}==1)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} chkconfig --del tarbitratord || : + ${csudo}chkconfig --del tarbitratord || : fi elif ((${initd_mod}==2)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} insserv -r tarbitratord || : + ${csudo}insserv -r tarbitratord || : fi elif ((${initd_mod}==3)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} update-rc.d -f tarbitratord remove || : + ${csudo}update-rc.d -f tarbitratord remove || : fi fi - ${csudo} rm -f ${service_config_dir}/tarbitratord || : + ${csudo}rm -f ${service_config_dir}/tarbitratord || : if $(which init &> /dev/null); then - ${csudo} init q || : + ${csudo}init q || : fi } @@ -156,21 +156,21 @@ function install_service_on_sysvinit() { # Install prodbs service if ((${os_type}==1)); then - ${csudo} cp -f ${script_dir}/init.d/tarbitratord.deb ${install_main_dir}/init.d/tarbitratord - ${csudo} cp ${script_dir}/init.d/tarbitratord.deb ${service_config_dir}/tarbitratord && ${csudo} chmod a+x ${service_config_dir}/tarbitratord + ${csudo}cp -f ${script_dir}/init.d/tarbitratord.deb ${install_main_dir}/init.d/tarbitratord + ${csudo}cp ${script_dir}/init.d/tarbitratord.deb ${service_config_dir}/tarbitratord && ${csudo}chmod a+x ${service_config_dir}/tarbitratord elif ((${os_type}==2)); then - ${csudo} cp -f ${script_dir}/init.d/tarbitratord.rpm ${install_main_dir}/init.d/tarbitratord - ${csudo} cp ${script_dir}/init.d/tarbitratord.rpm ${service_config_dir}/tarbitratord && ${csudo} chmod a+x ${service_config_dir}/tarbitratord + ${csudo}cp -f ${script_dir}/init.d/tarbitratord.rpm ${install_main_dir}/init.d/tarbitratord + ${csudo}cp ${script_dir}/init.d/tarbitratord.rpm ${service_config_dir}/tarbitratord && ${csudo}chmod a+x ${service_config_dir}/tarbitratord fi if ((${initd_mod}==1)); then - ${csudo} chkconfig --add tarbitratord || : - ${csudo} chkconfig --level 2345 tarbitratord on || : + ${csudo}chkconfig --add tarbitratord || : + ${csudo}chkconfig --level 2345 tarbitratord on || : elif ((${initd_mod}==2)); then - ${csudo} insserv tarbitratord || : - ${csudo} insserv -d tarbitratord || : + ${csudo}insserv tarbitratord || : + ${csudo}insserv -d tarbitratord || : elif ((${initd_mod}==3)); then - ${csudo} update-rc.d tarbitratord defaults || : + ${csudo}update-rc.d tarbitratord defaults || : fi } @@ -178,11 +178,11 @@ function clean_service_on_systemd() { tarbitratord_service_config="${service_config_dir}/tarbitratord.service" if systemctl is-active --quiet tarbitratord; then echo "tarbitrator is running, stopping it..." - ${csudo} systemctl stop tarbitratord &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop tarbitratord &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable tarbitratord &> /dev/null || echo &> /dev/null + ${csudo}systemctl disable tarbitratord &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${tarbitratord_service_config} + ${csudo}rm -f ${tarbitratord_service_config} } function install_service_on_systemd() { @@ -190,27 +190,27 @@ function install_service_on_systemd() { tarbitratord_service_config="${service_config_dir}/tarbitratord.service" - ${csudo} bash -c "echo '[Unit]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Description=ProDB arbitrator service' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'After=network-online.target' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Wants=network-online.target' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo '[Service]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Type=simple' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'ExecStart=/usr/bin/tarbitrator' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitCORE=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StandardOutput=null' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Restart=always' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StartLimitBurst=3' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo '[Install]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${tarbitratord_service_config}" - ${csudo} systemctl enable tarbitratord + ${csudo}bash -c "echo '[Unit]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Description=ProDB arbitrator service' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'After=network-online.target' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Wants=network-online.target' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo '[Service]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Type=simple' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'ExecStart=/usr/bin/tarbitrator' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'TimeoutStopSec=1000000s' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitNOFILE=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitNPROC=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitCORE=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'TimeoutStartSec=0' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StandardOutput=null' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Restart=always' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StartLimitBurst=3' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StartLimitInterval=60s' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo '[Install]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'WantedBy=multi-user.target' >> ${tarbitratord_service_config}" + ${csudo}systemctl enable tarbitratord } function install_service() { @@ -229,9 +229,9 @@ function update_prodb() { # Stop the service if running if pidof tarbitrator &> /dev/null; then if ((${service_mod}==0)); then - ${csudo} systemctl stop tarbitratord || : + ${csudo}systemctl stop tarbitratord || : elif ((${service_mod}==1)); then - ${csudo} service tarbitratord stop || : + ${csudo}service tarbitratord stop || : else kill_tarbitrator fi @@ -245,9 +245,9 @@ function update_prodb() { echo if ((${service_mod}==0)); then - echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo} systemctl start tarbitratord${NC}" + echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo}systemctl start tarbitratord${NC}" elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo} service tarbitratord start${NC}" + echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo}service tarbitratord start${NC}" else echo -e "${GREEN_DARK}To start arbitrator ${NC}: ./tarbitrator${NC}" fi @@ -265,9 +265,9 @@ function install_prodb() { install_service echo if ((${service_mod}==0)); then - echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo} systemctl start tarbitratord${NC}" + echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo}systemctl start tarbitratord${NC}" elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo} service tarbitratord start${NC}" + echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo}service tarbitratord start${NC}" else echo -e "${GREEN_DARK}To start arbitrator ${NC}: tarbitrator${NC}" fi diff --git a/packaging/tools/install_arbi_tq.sh b/packaging/tools/install_arbi_tq.sh index 8757326605b05aca63a585d1c3e1c66c98f6aaa7..132346a749f1559436e6db244593c660dbd69556 100755 --- a/packaging/tools/install_arbi_tq.sh +++ b/packaging/tools/install_arbi_tq.sh @@ -29,7 +29,7 @@ NC='\033[0m' csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi update_flag=0 @@ -91,61 +91,61 @@ fi function kill_tarbitrator() { pid=$(ps -ef | grep "tarbitrator" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function install_main_path() { #create install main dir and all sub dir - ${csudo} rm -rf ${install_main_dir} || : - ${csudo} mkdir -p ${install_main_dir} - ${csudo} mkdir -p ${install_main_dir}/bin - #${csudo} mkdir -p ${install_main_dir}/include - ${csudo} mkdir -p ${install_main_dir}/init.d + ${csudo}rm -rf ${install_main_dir} || : + ${csudo}mkdir -p ${install_main_dir} + ${csudo}mkdir -p ${install_main_dir}/bin + #${csudo}mkdir -p ${install_main_dir}/include + ${csudo}mkdir -p ${install_main_dir}/init.d } function install_bin() { # Remove links - ${csudo} rm -f ${bin_link_dir}/rmtarbitrator || : - ${csudo} rm -f ${bin_link_dir}/tarbitrator || : - ${csudo} cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo} chmod 0555 ${install_main_dir}/bin/* + ${csudo}rm -f ${bin_link_dir}/rmtarbitrator || : + ${csudo}rm -f ${bin_link_dir}/tarbitrator || : + ${csudo}cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo}chmod 0555 ${install_main_dir}/bin/* #Make link - [ -x ${install_main_dir}/bin/remove_arbi_tq.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove_arbi_tq.sh ${bin_link_dir}/rmtarbitrator || : - [ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo} ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || : + [ -x ${install_main_dir}/bin/remove_arbi_tq.sh ] && ${csudo}ln -s ${install_main_dir}/bin/remove_arbi_tq.sh ${bin_link_dir}/rmtarbitrator || : + [ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo}ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || : } function install_header() { - ${csudo} rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h || : - ${csudo} cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo} chmod 644 ${install_main_dir}/include/* - ${csudo} ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h - ${csudo} ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h - ${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h + ${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h || : + ${csudo}cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo}chmod 644 ${install_main_dir}/include/* + ${csudo}ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h + ${csudo}ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h + ${csudo}ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h } function clean_service_on_sysvinit() { if pidof tarbitrator &> /dev/null; then - ${csudo} service tarbitratord stop || : + ${csudo}service tarbitratord stop || : fi if ((${initd_mod}==1)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} chkconfig --del tarbitratord || : + ${csudo}chkconfig --del tarbitratord || : fi elif ((${initd_mod}==2)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} insserv -r tarbitratord || : + ${csudo}insserv -r tarbitratord || : fi elif ((${initd_mod}==3)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} update-rc.d -f tarbitratord remove || : + ${csudo}update-rc.d -f tarbitratord remove || : fi fi - ${csudo} rm -f ${service_config_dir}/tarbitratord || : + ${csudo}rm -f ${service_config_dir}/tarbitratord || : if $(which init &> /dev/null); then - ${csudo} init q || : + ${csudo}init q || : fi } @@ -156,24 +156,24 @@ function install_service_on_sysvinit() { # Install tqd service if ((${os_type}==1)); then - ${csudo} cp -f ${script_dir}/init.d/tarbitratord.deb ${install_main_dir}/init.d/tarbitratord - ${csudo} cp ${script_dir}/init.d/tarbitratord.deb ${service_config_dir}/tarbitratord && ${csudo} chmod a+x ${service_config_dir}/tarbitratord + ${csudo}cp -f ${script_dir}/init.d/tarbitratord.deb ${install_main_dir}/init.d/tarbitratord + ${csudo}cp ${script_dir}/init.d/tarbitratord.deb ${service_config_dir}/tarbitratord && ${csudo}chmod a+x ${service_config_dir}/tarbitratord elif ((${os_type}==2)); then - ${csudo} cp -f ${script_dir}/init.d/tarbitratord.rpm ${install_main_dir}/init.d/tarbitratord - ${csudo} cp ${script_dir}/init.d/tarbitratord.rpm ${service_config_dir}/tarbitratord && ${csudo} chmod a+x ${service_config_dir}/tarbitratord + ${csudo}cp -f ${script_dir}/init.d/tarbitratord.rpm ${install_main_dir}/init.d/tarbitratord + ${csudo}cp ${script_dir}/init.d/tarbitratord.rpm ${service_config_dir}/tarbitratord && ${csudo}chmod a+x ${service_config_dir}/tarbitratord fi #restart_config_str="tq:2345:respawn:${service_config_dir}/tqd start" - #${csudo} grep -q -F "$restart_config_str" /etc/inittab || ${csudo} bash -c "echo '${restart_config_str}' >> /etc/inittab" + #${csudo}grep -q -F "$restart_config_str" /etc/inittab || ${csudo}bash -c "echo '${restart_config_str}' >> /etc/inittab" if ((${initd_mod}==1)); then - ${csudo} chkconfig --add tarbitratord || : - ${csudo} chkconfig --level 2345 tarbitratord on || : + ${csudo}chkconfig --add tarbitratord || : + ${csudo}chkconfig --level 2345 tarbitratord on || : elif ((${initd_mod}==2)); then - ${csudo} insserv tarbitratord || : - ${csudo} insserv -d tarbitratord || : + ${csudo}insserv tarbitratord || : + ${csudo}insserv -d tarbitratord || : elif ((${initd_mod}==3)); then - ${csudo} update-rc.d tarbitratord defaults || : + ${csudo}update-rc.d tarbitratord defaults || : fi } @@ -181,11 +181,11 @@ function clean_service_on_systemd() { tarbitratord_service_config="${service_config_dir}/tarbitratord.service" if systemctl is-active --quiet tarbitratord; then echo "tarbitrator is running, stopping it..." - ${csudo} systemctl stop tarbitratord &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop tarbitratord &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable tarbitratord &> /dev/null || echo &> /dev/null + ${csudo}systemctl disable tarbitratord &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${tarbitratord_service_config} + ${csudo}rm -f ${tarbitratord_service_config} } # tq:2345:respawn:/etc/init.d/tarbitratord start @@ -195,27 +195,27 @@ function install_service_on_systemd() { tarbitratord_service_config="${service_config_dir}/tarbitratord.service" - ${csudo} bash -c "echo '[Unit]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Description=TQ arbitrator service' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'After=network-online.target' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Wants=network-online.target' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo '[Service]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Type=simple' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'ExecStart=/usr/bin/tarbitrator' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitCORE=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StandardOutput=null' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Restart=always' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StartLimitBurst=3' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo '[Install]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${tarbitratord_service_config}" - ${csudo} systemctl enable tarbitratord + ${csudo}bash -c "echo '[Unit]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Description=TQ arbitrator service' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'After=network-online.target' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Wants=network-online.target' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo '[Service]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Type=simple' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'ExecStart=/usr/bin/tarbitrator' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'TimeoutStopSec=1000000s' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitNOFILE=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitNPROC=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitCORE=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'TimeoutStartSec=0' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StandardOutput=null' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Restart=always' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StartLimitBurst=3' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StartLimitInterval=60s' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo '[Install]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'WantedBy=multi-user.target' >> ${tarbitratord_service_config}" + ${csudo}systemctl enable tarbitratord } function install_service() { @@ -234,9 +234,9 @@ function update_tq() { # Stop the service if running if pidof tarbitrator &> /dev/null; then if ((${service_mod}==0)); then - ${csudo} systemctl stop tarbitratord || : + ${csudo}systemctl stop tarbitratord || : elif ((${service_mod}==1)); then - ${csudo} service tarbitratord stop || : + ${csudo}service tarbitratord stop || : else kill_tarbitrator fi @@ -250,9 +250,9 @@ function update_tq() { echo if ((${service_mod}==0)); then - echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo} systemctl start tarbitratord${NC}" + echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo}systemctl start tarbitratord${NC}" elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo} service tarbitratord start${NC}" + echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo}service tarbitratord start${NC}" else echo -e "${GREEN_DARK}To start arbitrator ${NC}: ./tarbitrator${NC}" fi @@ -270,9 +270,9 @@ function install_tq() { install_service echo if ((${service_mod}==0)); then - echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo} systemctl start tarbitratord${NC}" + echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo}systemctl start tarbitratord${NC}" elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo} service tarbitratord start${NC}" + echo -e "${GREEN_DARK}To start arbitrator ${NC}: ${csudo}service tarbitratord start${NC}" else echo -e "${GREEN_DARK}To start arbitrator ${NC}: tarbitrator${NC}" fi diff --git a/packaging/tools/install_client.sh b/packaging/tools/install_client.sh index a73f6ac9718064855a245c0505e179b6376d7c96..4ea60d1d55336d606f7eabf10b464cff90860519 100755 --- a/packaging/tools/install_client.sh +++ b/packaging/tools/install_client.sh @@ -57,7 +57,7 @@ NC='\033[0m' csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi update_flag=0 @@ -65,40 +65,40 @@ update_flag=0 function kill_client() { pid=$(ps -ef | grep "taos" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function install_main_path() { #create install main dir and all sub dir - ${csudo} rm -rf ${install_main_dir} || : - ${csudo} mkdir -p ${install_main_dir} - ${csudo} mkdir -p ${install_main_dir}/cfg - ${csudo} mkdir -p ${install_main_dir}/bin - ${csudo} mkdir -p ${install_main_dir}/connector - ${csudo} mkdir -p ${install_main_dir}/driver - ${csudo} mkdir -p ${install_main_dir}/examples - ${csudo} mkdir -p ${install_main_dir}/include + ${csudo}rm -rf ${install_main_dir} || : + ${csudo}mkdir -p ${install_main_dir} + ${csudo}mkdir -p ${install_main_dir}/cfg + ${csudo}mkdir -p ${install_main_dir}/bin + ${csudo}mkdir -p ${install_main_dir}/connector + ${csudo}mkdir -p ${install_main_dir}/driver + ${csudo}mkdir -p ${install_main_dir}/examples + ${csudo}mkdir -p ${install_main_dir}/include } function install_bin() { # Remove links - ${csudo} rm -f ${bin_link_dir}/taos || : + ${csudo}rm -f ${bin_link_dir}/taos || : if [ "$osType" != "Darwin" ]; then - ${csudo} rm -f ${bin_link_dir}/taosdemo || : + ${csudo}rm -f ${bin_link_dir}/taosdemo || : fi - ${csudo} rm -f ${bin_link_dir}/rmtaos || : - ${csudo} rm -f ${bin_link_dir}/set_core || : + ${csudo}rm -f ${bin_link_dir}/rmtaos || : + ${csudo}rm -f ${bin_link_dir}/set_core || : - ${csudo} cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo} chmod 0555 ${install_main_dir}/bin/* + ${csudo}cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo}chmod 0555 ${install_main_dir}/bin/* #Make link - [ -x ${install_main_dir}/bin/taos ] && ${csudo} ln -s ${install_main_dir}/bin/taos ${bin_link_dir}/taos || : + [ -x ${install_main_dir}/bin/taos ] && ${csudo}ln -s ${install_main_dir}/bin/taos ${bin_link_dir}/taos || : if [ "$osType" != "Darwin" ]; then - [ -x ${install_main_dir}/bin/taosdemo ] && ${csudo} ln -s ${install_main_dir}/bin/taosdemo ${bin_link_dir}/taosdemo || : + [ -x ${install_main_dir}/bin/taosdemo ] && ${csudo}ln -s ${install_main_dir}/bin/taosdemo ${bin_link_dir}/taosdemo || : fi - [ -x ${install_main_dir}/bin/remove_client.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove_client.sh ${bin_link_dir}/rmtaos || : - [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo} ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : + [ -x ${install_main_dir}/bin/remove_client.sh ] && ${csudo}ln -s ${install_main_dir}/bin/remove_client.sh ${bin_link_dir}/rmtaos || : + [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo}ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : } function clean_lib() { @@ -108,87 +108,87 @@ function clean_lib() { function install_lib() { # Remove links - ${csudo} rm -f ${lib_link_dir}/libtaos.* || : - ${csudo} rm -f ${lib64_link_dir}/libtaos.* || : - #${csudo} rm -rf ${v15_java_app_dir} || : + ${csudo}rm -f ${lib_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : + #${csudo}rm -rf ${v15_java_app_dir} || : - ${csudo} cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo} chmod 777 ${install_main_dir}/driver/* + ${csudo}cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo}chmod 777 ${install_main_dir}/driver/* if [ "$osType" != "Darwin" ]; then - ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 - ${csudo} ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so + ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 + ${csudo}ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so if [ -d "${lib64_link_dir}" ]; then - ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 || : - ${csudo} ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || : + ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 || : + ${csudo}ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || : fi else - ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.1.dylib - ${csudo} ln -s ${lib_link_dir}/libtaos.1.dylib ${lib_link_dir}/libtaos.dylib + ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.1.dylib + ${csudo}ln -s ${lib_link_dir}/libtaos.1.dylib ${lib_link_dir}/libtaos.dylib fi if [ "$osType" != "Darwin" ]; then - ${csudo} ldconfig + ${csudo}ldconfig else - ${csudo} update_dyld_shared_cache + ${csudo}update_dyld_shared_cache fi } function install_header() { - ${csudo} rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h || : - ${csudo} cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo} chmod 644 ${install_main_dir}/include/* - ${csudo} ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h - ${csudo} ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h - ${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h + ${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h || : + ${csudo}cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo}chmod 644 ${install_main_dir}/include/* + ${csudo}ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h + ${csudo}ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h + ${csudo}ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h } function install_jemalloc() { jemalloc_dir=${script_dir}/jemalloc if [ -d ${jemalloc_dir} ]; then - ${csudo} /usr/bin/install -c -d /usr/local/bin + ${csudo}/usr/bin/install -c -d /usr/local/bin if [ -f ${jemalloc_dir}/bin/jemalloc-config ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc-config /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc-config /usr/local/bin fi if [ -f ${jemalloc_dir}/bin/jemalloc.sh ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc.sh /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc.sh /usr/local/bin fi if [ -f ${jemalloc_dir}/bin/jeprof ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jeprof /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jeprof /usr/local/bin fi if [ -f ${jemalloc_dir}/include/jemalloc/jemalloc.h ]; then - ${csudo} /usr/bin/install -c -d /usr/local/include/jemalloc - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/include/jemalloc/jemalloc.h /usr/local/include/jemalloc + ${csudo}/usr/bin/install -c -d /usr/local/include/jemalloc + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/include/jemalloc/jemalloc.h /usr/local/include/jemalloc fi if [ -f ${jemalloc_dir}/lib/libjemalloc.so.2 ]; then - ${csudo} /usr/bin/install -c -d /usr/local/lib - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.so.2 /usr/local/lib - ${csudo} ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so - ${csudo} /usr/bin/install -c -d /usr/local/lib + ${csudo}/usr/bin/install -c -d /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.so.2 /usr/local/lib + ${csudo}ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so + ${csudo}/usr/bin/install -c -d /usr/local/lib if [ -f ${jemalloc_dir}/lib/libjemalloc.a ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.a /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.a /usr/local/lib fi if [ -f ${jemalloc_dir}/lib/libjemalloc_pic.a ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc_pic.a /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc_pic.a /usr/local/lib fi if [ -f ${jemalloc_dir}/lib/libjemalloc_pic.a ]; then - ${csudo} /usr/bin/install -c -d /usr/local/lib/pkgconfig - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/lib/pkgconfig/jemalloc.pc /usr/local/lib/pkgconfig + ${csudo}/usr/bin/install -c -d /usr/local/lib/pkgconfig + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/lib/pkgconfig/jemalloc.pc /usr/local/lib/pkgconfig fi fi if [ -f ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html ]; then - ${csudo} /usr/bin/install -c -d /usr/local/share/doc/jemalloc - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html /usr/local/share/doc/jemalloc + ${csudo}/usr/bin/install -c -d /usr/local/share/doc/jemalloc + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html /usr/local/share/doc/jemalloc fi if [ -f ${jemalloc_dir}/share/man/man3/jemalloc.3 ]; then - ${csudo} /usr/bin/install -c -d /usr/local/share/man/man3 - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/share/man/man3/jemalloc.3 /usr/local/share/man/man3 + ${csudo}/usr/bin/install -c -d /usr/local/share/man/man3 + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/share/man/man3/jemalloc.3 /usr/local/share/man/man3 fi if [ -d /etc/ld.so.conf.d ]; then - echo "/usr/local/lib" | ${csudo} tee /etc/ld.so.conf.d/jemalloc.conf > /dev/null || echo -e "failed to write /etc/ld.so.conf.d/jemalloc.conf" - ${csudo} ldconfig + echo "/usr/local/lib" | ${csudo}tee /etc/ld.so.conf.d/jemalloc.conf > /dev/null || echo -e "failed to write /etc/ld.so.conf.d/jemalloc.conf" + ${csudo}ldconfig else echo "/etc/ld.so.conf.d not found!" fi @@ -196,37 +196,37 @@ function install_jemalloc() { } function install_config() { - #${csudo} rm -f ${install_main_dir}/cfg/taos.cfg || : + #${csudo}rm -f ${install_main_dir}/cfg/taos.cfg || : if [ ! -f ${cfg_install_dir}/taos.cfg ]; then - ${csudo} mkdir -p ${cfg_install_dir} - [ -f ${script_dir}/cfg/taos.cfg ] && ${csudo} cp ${script_dir}/cfg/taos.cfg ${cfg_install_dir} - ${csudo} chmod 644 ${cfg_install_dir}/* + ${csudo}mkdir -p ${cfg_install_dir} + [ -f ${script_dir}/cfg/taos.cfg ] && ${csudo}cp ${script_dir}/cfg/taos.cfg ${cfg_install_dir} + ${csudo}chmod 644 ${cfg_install_dir}/* fi - ${csudo} cp -f ${script_dir}/cfg/taos.cfg ${install_main_dir}/cfg/taos.cfg.org - ${csudo} ln -s ${cfg_install_dir}/taos.cfg ${install_main_dir}/cfg + ${csudo}cp -f ${script_dir}/cfg/taos.cfg ${install_main_dir}/cfg/taos.cfg.org + ${csudo}ln -s ${cfg_install_dir}/taos.cfg ${install_main_dir}/cfg } function install_log() { - ${csudo} rm -rf ${log_dir} || : + ${csudo}rm -rf ${log_dir} || : if [ "$osType" != "Darwin" ]; then - ${csudo} mkdir -p ${log_dir} && ${csudo} chmod 777 ${log_dir} + ${csudo}mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir} else - mkdir -p ${log_dir} && ${csudo} chmod 777 ${log_dir} + mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir} fi - ${csudo} ln -s ${log_dir} ${install_main_dir}/log + ${csudo}ln -s ${log_dir} ${install_main_dir}/log } function install_connector() { - ${csudo} cp -rf ${script_dir}/connector/ ${install_main_dir}/ + ${csudo}cp -rf ${script_dir}/connector/ ${install_main_dir}/ } function install_examples() { if [ -d ${script_dir}/examples ]; then - ${csudo} cp -rf ${script_dir}/examples/* ${install_main_dir}/examples + ${csudo}cp -rf ${script_dir}/examples/* ${install_main_dir}/examples fi } diff --git a/packaging/tools/install_client_jh.sh b/packaging/tools/install_client_jh.sh index a8599812feaea06120aa3391771e7c94523a53c2..436b683b29b81e612ef15af6cf976f29b42347fc 100755 --- a/packaging/tools/install_client_jh.sh +++ b/packaging/tools/install_client_jh.sh @@ -54,7 +54,7 @@ NC='\033[0m' csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi update_flag=0 @@ -62,42 +62,42 @@ update_flag=0 function kill_client() { pid=$(ps -ef | grep "jh_taos" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function install_main_path() { #create install main dir and all sub dir - ${csudo} rm -rf ${install_main_dir} || : - ${csudo} mkdir -p ${install_main_dir} - ${csudo} mkdir -p ${install_main_dir}/cfg - ${csudo} mkdir -p ${install_main_dir}/bin - ${csudo} mkdir -p ${install_main_dir}/connector - ${csudo} mkdir -p ${install_main_dir}/driver - ${csudo} mkdir -p ${install_main_dir}/examples - ${csudo} mkdir -p ${install_main_dir}/include + ${csudo}rm -rf ${install_main_dir} || : + ${csudo}mkdir -p ${install_main_dir} + ${csudo}mkdir -p ${install_main_dir}/cfg + ${csudo}mkdir -p ${install_main_dir}/bin + ${csudo}mkdir -p ${install_main_dir}/connector + ${csudo}mkdir -p ${install_main_dir}/driver + ${csudo}mkdir -p ${install_main_dir}/examples + ${csudo}mkdir -p ${install_main_dir}/include } function install_bin() { # Remove links - ${csudo} rm -f ${bin_link_dir}/jh_taos || : + ${csudo}rm -f ${bin_link_dir}/jh_taos || : if [ "$osType" != "Darwin" ]; then - ${csudo} rm -f ${bin_link_dir}/jhdemo || : - ${csudo} rm -f ${bin_link_dir}/jh_taosdump || : + ${csudo}rm -f ${bin_link_dir}/jhdemo || : + ${csudo}rm -f ${bin_link_dir}/jh_taosdump || : fi - ${csudo} rm -f ${bin_link_dir}/rmjh || : - ${csudo} rm -f ${bin_link_dir}/set_core || : + ${csudo}rm -f ${bin_link_dir}/rmjh || : + ${csudo}rm -f ${bin_link_dir}/set_core || : - ${csudo} cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo} chmod 0555 ${install_main_dir}/bin/* + ${csudo}cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo}chmod 0555 ${install_main_dir}/bin/* #Make link - [ -x ${install_main_dir}/bin/jh_taos ] && ${csudo} ln -s ${install_main_dir}/bin/jh_taos ${bin_link_dir}/jh_taos || : + [ -x ${install_main_dir}/bin/jh_taos ] && ${csudo}ln -s ${install_main_dir}/bin/jh_taos ${bin_link_dir}/jh_taos || : if [ "$osType" != "Darwin" ]; then - [ -x ${install_main_dir}/bin/jhdemo ] && ${csudo} ln -s ${install_main_dir}/bin/jhdemo ${bin_link_dir}/jhdemo || : - [ -x ${install_main_dir}/bin/jh_taosdump ] && ${csudo} ln -s ${install_main_dir}/bin/jh_taosdump ${bin_link_dir}/jh_taosdump || : + [ -x ${install_main_dir}/bin/jhdemo ] && ${csudo}ln -s ${install_main_dir}/bin/jhdemo ${bin_link_dir}/jhdemo || : + [ -x ${install_main_dir}/bin/jh_taosdump ] && ${csudo}ln -s ${install_main_dir}/bin/jh_taosdump ${bin_link_dir}/jh_taosdump || : fi - [ -x ${install_main_dir}/bin/remove_client_jh.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove_client_jh.sh ${bin_link_dir}/rmjh || : - [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo} ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : + [ -x ${install_main_dir}/bin/remove_client_jh.sh ] && ${csudo}ln -s ${install_main_dir}/bin/remove_client_jh.sh ${bin_link_dir}/rmjh || : + [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo}ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : } function clean_lib() { @@ -107,64 +107,64 @@ function clean_lib() { function install_lib() { # Remove links - ${csudo} rm -f ${lib_link_dir}/libtaos.* || : - ${csudo} rm -f ${lib64_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : - ${csudo} cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo} chmod 777 ${install_main_dir}/driver/* + ${csudo}cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo}chmod 777 ${install_main_dir}/driver/* if [ "$osType" != "Darwin" ]; then - ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 - ${csudo} ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so + ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 + ${csudo}ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so if [ -d "${lib64_link_dir}" ]; then - ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 || : - ${csudo} ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || : + ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 || : + ${csudo}ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || : fi else - ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.1.dylib - ${csudo} ln -s ${lib_link_dir}/libtaos.1.dylib ${lib_link_dir}/libtaos.dylib + ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.1.dylib + ${csudo}ln -s ${lib_link_dir}/libtaos.1.dylib ${lib_link_dir}/libtaos.dylib fi - ${csudo} ldconfig + ${csudo}ldconfig } function install_header() { - ${csudo} rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taoserror.h || : - ${csudo} cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo} chmod 644 ${install_main_dir}/include/* - ${csudo} ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h - ${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h + ${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taoserror.h || : + ${csudo}cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo}chmod 644 ${install_main_dir}/include/* + ${csudo}ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h + ${csudo}ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h } function install_config() { if [ ! -f ${cfg_install_dir}/taos.cfg ]; then - ${csudo} mkdir -p ${cfg_install_dir} - [ -f ${script_dir}/cfg/taos.cfg ] && ${csudo} cp ${script_dir}/cfg/taos.cfg ${cfg_install_dir} - ${csudo} chmod 644 ${cfg_install_dir}/* + ${csudo}mkdir -p ${cfg_install_dir} + [ -f ${script_dir}/cfg/taos.cfg ] && ${csudo}cp ${script_dir}/cfg/taos.cfg ${cfg_install_dir} + ${csudo}chmod 644 ${cfg_install_dir}/* fi - ${csudo} cp -f ${script_dir}/cfg/taos.cfg ${install_main_dir}/cfg/taos.cfg.org - ${csudo} ln -s ${cfg_install_dir}/taos.cfg ${install_main_dir}/cfg + ${csudo}cp -f ${script_dir}/cfg/taos.cfg ${install_main_dir}/cfg/taos.cfg.org + ${csudo}ln -s ${cfg_install_dir}/taos.cfg ${install_main_dir}/cfg } function install_log() { - ${csudo} rm -rf ${log_dir} || : + ${csudo}rm -rf ${log_dir} || : if [ "$osType" != "Darwin" ]; then - ${csudo} mkdir -p ${log_dir} && ${csudo} chmod 777 ${log_dir} + ${csudo}mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir} else - mkdir -p ${log_dir} && ${csudo} chmod 777 ${log_dir} + mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir} fi - ${csudo} ln -s ${log_dir} ${install_main_dir}/log + ${csudo}ln -s ${log_dir} ${install_main_dir}/log } function install_connector() { - ${csudo} cp -rf ${script_dir}/connector/* ${install_main_dir}/connector + ${csudo}cp -rf ${script_dir}/connector/* ${install_main_dir}/connector } function install_examples() { if [ -d ${script_dir}/examples ]; then - ${csudo} cp -rf ${script_dir}/examples/* ${install_main_dir}/examples + ${csudo}cp -rf ${script_dir}/examples/* ${install_main_dir}/examples fi } diff --git a/packaging/tools/install_client_kh.sh b/packaging/tools/install_client_kh.sh index 3e7df18486a20b9ea75dba3d2644d46bee6b423b..0b8c0f5aeba96fff65907105ca571cf5955c6648 100755 --- a/packaging/tools/install_client_kh.sh +++ b/packaging/tools/install_client_kh.sh @@ -54,7 +54,7 @@ NC='\033[0m' csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi update_flag=0 @@ -62,42 +62,42 @@ update_flag=0 function kill_client() { pid=$(ps -ef | grep "khclient" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function install_main_path() { #create install main dir and all sub dir - ${csudo} rm -rf ${install_main_dir} || : - ${csudo} mkdir -p ${install_main_dir} - ${csudo} mkdir -p ${install_main_dir}/cfg - ${csudo} mkdir -p ${install_main_dir}/bin - ${csudo} mkdir -p ${install_main_dir}/connector - ${csudo} mkdir -p ${install_main_dir}/driver - ${csudo} mkdir -p ${install_main_dir}/examples - ${csudo} mkdir -p ${install_main_dir}/include + ${csudo}rm -rf ${install_main_dir} || : + ${csudo}mkdir -p ${install_main_dir} + ${csudo}mkdir -p ${install_main_dir}/cfg + ${csudo}mkdir -p ${install_main_dir}/bin + ${csudo}mkdir -p ${install_main_dir}/connector + ${csudo}mkdir -p ${install_main_dir}/driver + ${csudo}mkdir -p ${install_main_dir}/examples + ${csudo}mkdir -p ${install_main_dir}/include } function install_bin() { # Remove links - ${csudo} rm -f ${bin_link_dir}/khclient || : + ${csudo}rm -f ${bin_link_dir}/khclient || : if [ "$osType" != "Darwin" ]; then - ${csudo} rm -f ${bin_link_dir}/khdemo || : - ${csudo} rm -f ${bin_link_dir}/khdump || : + ${csudo}rm -f ${bin_link_dir}/khdemo || : + ${csudo}rm -f ${bin_link_dir}/khdump || : fi - ${csudo} rm -f ${bin_link_dir}/rmkh || : - ${csudo} rm -f ${bin_link_dir}/set_core || : + ${csudo}rm -f ${bin_link_dir}/rmkh || : + ${csudo}rm -f ${bin_link_dir}/set_core || : - ${csudo} cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo} chmod 0555 ${install_main_dir}/bin/* + ${csudo}cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo}chmod 0555 ${install_main_dir}/bin/* #Make link - [ -x ${install_main_dir}/bin/khclient ] && ${csudo} ln -s ${install_main_dir}/bin/khclient ${bin_link_dir}/khclient || : + [ -x ${install_main_dir}/bin/khclient ] && ${csudo}ln -s ${install_main_dir}/bin/khclient ${bin_link_dir}/khclient || : if [ "$osType" != "Darwin" ]; then - [ -x ${install_main_dir}/bin/khdemo ] && ${csudo} ln -s ${install_main_dir}/bin/khdemo ${bin_link_dir}/khdemo || : - [ -x ${install_main_dir}/bin/khdump ] && ${csudo} ln -s ${install_main_dir}/bin/khdump ${bin_link_dir}/khdump || : + [ -x ${install_main_dir}/bin/khdemo ] && ${csudo}ln -s ${install_main_dir}/bin/khdemo ${bin_link_dir}/khdemo || : + [ -x ${install_main_dir}/bin/khdump ] && ${csudo}ln -s ${install_main_dir}/bin/khdump ${bin_link_dir}/khdump || : fi - [ -x ${install_main_dir}/bin/remove_client_kh.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove_client_kh.sh ${bin_link_dir}/rmkh || : - [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo} ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : + [ -x ${install_main_dir}/bin/remove_client_kh.sh ] && ${csudo}ln -s ${install_main_dir}/bin/remove_client_kh.sh ${bin_link_dir}/rmkh || : + [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo}ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : } function clean_lib() { @@ -107,65 +107,65 @@ function clean_lib() { function install_lib() { # Remove links - ${csudo} rm -f ${lib_link_dir}/libtaos.* || : - ${csudo} rm -f ${lib64_link_dir}/libtaos.* || : - #${csudo} rm -rf ${v15_java_app_dir} || : + ${csudo}rm -f ${lib_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : + #${csudo}rm -rf ${v15_java_app_dir} || : - ${csudo} cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo} chmod 777 ${install_main_dir}/driver/* + ${csudo}cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo}chmod 777 ${install_main_dir}/driver/* if [ "$osType" != "Darwin" ]; then - ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 - ${csudo} ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so + ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 + ${csudo}ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so if [ -d "${lib64_link_dir}" ]; then - ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 || : - ${csudo} ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || : + ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 || : + ${csudo}ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || : fi else - ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.1.dylib - ${csudo} ln -s ${lib_link_dir}/libtaos.1.dylib ${lib_link_dir}/libtaos.dylib + ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.1.dylib + ${csudo}ln -s ${lib_link_dir}/libtaos.1.dylib ${lib_link_dir}/libtaos.dylib fi - ${csudo} ldconfig + ${csudo}ldconfig } function install_header() { - ${csudo} rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taoserror.h || : - ${csudo} cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo} chmod 644 ${install_main_dir}/include/* - ${csudo} ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h - ${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h + ${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taoserror.h || : + ${csudo}cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo}chmod 644 ${install_main_dir}/include/* + ${csudo}ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h + ${csudo}ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h } function install_config() { if [ ! -f ${cfg_install_dir}/kinghistorian.cfg ]; then - ${csudo} mkdir -p ${cfg_install_dir} - [ -f ${script_dir}/cfg/kinghistorian.cfg ] && ${csudo} cp ${script_dir}/cfg/kinghistorian.cfg ${cfg_install_dir} - ${csudo} chmod 644 ${cfg_install_dir}/* + ${csudo}mkdir -p ${cfg_install_dir} + [ -f ${script_dir}/cfg/kinghistorian.cfg ] && ${csudo}cp ${script_dir}/cfg/kinghistorian.cfg ${cfg_install_dir} + ${csudo}chmod 644 ${cfg_install_dir}/* fi - ${csudo} cp -f ${script_dir}/cfg/kinghistorian.cfg ${install_main_dir}/cfg/kinghistorian.cfg.org - ${csudo} ln -s ${cfg_install_dir}/kinghistorian.cfg ${install_main_dir}/cfg + ${csudo}cp -f ${script_dir}/cfg/kinghistorian.cfg ${install_main_dir}/cfg/kinghistorian.cfg.org + ${csudo}ln -s ${cfg_install_dir}/kinghistorian.cfg ${install_main_dir}/cfg } function install_log() { - ${csudo} rm -rf ${log_dir} || : + ${csudo}rm -rf ${log_dir} || : if [ "$osType" != "Darwin" ]; then - ${csudo} mkdir -p ${log_dir} && ${csudo} chmod 777 ${log_dir} + ${csudo}mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir} else - mkdir -p ${log_dir} && ${csudo} chmod 777 ${log_dir} + mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir} fi - ${csudo} ln -s ${log_dir} ${install_main_dir}/log + ${csudo}ln -s ${log_dir} ${install_main_dir}/log } function install_connector() { - ${csudo} cp -rf ${script_dir}/connector/* ${install_main_dir}/connector + ${csudo}cp -rf ${script_dir}/connector/* ${install_main_dir}/connector } function install_examples() { if [ -d ${script_dir}/examples ]; then - ${csudo} cp -rf ${script_dir}/examples/* ${install_main_dir}/examples + ${csudo}cp -rf ${script_dir}/examples/* ${install_main_dir}/examples fi } diff --git a/packaging/tools/install_client_power.sh b/packaging/tools/install_client_power.sh index 3c9abddb09646ea54f44e28664afea49822055f6..4e7ee96a6255bd74862a509206ef6aff69320916 100755 --- a/packaging/tools/install_client_power.sh +++ b/packaging/tools/install_client_power.sh @@ -57,7 +57,7 @@ NC='\033[0m' csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi update_flag=0 @@ -65,42 +65,42 @@ update_flag=0 function kill_client() { pid=$(ps -ef | grep "power" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function install_main_path() { #create install main dir and all sub dir - ${csudo} rm -rf ${install_main_dir} || : - ${csudo} mkdir -p ${install_main_dir} - ${csudo} mkdir -p ${install_main_dir}/cfg - ${csudo} mkdir -p ${install_main_dir}/bin - ${csudo} mkdir -p ${install_main_dir}/connector - ${csudo} mkdir -p ${install_main_dir}/driver - ${csudo} mkdir -p ${install_main_dir}/examples - ${csudo} mkdir -p ${install_main_dir}/include + ${csudo}rm -rf ${install_main_dir} || : + ${csudo}mkdir -p ${install_main_dir} + ${csudo}mkdir -p ${install_main_dir}/cfg + ${csudo}mkdir -p ${install_main_dir}/bin + ${csudo}mkdir -p ${install_main_dir}/connector + ${csudo}mkdir -p ${install_main_dir}/driver + ${csudo}mkdir -p ${install_main_dir}/examples + ${csudo}mkdir -p ${install_main_dir}/include } function install_bin() { # Remove links - ${csudo} rm -f ${bin_link_dir}/power || : + ${csudo}rm -f ${bin_link_dir}/power || : if [ "$osType" != "Darwin" ]; then - ${csudo} rm -f ${bin_link_dir}/powerdemo || : - ${csudo} rm -f ${bin_link_dir}/powerdump || : + ${csudo}rm -f ${bin_link_dir}/powerdemo || : + ${csudo}rm -f ${bin_link_dir}/powerdump || : fi - ${csudo} rm -f ${bin_link_dir}/rmpower || : - ${csudo} rm -f ${bin_link_dir}/set_core || : + ${csudo}rm -f ${bin_link_dir}/rmpower || : + ${csudo}rm -f ${bin_link_dir}/set_core || : - ${csudo} cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo} chmod 0555 ${install_main_dir}/bin/* + ${csudo}cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo}chmod 0555 ${install_main_dir}/bin/* #Make link - [ -x ${install_main_dir}/bin/power ] && ${csudo} ln -s ${install_main_dir}/bin/power ${bin_link_dir}/power || : + [ -x ${install_main_dir}/bin/power ] && ${csudo}ln -s ${install_main_dir}/bin/power ${bin_link_dir}/power || : if [ "$osType" != "Darwin" ]; then - [ -x ${install_main_dir}/bin/powerdemo ] && ${csudo} ln -s ${install_main_dir}/bin/powerdemo ${bin_link_dir}/powerdemo || : - [ -x ${install_main_dir}/bin/powerdump ] && ${csudo} ln -s ${install_main_dir}/bin/powerdump ${bin_link_dir}/powerdump || : + [ -x ${install_main_dir}/bin/powerdemo ] && ${csudo}ln -s ${install_main_dir}/bin/powerdemo ${bin_link_dir}/powerdemo || : + [ -x ${install_main_dir}/bin/powerdump ] && ${csudo}ln -s ${install_main_dir}/bin/powerdump ${bin_link_dir}/powerdump || : fi - [ -x ${install_main_dir}/bin/remove_client_power.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove_client_power.sh ${bin_link_dir}/rmpower || : - [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo} ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : + [ -x ${install_main_dir}/bin/remove_client_power.sh ] && ${csudo}ln -s ${install_main_dir}/bin/remove_client_power.sh ${bin_link_dir}/rmpower || : + [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo}ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : } function clean_lib() { @@ -110,83 +110,83 @@ function clean_lib() { function install_lib() { # Remove links - ${csudo} rm -f ${lib_link_dir}/libtaos.* || : - ${csudo} rm -f ${lib64_link_dir}/libtaos.* || : - #${csudo} rm -rf ${v15_java_app_dir} || : + ${csudo}rm -f ${lib_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : + #${csudo}rm -rf ${v15_java_app_dir} || : - ${csudo} cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo} chmod 777 ${install_main_dir}/driver/* + ${csudo}cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo}chmod 777 ${install_main_dir}/driver/* if [ "$osType" != "Darwin" ]; then - ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 - ${csudo} ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so + ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 + ${csudo}ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so if [ -d "${lib64_link_dir}" ]; then - ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 || : - ${csudo} ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || : + ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 || : + ${csudo}ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || : fi else - ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.1.dylib - ${csudo} ln -s ${lib_link_dir}/libtaos.1.dylib ${lib_link_dir}/libtaos.dylib + ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.1.dylib + ${csudo}ln -s ${lib_link_dir}/libtaos.1.dylib ${lib_link_dir}/libtaos.dylib fi - ${csudo} ldconfig + ${csudo}ldconfig } function install_header() { - ${csudo} rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h || : - ${csudo} cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo} chmod 644 ${install_main_dir}/include/* - ${csudo} ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h - ${csudo} ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h - ${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h + ${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h || : + ${csudo}cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo}chmod 644 ${install_main_dir}/include/* + ${csudo}ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h + ${csudo}ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h + ${csudo}ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h } function install_jemalloc() { jemalloc_dir=${script_dir}/jemalloc if [ -d ${jemalloc_dir} ]; then - ${csudo} /usr/bin/install -c -d /usr/local/bin + ${csudo}/usr/bin/install -c -d /usr/local/bin if [ -f ${jemalloc_dir}/bin/jemalloc-config ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc-config /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc-config /usr/local/bin fi if [ -f ${jemalloc_dir}/bin/jemalloc.sh ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc.sh /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc.sh /usr/local/bin fi if [ -f ${jemalloc_dir}/bin/jeprof ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jeprof /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jeprof /usr/local/bin fi if [ -f ${jemalloc_dir}/include/jemalloc/jemalloc.h ]; then - ${csudo} /usr/bin/install -c -d /usr/local/include/jemalloc - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/include/jemalloc/jemalloc.h /usr/local/include/jemalloc + ${csudo}/usr/bin/install -c -d /usr/local/include/jemalloc + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/include/jemalloc/jemalloc.h /usr/local/include/jemalloc fi if [ -f ${jemalloc_dir}/lib/libjemalloc.so.2 ]; then - ${csudo} /usr/bin/install -c -d /usr/local/lib - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.so.2 /usr/local/lib - ${csudo} ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so - ${csudo} /usr/bin/install -c -d /usr/local/lib + ${csudo}/usr/bin/install -c -d /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.so.2 /usr/local/lib + ${csudo}ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so + ${csudo}/usr/bin/install -c -d /usr/local/lib if [ -f ${jemalloc_dir}/lib/libjemalloc.a ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.a /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.a /usr/local/lib fi if [ -f ${jemalloc_dir}/lib/libjemalloc_pic.a ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc_pic.a /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc_pic.a /usr/local/lib fi if [ -f ${jemalloc_dir}/lib/libjemalloc_pic.a ]; then - ${csudo} /usr/bin/install -c -d /usr/local/lib/pkgconfig - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/lib/pkgconfig/jemalloc.pc /usr/local/lib/pkgconfig + ${csudo}/usr/bin/install -c -d /usr/local/lib/pkgconfig + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/lib/pkgconfig/jemalloc.pc /usr/local/lib/pkgconfig fi fi if [ -f ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html ]; then - ${csudo} /usr/bin/install -c -d /usr/local/share/doc/jemalloc - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html /usr/local/share/doc/jemalloc + ${csudo}/usr/bin/install -c -d /usr/local/share/doc/jemalloc + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html /usr/local/share/doc/jemalloc fi if [ -f ${jemalloc_dir}/share/man/man3/jemalloc.3 ]; then - ${csudo} /usr/bin/install -c -d /usr/local/share/man/man3 - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/share/man/man3/jemalloc.3 /usr/local/share/man/man3 + ${csudo}/usr/bin/install -c -d /usr/local/share/man/man3 + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/share/man/man3/jemalloc.3 /usr/local/share/man/man3 fi if [ -d /etc/ld.so.conf.d ]; then - echo "/usr/local/lib" | ${csudo} tee /etc/ld.so.conf.d/jemalloc.conf > /dev/null || echo -e "failed to write /etc/ld.so.conf.d/jemalloc.conf" - ${csudo} ldconfig + echo "/usr/local/lib" | ${csudo}tee /etc/ld.so.conf.d/jemalloc.conf > /dev/null || echo -e "failed to write /etc/ld.so.conf.d/jemalloc.conf" + ${csudo}ldconfig else echo "/etc/ld.so.conf.d not found!" fi @@ -195,34 +195,34 @@ function install_jemalloc() { function install_config() { if [ ! -f ${cfg_install_dir}/power.cfg ]; then - ${csudo} mkdir -p ${cfg_install_dir} - [ -f ${script_dir}/cfg/power.cfg ] && ${csudo} cp ${script_dir}/cfg/power.cfg ${cfg_install_dir} - ${csudo} chmod 644 ${cfg_install_dir}/* + ${csudo}mkdir -p ${cfg_install_dir} + [ -f ${script_dir}/cfg/power.cfg ] && ${csudo}cp ${script_dir}/cfg/power.cfg ${cfg_install_dir} + ${csudo}chmod 644 ${cfg_install_dir}/* fi - ${csudo} cp -f ${script_dir}/cfg/power.cfg ${install_main_dir}/cfg/power.cfg.org - ${csudo} ln -s ${cfg_install_dir}/power.cfg ${install_main_dir}/cfg + ${csudo}cp -f ${script_dir}/cfg/power.cfg ${install_main_dir}/cfg/power.cfg.org + ${csudo}ln -s ${cfg_install_dir}/power.cfg ${install_main_dir}/cfg } function install_log() { - ${csudo} rm -rf ${log_dir} || : + ${csudo}rm -rf ${log_dir} || : if [ "$osType" != "Darwin" ]; then - ${csudo} mkdir -p ${log_dir} && ${csudo} chmod 777 ${log_dir} + ${csudo}mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir} else - mkdir -p ${log_dir} && ${csudo} chmod 777 ${log_dir} + mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir} fi - ${csudo} ln -s ${log_dir} ${install_main_dir}/log + ${csudo}ln -s ${log_dir} ${install_main_dir}/log } function install_connector() { - ${csudo} cp -rf ${script_dir}/connector/* ${install_main_dir}/connector + ${csudo}cp -rf ${script_dir}/connector/* ${install_main_dir}/connector } function install_examples() { if [ -d ${script_dir}/examples ]; then - ${csudo} cp -rf ${script_dir}/examples/* ${install_main_dir}/examples + ${csudo}cp -rf ${script_dir}/examples/* ${install_main_dir}/examples fi } diff --git a/packaging/tools/install_client_pro.sh b/packaging/tools/install_client_pro.sh index e34dc6d4ac1d1ef1715ff903b38b1a8735001985..7551484e56c8d5fc59539d26f52ac7d318106fa5 100755 --- a/packaging/tools/install_client_pro.sh +++ b/packaging/tools/install_client_pro.sh @@ -54,7 +54,7 @@ NC='\033[0m' csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi update_flag=0 @@ -62,42 +62,42 @@ update_flag=0 function kill_client() { pid=$(ps -ef | grep "prodbc" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function install_main_path() { #create install main dir and all sub dir - ${csudo} rm -rf ${install_main_dir} || : - ${csudo} mkdir -p ${install_main_dir} - ${csudo} mkdir -p ${install_main_dir}/cfg - ${csudo} mkdir -p ${install_main_dir}/bin - ${csudo} mkdir -p ${install_main_dir}/connector - ${csudo} mkdir -p ${install_main_dir}/driver - ${csudo} mkdir -p ${install_main_dir}/examples - ${csudo} mkdir -p ${install_main_dir}/include + ${csudo}rm -rf ${install_main_dir} || : + ${csudo}mkdir -p ${install_main_dir} + ${csudo}mkdir -p ${install_main_dir}/cfg + ${csudo}mkdir -p ${install_main_dir}/bin + ${csudo}mkdir -p ${install_main_dir}/connector + ${csudo}mkdir -p ${install_main_dir}/driver + ${csudo}mkdir -p ${install_main_dir}/examples + ${csudo}mkdir -p ${install_main_dir}/include } function install_bin() { # Remove links - ${csudo} rm -f ${bin_link_dir}/prodbc || : + ${csudo}rm -f ${bin_link_dir}/prodbc || : if [ "$osType" != "Darwin" ]; then - ${csudo} rm -f ${bin_link_dir}/prodemo || : - ${csudo} rm -f ${bin_link_dir}/prodump || : + ${csudo}rm -f ${bin_link_dir}/prodemo || : + ${csudo}rm -f ${bin_link_dir}/prodump || : fi - ${csudo} rm -f ${bin_link_dir}/rmprodb || : - ${csudo} rm -f ${bin_link_dir}/set_core || : + ${csudo}rm -f ${bin_link_dir}/rmprodb || : + ${csudo}rm -f ${bin_link_dir}/set_core || : - ${csudo} cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo} chmod 0555 ${install_main_dir}/bin/* + ${csudo}cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo}chmod 0555 ${install_main_dir}/bin/* #Make link - [ -x ${install_main_dir}/bin/prodbc ] && ${csudo} ln -s ${install_main_dir}/bin/prodbc ${bin_link_dir}/prodbc || : + [ -x ${install_main_dir}/bin/prodbc ] && ${csudo}ln -s ${install_main_dir}/bin/prodbc ${bin_link_dir}/prodbc || : if [ "$osType" != "Darwin" ]; then - [ -x ${install_main_dir}/bin/prodemo ] && ${csudo} ln -s ${install_main_dir}/bin/prodemo ${bin_link_dir}/prodemo || : - [ -x ${install_main_dir}/bin/prodump ] && ${csudo} ln -s ${install_main_dir}/bin/prodump ${bin_link_dir}/prodump || : + [ -x ${install_main_dir}/bin/prodemo ] && ${csudo}ln -s ${install_main_dir}/bin/prodemo ${bin_link_dir}/prodemo || : + [ -x ${install_main_dir}/bin/prodump ] && ${csudo}ln -s ${install_main_dir}/bin/prodump ${bin_link_dir}/prodump || : fi - [ -x ${install_main_dir}/bin/remove_client_prodb.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove_client_prodb.sh ${bin_link_dir}/rmprodb || : - [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo} ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : + [ -x ${install_main_dir}/bin/remove_client_prodb.sh ] && ${csudo}ln -s ${install_main_dir}/bin/remove_client_prodb.sh ${bin_link_dir}/rmprodb || : + [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo}ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : } function clean_lib() { @@ -107,65 +107,65 @@ function clean_lib() { function install_lib() { # Remove links - ${csudo} rm -f ${lib_link_dir}/libtaos.* || : - ${csudo} rm -f ${lib64_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : - ${csudo} cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo} chmod 777 ${install_main_dir}/driver/* + ${csudo}cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo}chmod 777 ${install_main_dir}/driver/* if [ "$osType" != "Darwin" ]; then - ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 - ${csudo} ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so + ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 + ${csudo}ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so if [ -d "${lib64_link_dir}" ]; then - ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 || : - ${csudo} ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || : + ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 || : + ${csudo}ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || : fi else - ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.1.dylib - ${csudo} ln -s ${lib_link_dir}/libtaos.1.dylib ${lib_link_dir}/libtaos.dylib + ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.1.dylib + ${csudo}ln -s ${lib_link_dir}/libtaos.1.dylib ${lib_link_dir}/libtaos.dylib fi - ${csudo} ldconfig + ${csudo}ldconfig } function install_header() { - ${csudo} rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h || : - ${csudo} cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo} chmod 644 ${install_main_dir}/include/* - ${csudo} ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h - ${csudo} ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h - ${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h + ${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h || : + ${csudo}cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo}chmod 644 ${install_main_dir}/include/* + ${csudo}ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h + ${csudo}ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h + ${csudo}ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h } function install_config() { if [ ! -f ${cfg_install_dir}/prodb.cfg ]; then - ${csudo} mkdir -p ${cfg_install_dir} - [ -f ${script_dir}/cfg/prodb.cfg ] && ${csudo} cp ${script_dir}/cfg/prodb.cfg ${cfg_install_dir} - ${csudo} chmod 644 ${cfg_install_dir}/* + ${csudo}mkdir -p ${cfg_install_dir} + [ -f ${script_dir}/cfg/prodb.cfg ] && ${csudo}cp ${script_dir}/cfg/prodb.cfg ${cfg_install_dir} + ${csudo}chmod 644 ${cfg_install_dir}/* fi - ${csudo} cp -f ${script_dir}/cfg/prodb.cfg ${install_main_dir}/cfg/prodb.cfg.org - ${csudo} ln -s ${cfg_install_dir}/prodb.cfg ${install_main_dir}/cfg + ${csudo}cp -f ${script_dir}/cfg/prodb.cfg ${install_main_dir}/cfg/prodb.cfg.org + ${csudo}ln -s ${cfg_install_dir}/prodb.cfg ${install_main_dir}/cfg } function install_log() { - ${csudo} rm -rf ${log_dir} || : + ${csudo}rm -rf ${log_dir} || : if [ "$osType" != "Darwin" ]; then - ${csudo} mkdir -p ${log_dir} && ${csudo} chmod 777 ${log_dir} + ${csudo}mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir} else - mkdir -p ${log_dir} && ${csudo} chmod 777 ${log_dir} + mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir} fi - ${csudo} ln -s ${log_dir} ${install_main_dir}/log + ${csudo}ln -s ${log_dir} ${install_main_dir}/log } function install_connector() { - ${csudo} cp -rf ${script_dir}/connector/* ${install_main_dir}/connector + ${csudo}cp -rf ${script_dir}/connector/* ${install_main_dir}/connector } function install_examples() { if [ -d ${script_dir}/examples ]; then - ${csudo} cp -rf ${script_dir}/examples/* ${install_main_dir}/examples + ${csudo}cp -rf ${script_dir}/examples/* ${install_main_dir}/examples fi } diff --git a/packaging/tools/install_client_tq.sh b/packaging/tools/install_client_tq.sh index b7f10324dcd1c62fee20fe11399fbb61d8a38577..04479cfdbe234fe323a43a6a521992838069ecd9 100755 --- a/packaging/tools/install_client_tq.sh +++ b/packaging/tools/install_client_tq.sh @@ -57,7 +57,7 @@ NC='\033[0m' csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi update_flag=0 @@ -65,42 +65,42 @@ update_flag=0 function kill_client() { pid=$(ps -ef | grep "tq" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function install_main_path() { #create install main dir and all sub dir - ${csudo} rm -rf ${install_main_dir} || : - ${csudo} mkdir -p ${install_main_dir} - ${csudo} mkdir -p ${install_main_dir}/cfg - ${csudo} mkdir -p ${install_main_dir}/bin - ${csudo} mkdir -p ${install_main_dir}/connector - ${csudo} mkdir -p ${install_main_dir}/driver - ${csudo} mkdir -p ${install_main_dir}/examples - ${csudo} mkdir -p ${install_main_dir}/include + ${csudo}rm -rf ${install_main_dir} || : + ${csudo}mkdir -p ${install_main_dir} + ${csudo}mkdir -p ${install_main_dir}/cfg + ${csudo}mkdir -p ${install_main_dir}/bin + ${csudo}mkdir -p ${install_main_dir}/connector + ${csudo}mkdir -p ${install_main_dir}/driver + ${csudo}mkdir -p ${install_main_dir}/examples + ${csudo}mkdir -p ${install_main_dir}/include } function install_bin() { # Remove links - ${csudo} rm -f ${bin_link_dir}/tq || : + ${csudo}rm -f ${bin_link_dir}/tq || : if [ "$osType" != "Darwin" ]; then - ${csudo} rm -f ${bin_link_dir}/tqdemo || : - ${csudo} rm -f ${bin_link_dir}/tqdump || : + ${csudo}rm -f ${bin_link_dir}/tqdemo || : + ${csudo}rm -f ${bin_link_dir}/tqdump || : fi - ${csudo} rm -f ${bin_link_dir}/rmtq || : - ${csudo} rm -f ${bin_link_dir}/set_core || : + ${csudo}rm -f ${bin_link_dir}/rmtq || : + ${csudo}rm -f ${bin_link_dir}/set_core || : - ${csudo} cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo} chmod 0555 ${install_main_dir}/bin/* + ${csudo}cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo}chmod 0555 ${install_main_dir}/bin/* #Make link - [ -x ${install_main_dir}/bin/tq ] && ${csudo} ln -s ${install_main_dir}/bin/tq ${bin_link_dir}/tq || : + [ -x ${install_main_dir}/bin/tq ] && ${csudo}ln -s ${install_main_dir}/bin/tq ${bin_link_dir}/tq || : if [ "$osType" != "Darwin" ]; then - [ -x ${install_main_dir}/bin/tqdemo ] && ${csudo} ln -s ${install_main_dir}/bin/tqdemo ${bin_link_dir}/tqdemo || : - [ -x ${install_main_dir}/bin/tqdump ] && ${csudo} ln -s ${install_main_dir}/bin/tqdump ${bin_link_dir}/tqdump || : + [ -x ${install_main_dir}/bin/tqdemo ] && ${csudo}ln -s ${install_main_dir}/bin/tqdemo ${bin_link_dir}/tqdemo || : + [ -x ${install_main_dir}/bin/tqdump ] && ${csudo}ln -s ${install_main_dir}/bin/tqdump ${bin_link_dir}/tqdump || : fi - [ -x ${install_main_dir}/bin/remove_client_tq.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove_client_tq.sh ${bin_link_dir}/rmtq || : - [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo} ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : + [ -x ${install_main_dir}/bin/remove_client_tq.sh ] && ${csudo}ln -s ${install_main_dir}/bin/remove_client_tq.sh ${bin_link_dir}/rmtq || : + [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo}ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : } function clean_lib() { @@ -110,66 +110,66 @@ function clean_lib() { function install_lib() { # Remove links - ${csudo} rm -f ${lib_link_dir}/libtaos.* || : - ${csudo} rm -f ${lib64_link_dir}/libtaos.* || : - #${csudo} rm -rf ${v15_java_app_dir} || : + ${csudo}rm -f ${lib_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : + #${csudo}rm -rf ${v15_java_app_dir} || : - ${csudo} cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo} chmod 777 ${install_main_dir}/driver/* + ${csudo}cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo}chmod 777 ${install_main_dir}/driver/* if [ "$osType" != "Darwin" ]; then - ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 - ${csudo} ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so + ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 + ${csudo}ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so if [ -d "${lib64_link_dir}" ]; then - ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 || : - ${csudo} ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || : + ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 || : + ${csudo}ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || : fi else - ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.1.dylib - ${csudo} ln -s ${lib_link_dir}/libtaos.1.dylib ${lib_link_dir}/libtaos.dylib + ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.1.dylib + ${csudo}ln -s ${lib_link_dir}/libtaos.1.dylib ${lib_link_dir}/libtaos.dylib fi - ${csudo} ldconfig + ${csudo}ldconfig } function install_header() { - ${csudo} rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h || : - ${csudo} cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo} chmod 644 ${install_main_dir}/include/* - ${csudo} ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h - ${csudo} ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h - ${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h + ${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h || : + ${csudo}cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo}chmod 644 ${install_main_dir}/include/* + ${csudo}ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h + ${csudo}ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h + ${csudo}ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h } function install_config() { if [ ! -f ${cfg_install_dir}/tq.cfg ]; then - ${csudo} mkdir -p ${cfg_install_dir} - [ -f ${script_dir}/cfg/tq.cfg ] && ${csudo} cp ${script_dir}/cfg/tq.cfg ${cfg_install_dir} - ${csudo} chmod 644 ${cfg_install_dir}/* + ${csudo}mkdir -p ${cfg_install_dir} + [ -f ${script_dir}/cfg/tq.cfg ] && ${csudo}cp ${script_dir}/cfg/tq.cfg ${cfg_install_dir} + ${csudo}chmod 644 ${cfg_install_dir}/* fi - ${csudo} cp -f ${script_dir}/cfg/tq.cfg ${install_main_dir}/cfg/tq.cfg.org - ${csudo} ln -s ${cfg_install_dir}/tq.cfg ${install_main_dir}/cfg + ${csudo}cp -f ${script_dir}/cfg/tq.cfg ${install_main_dir}/cfg/tq.cfg.org + ${csudo}ln -s ${cfg_install_dir}/tq.cfg ${install_main_dir}/cfg } function install_log() { - ${csudo} rm -rf ${log_dir} || : + ${csudo}rm -rf ${log_dir} || : if [ "$osType" != "Darwin" ]; then - ${csudo} mkdir -p ${log_dir} && ${csudo} chmod 777 ${log_dir} + ${csudo}mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir} else - mkdir -p ${log_dir} && ${csudo} chmod 777 ${log_dir} + mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir} fi - ${csudo} ln -s ${log_dir} ${install_main_dir}/log + ${csudo}ln -s ${log_dir} ${install_main_dir}/log } function install_connector() { - ${csudo} cp -rf ${script_dir}/connector/* ${install_main_dir}/connector + ${csudo}cp -rf ${script_dir}/connector/* ${install_main_dir}/connector } function install_examples() { if [ -d ${script_dir}/examples ]; then - ${csudo} cp -rf ${script_dir}/examples/* ${install_main_dir}/examples + ${csudo}cp -rf ${script_dir}/examples/* ${install_main_dir}/examples fi } diff --git a/packaging/tools/install_jh.sh b/packaging/tools/install_jh.sh index ecc166fba10ef4c3f8e0bacc04ff27ebf717e409..667766154e92004b3eea695b08f0fc43872cbd2e 100755 --- a/packaging/tools/install_jh.sh +++ b/packaging/tools/install_jh.sh @@ -46,7 +46,7 @@ NC='\033[0m' csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi update_flag=0 @@ -144,129 +144,129 @@ done function kill_process() { pid=$(ps -ef | grep "$1" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function install_main_path() { #create install main dir and all sub dir - ${csudo} rm -rf ${install_main_dir} || : - ${csudo} mkdir -p ${install_main_dir} - ${csudo} mkdir -p ${install_main_dir}/cfg - ${csudo} mkdir -p ${install_main_dir}/bin -# ${csudo} mkdir -p ${install_main_dir}/connector - ${csudo} mkdir -p ${install_main_dir}/driver -# ${csudo} mkdir -p ${install_main_dir}/examples - ${csudo} mkdir -p ${install_main_dir}/include - ${csudo} mkdir -p ${install_main_dir}/init.d + ${csudo}rm -rf ${install_main_dir} || : + ${csudo}mkdir -p ${install_main_dir} + ${csudo}mkdir -p ${install_main_dir}/cfg + ${csudo}mkdir -p ${install_main_dir}/bin +# ${csudo}mkdir -p ${install_main_dir}/connector + ${csudo}mkdir -p ${install_main_dir}/driver +# ${csudo}mkdir -p ${install_main_dir}/examples + ${csudo}mkdir -p ${install_main_dir}/include + ${csudo}mkdir -p ${install_main_dir}/init.d if [ "$verMode" == "cluster" ]; then - ${csudo} mkdir -p ${nginx_dir} + ${csudo}mkdir -p ${nginx_dir} fi } function install_bin() { # Remove links - ${csudo} rm -f ${bin_link_dir}/jh_taos || : - ${csudo} rm -f ${bin_link_dir}/jh_taosd || : - ${csudo} rm -f ${bin_link_dir}/jhdemo || : - ${csudo} rm -f ${bin_link_dir}/rmjh || : - ${csudo} rm -f ${bin_link_dir}/tarbitrator || : - ${csudo} rm -f ${bin_link_dir}/set_core || : - ${csudo} rm -f ${bin_link_dir}/run_taosd.sh || : + ${csudo}rm -f ${bin_link_dir}/jh_taos || : + ${csudo}rm -f ${bin_link_dir}/jh_taosd || : + ${csudo}rm -f ${bin_link_dir}/jhdemo || : + ${csudo}rm -f ${bin_link_dir}/rmjh || : + ${csudo}rm -f ${bin_link_dir}/tarbitrator || : + ${csudo}rm -f ${bin_link_dir}/set_core || : + ${csudo}rm -f ${bin_link_dir}/run_taosd.sh || : - ${csudo} cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo} chmod 0555 ${install_main_dir}/bin/* + ${csudo}cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo}chmod 0555 ${install_main_dir}/bin/* #Make link - [ -x ${install_main_dir}/bin/jh_taos ] && ${csudo} ln -s ${install_main_dir}/bin/jh_taos ${bin_link_dir}/jh_taos || : - [ -x ${install_main_dir}/bin/jh_taosd ] && ${csudo} ln -s ${install_main_dir}/bin/jh_taosd ${bin_link_dir}/jh_taosd || : - [ -x ${install_main_dir}/bin/jhdemo ] && ${csudo} ln -s ${install_main_dir}/bin/jhdemo ${bin_link_dir}/jhdemo || : - [ -x ${install_main_dir}/bin/remove_jh.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove_jh.sh ${bin_link_dir}/rmjh || : - [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo} ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : - [ -x ${install_main_dir}/bin/run_taosd.sh ] && ${csudo} ln -s ${install_main_dir}/bin/run_taosd.sh ${bin_link_dir}/run_taosd.sh || : - [ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo} ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || : + [ -x ${install_main_dir}/bin/jh_taos ] && ${csudo}ln -s ${install_main_dir}/bin/jh_taos ${bin_link_dir}/jh_taos || : + [ -x ${install_main_dir}/bin/jh_taosd ] && ${csudo}ln -s ${install_main_dir}/bin/jh_taosd ${bin_link_dir}/jh_taosd || : + [ -x ${install_main_dir}/bin/jhdemo ] && ${csudo}ln -s ${install_main_dir}/bin/jhdemo ${bin_link_dir}/jhdemo || : + [ -x ${install_main_dir}/bin/remove_jh.sh ] && ${csudo}ln -s ${install_main_dir}/bin/remove_jh.sh ${bin_link_dir}/rmjh || : + [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo}ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : + [ -x ${install_main_dir}/bin/run_taosd.sh ] && ${csudo}ln -s ${install_main_dir}/bin/run_taosd.sh ${bin_link_dir}/run_taosd.sh || : + [ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo}ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || : if [ "$verMode" == "cluster" ]; then - ${csudo} cp -r ${script_dir}/nginxd/* ${nginx_dir} && ${csudo} chmod 0555 ${nginx_dir}/* - ${csudo} mkdir -p ${nginx_dir}/logs - ${csudo} chmod 777 ${nginx_dir}/sbin/nginx + ${csudo}cp -r ${script_dir}/nginxd/* ${nginx_dir} && ${csudo}chmod 0555 ${nginx_dir}/* + ${csudo}mkdir -p ${nginx_dir}/logs + ${csudo}chmod 777 ${nginx_dir}/sbin/nginx fi } function install_lib() { # Remove links - ${csudo} rm -f ${lib_link_dir}/libtaos.* || : - ${csudo} rm -f ${lib64_link_dir}/libtaos.* || : - ${csudo} cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo} chmod 777 ${install_main_dir}/driver/* + ${csudo}rm -f ${lib_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : + ${csudo}cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo}chmod 777 ${install_main_dir}/driver/* - ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 - ${csudo} ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so + ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 + ${csudo}ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so if [[ -d ${lib64_link_dir} && ! -e ${lib64_link_dir}/libtaos.so ]]; then - ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 || : - ${csudo} ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || : + ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 || : + ${csudo}ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || : fi if [ "$osType" != "Darwin" ]; then - ${csudo} ldconfig + ${csudo}ldconfig else - ${csudo} update_dyld_shared_cache + ${csudo}update_dyld_shared_cache fi } function install_header() { - ${csudo} rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taoserror.h || : - ${csudo} cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo} chmod 644 ${install_main_dir}/include/* - ${csudo} ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h - ${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h + ${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taoserror.h || : + ${csudo}cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo}chmod 644 ${install_main_dir}/include/* + ${csudo}ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h + ${csudo}ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h } function install_jemalloc() { jemalloc_dir=${script_dir}/jemalloc if [ -d ${jemalloc_dir} ]; then - ${csudo} /usr/bin/install -c -d /usr/local/bin + ${csudo}/usr/bin/install -c -d /usr/local/bin if [ -f ${jemalloc_dir}/bin/jemalloc-config ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc-config /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc-config /usr/local/bin fi if [ -f ${jemalloc_dir}/bin/jemalloc.sh ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc.sh /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc.sh /usr/local/bin fi if [ -f ${jemalloc_dir}/bin/jeprof ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jeprof /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jeprof /usr/local/bin fi if [ -f ${jemalloc_dir}/include/jemalloc/jemalloc.h ]; then - ${csudo} /usr/bin/install -c -d /usr/local/include/jemalloc - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/include/jemalloc/jemalloc.h /usr/local/include/jemalloc + ${csudo}/usr/bin/install -c -d /usr/local/include/jemalloc + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/include/jemalloc/jemalloc.h /usr/local/include/jemalloc fi if [ -f ${jemalloc_dir}/lib/libjemalloc.so.2 ]; then - ${csudo} /usr/bin/install -c -d /usr/local/lib - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.so.2 /usr/local/lib - ${csudo} ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so - ${csudo} /usr/bin/install -c -d /usr/local/lib + ${csudo}/usr/bin/install -c -d /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.so.2 /usr/local/lib + ${csudo}ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so + ${csudo}/usr/bin/install -c -d /usr/local/lib if [ -f ${jemalloc_dir}/lib/libjemalloc.a ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.a /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.a /usr/local/lib fi if [ -f ${jemalloc_dir}/lib/libjemalloc_pic.a ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc_pic.a /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc_pic.a /usr/local/lib fi if [ -f ${jemalloc_dir}/lib/libjemalloc_pic.a ]; then - ${csudo} /usr/bin/install -c -d /usr/local/lib/pkgconfig - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/lib/pkgconfig/jemalloc.pc /usr/local/lib/pkgconfig + ${csudo}/usr/bin/install -c -d /usr/local/lib/pkgconfig + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/lib/pkgconfig/jemalloc.pc /usr/local/lib/pkgconfig fi fi if [ -f ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html ]; then - ${csudo} /usr/bin/install -c -d /usr/local/share/doc/jemalloc - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html /usr/local/share/doc/jemalloc + ${csudo}/usr/bin/install -c -d /usr/local/share/doc/jemalloc + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html /usr/local/share/doc/jemalloc fi if [ -f ${jemalloc_dir}/share/man/man3/jemalloc.3 ]; then - ${csudo} /usr/bin/install -c -d /usr/local/share/man/man3 - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/share/man/man3/jemalloc.3 /usr/local/share/man/man3 + ${csudo}/usr/bin/install -c -d /usr/local/share/man/man3 + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/share/man/man3/jemalloc.3 /usr/local/share/man/man3 fi if [ -d /etc/ld.so.conf.d ]; then - echo "/usr/local/lib" | ${csudo} tee /etc/ld.so.conf.d/jemalloc.conf > /dev/null || echo -e "failed to write /etc/ld.so.conf.d/jemalloc.conf" - ${csudo} ldconfig + echo "/usr/local/lib" | ${csudo}tee /etc/ld.so.conf.d/jemalloc.conf > /dev/null || echo -e "failed to write /etc/ld.so.conf.d/jemalloc.conf" + ${csudo}ldconfig else echo "/etc/ld.so.conf.d not found!" fi @@ -286,7 +286,7 @@ function add_newHostname_to_hosts() { return fi done - ${csudo} echo "127.0.0.1 $1" >> /etc/hosts ||: + ${csudo}echo "127.0.0.1 $1" >> /etc/hosts ||: } function set_hostname() { @@ -300,7 +300,7 @@ function set_hostname() { fi done - ${csudo} hostname $newHostname ||: + ${csudo}hostname $newHostname ||: retval=`echo $?` if [[ $retval != 0 ]]; then echo @@ -310,15 +310,15 @@ function set_hostname() { #ubuntu/centos /etc/hostname if [[ -e /etc/hostname ]]; then - ${csudo} echo $newHostname > /etc/hostname ||: + ${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 ||: + ${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}/taos.cfg + ${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$newHostname/" ${cfg_install_dir}/taos.cfg serverFqdn=$newHostname if [[ -e /etc/hosts ]]; then @@ -353,7 +353,7 @@ 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}/taos.cfg + ${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${cfg_install_dir}/taos.cfg serverFqdn=$localFqdn echo return @@ -375,7 +375,7 @@ function set_ipAsFqdn() { 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}/taos.cfg + ${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${cfg_install_dir}/taos.cfg serverFqdn=$localFqdn break fi @@ -423,13 +423,13 @@ function local_fqdn_check() { function install_config() { if [ ! -f ${cfg_install_dir}/taos.cfg ]; then - ${csudo} mkdir -p ${cfg_install_dir} - [ -f ${script_dir}/cfg/taos.cfg ] && ${csudo} cp ${script_dir}/cfg/taos.cfg ${cfg_install_dir} - ${csudo} chmod 644 ${cfg_install_dir}/* + ${csudo}mkdir -p ${cfg_install_dir} + [ -f ${script_dir}/cfg/taos.cfg ] && ${csudo}cp ${script_dir}/cfg/taos.cfg ${cfg_install_dir} + ${csudo}chmod 644 ${cfg_install_dir}/* fi - ${csudo} cp -f ${script_dir}/cfg/taos.cfg ${install_main_dir}/cfg/taos.cfg.org - ${csudo} ln -s ${cfg_install_dir}/taos.cfg ${install_main_dir}/cfg + ${csudo}cp -f ${script_dir}/cfg/taos.cfg ${install_main_dir}/cfg/taos.cfg.org + ${csudo}ln -s ${cfg_install_dir}/taos.cfg ${install_main_dir}/cfg [ ! -z $1 ] && return 0 || : # only install client @@ -459,7 +459,7 @@ function install_config() { # check the format of the firstEp #if [[ $firstEp == $FQDN_PATTERN ]]; then # Write the first FQDN to configuration file - ${csudo} sed -i -r "s/#*\s*(firstEp\s*).*/\1$firstEp/" ${cfg_install_dir}/taos.cfg + ${csudo}sed -i -r "s/#*\s*(firstEp\s*).*/\1$firstEp/" ${cfg_install_dir}/taos.cfg break #else # read -p "Please enter the correct FQDN:port: " firstEp @@ -472,66 +472,66 @@ function install_config() { function install_log() { - ${csudo} rm -rf ${log_dir} || : - ${csudo} mkdir -p ${log_dir} && ${csudo} chmod 777 ${log_dir} + ${csudo}rm -rf ${log_dir} || : + ${csudo}mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir} - ${csudo} ln -s ${log_dir} ${install_main_dir}/log + ${csudo}ln -s ${log_dir} ${install_main_dir}/log } function install_data() { - ${csudo} mkdir -p ${data_dir} + ${csudo}mkdir -p ${data_dir} - ${csudo} ln -s ${data_dir} ${install_main_dir}/data + ${csudo}ln -s ${data_dir} ${install_main_dir}/data } function install_connector() { - ${csudo} cp -rf ${script_dir}/connector/* ${install_main_dir}/connector + ${csudo}cp -rf ${script_dir}/connector/* ${install_main_dir}/connector } function install_examples() { if [ -d ${script_dir}/examples ]; then - ${csudo} cp -rf ${script_dir}/examples/* ${install_main_dir}/examples + ${csudo}cp -rf ${script_dir}/examples/* ${install_main_dir}/examples fi } function clean_service_on_sysvinit() { if pidof jh_taosd &> /dev/null; then - ${csudo} service jh_taosd stop || : + ${csudo}service jh_taosd stop || : fi if pidof tarbitrator &> /dev/null; then - ${csudo} service tarbitratord stop || : + ${csudo}service tarbitratord stop || : fi if ((${initd_mod}==1)); then if [ -e ${service_config_dir}/jh_taosd ]; then - ${csudo} chkconfig --del jh_taosd || : + ${csudo}chkconfig --del jh_taosd || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} chkconfig --del tarbitratord || : + ${csudo}chkconfig --del tarbitratord || : fi elif ((${initd_mod}==2)); then if [ -e ${service_config_dir}/jh_taosd ]; then - ${csudo} insserv -r jh_taosd || : + ${csudo}insserv -r jh_taosd || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} insserv -r tarbitratord || : + ${csudo}insserv -r tarbitratord || : fi elif ((${initd_mod}==3)); then if [ -e ${service_config_dir}/jh_taosd ]; then - ${csudo} update-rc.d -f jh_taosd remove || : + ${csudo}update-rc.d -f jh_taosd remove || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} update-rc.d -f tarbitratord remove || : + ${csudo}update-rc.d -f tarbitratord remove || : fi fi - ${csudo} rm -f ${service_config_dir}/jh_taosd || : - ${csudo} rm -f ${service_config_dir}/tarbitratord || : + ${csudo}rm -f ${service_config_dir}/jh_taosd || : + ${csudo}rm -f ${service_config_dir}/tarbitratord || : if $(which init &> /dev/null); then - ${csudo} init q || : + ${csudo}init q || : fi } @@ -542,30 +542,30 @@ function install_service_on_sysvinit() { # Install jh_taosd service if ((${os_type}==1)); then - ${csudo} cp -f ${script_dir}/init.d/jh_taosd.deb ${install_main_dir}/init.d/jh_taosd - ${csudo} cp ${script_dir}/init.d/jh_taosd.deb ${service_config_dir}/jh_taosd && ${csudo} chmod a+x ${service_config_dir}/jh_taosd - ${csudo} cp -f ${script_dir}/init.d/tarbitratord.deb ${install_main_dir}/init.d/tarbitratord - ${csudo} cp ${script_dir}/init.d/tarbitratord.deb ${service_config_dir}/tarbitratord && ${csudo} chmod a+x ${service_config_dir}/tarbitratord + ${csudo}cp -f ${script_dir}/init.d/jh_taosd.deb ${install_main_dir}/init.d/jh_taosd + ${csudo}cp ${script_dir}/init.d/jh_taosd.deb ${service_config_dir}/jh_taosd && ${csudo}chmod a+x ${service_config_dir}/jh_taosd + ${csudo}cp -f ${script_dir}/init.d/tarbitratord.deb ${install_main_dir}/init.d/tarbitratord + ${csudo}cp ${script_dir}/init.d/tarbitratord.deb ${service_config_dir}/tarbitratord && ${csudo}chmod a+x ${service_config_dir}/tarbitratord elif ((${os_type}==2)); then - ${csudo} cp -f ${script_dir}/init.d/jh_taosd.rpm ${install_main_dir}/init.d/jh_taosd - ${csudo} cp ${script_dir}/init.d/jh_taosd.rpm ${service_config_dir}/jh_taosd && ${csudo} chmod a+x ${service_config_dir}/jh_taosd - ${csudo} cp -f ${script_dir}/init.d/tarbitratord.rpm ${install_main_dir}/init.d/tarbitratord - ${csudo} cp ${script_dir}/init.d/tarbitratord.rpm ${service_config_dir}/tarbitratord && ${csudo} chmod a+x ${service_config_dir}/tarbitratord + ${csudo}cp -f ${script_dir}/init.d/jh_taosd.rpm ${install_main_dir}/init.d/jh_taosd + ${csudo}cp ${script_dir}/init.d/jh_taosd.rpm ${service_config_dir}/jh_taosd && ${csudo}chmod a+x ${service_config_dir}/jh_taosd + ${csudo}cp -f ${script_dir}/init.d/tarbitratord.rpm ${install_main_dir}/init.d/tarbitratord + ${csudo}cp ${script_dir}/init.d/tarbitratord.rpm ${service_config_dir}/tarbitratord && ${csudo}chmod a+x ${service_config_dir}/tarbitratord fi if ((${initd_mod}==1)); then - ${csudo} chkconfig --add jh_taosd || : - ${csudo} chkconfig --level 2345 jh_taosd on || : - ${csudo} chkconfig --add tarbitratord || : - ${csudo} chkconfig --level 2345 tarbitratord on || : + ${csudo}chkconfig --add jh_taosd || : + ${csudo}chkconfig --level 2345 jh_taosd on || : + ${csudo}chkconfig --add tarbitratord || : + ${csudo}chkconfig --level 2345 tarbitratord on || : elif ((${initd_mod}==2)); then - ${csudo} insserv jh_taosd || : - ${csudo} insserv -d jh_taosd || : - ${csudo} insserv tarbitratord || : - ${csudo} insserv -d tarbitratord || : + ${csudo}insserv jh_taosd || : + ${csudo}insserv -d jh_taosd || : + ${csudo}insserv tarbitratord || : + ${csudo}insserv -d tarbitratord || : elif ((${initd_mod}==3)); then - ${csudo} update-rc.d jh_taosd defaults || : - ${csudo} update-rc.d tarbitratord defaults || : + ${csudo}update-rc.d jh_taosd defaults || : + ${csudo}update-rc.d tarbitratord defaults || : fi } @@ -573,27 +573,27 @@ function clean_service_on_systemd() { jh_taosd_service_config="${service_config_dir}/jh_taosd.service" if systemctl is-active --quiet jh_taosd; then echo "jh_iot is running, stopping it..." - ${csudo} systemctl stop jh_taosd &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop jh_taosd &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable jh_taosd &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${jh_taosd_service_config} + ${csudo}systemctl disable jh_taosd &> /dev/null || echo &> /dev/null + ${csudo}rm -f ${jh_taosd_service_config} tarbitratord_service_config="${service_config_dir}/tarbitratord.service" if systemctl is-active --quiet tarbitratord; then echo "tarbitrator is running, stopping it..." - ${csudo} systemctl stop tarbitratord &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop tarbitratord &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable tarbitratord &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${tarbitratord_service_config} + ${csudo}systemctl disable tarbitratord &> /dev/null || echo &> /dev/null + ${csudo}rm -f ${tarbitratord_service_config} if [ "$verMode" == "cluster" ]; then nginx_service_config="${service_config_dir}/nginxd.service" if systemctl is-active --quiet nginxd; then echo "Nginx for jh_iot is running, stopping it..." - ${csudo} systemctl stop nginxd &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop nginxd &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable nginxd &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${nginx_service_config} + ${csudo}systemctl disable nginxd &> /dev/null || echo &> /dev/null + ${csudo}rm -f ${nginx_service_config} fi } @@ -601,81 +601,81 @@ function install_service_on_systemd() { clean_service_on_systemd service_config="${service_config_dir}/jh_taosd.service" - ${csudo} bash -c "echo '[Unit]' >> ${service_config}" - ${csudo} bash -c "echo 'Description=jh_iot server service' >> ${service_config}" - ${csudo} bash -c "echo 'After=network-online.target' >> ${service_config}" - ${csudo} bash -c "echo 'Wants=network-online.target' >> ${service_config}" - ${csudo} bash -c "echo >> ${service_config}" - ${csudo} bash -c "echo '[Service]' >> ${service_config}" - ${csudo} bash -c "echo 'Type=simple' >> ${service_config}" - ${csudo} bash -c "echo 'ExecStart=/usr/bin/jh_taosd' >> ${service_config}" - ${csudo} bash -c "echo 'ExecStartPre=/usr/local/jh_taos/bin/startPre.sh' >> ${service_config}" - ${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${service_config}" - ${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${service_config}" - ${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${service_config}" - ${csudo} bash -c "echo 'LimitCORE=infinity' >> ${service_config}" - ${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${service_config}" - ${csudo} bash -c "echo 'StandardOutput=null' >> ${service_config}" - ${csudo} bash -c "echo 'Restart=always' >> ${service_config}" - ${csudo} bash -c "echo 'StartLimitBurst=3' >> ${service_config}" - ${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${service_config}" - ${csudo} bash -c "echo >> ${service_config}" - ${csudo} bash -c "echo '[Install]' >> ${service_config}" - ${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${service_config}" - ${csudo} systemctl enable jh_taosd + ${csudo}bash -c "echo '[Unit]' >> ${service_config}" + ${csudo}bash -c "echo 'Description=jh_iot server service' >> ${service_config}" + ${csudo}bash -c "echo 'After=network-online.target' >> ${service_config}" + ${csudo}bash -c "echo 'Wants=network-online.target' >> ${service_config}" + ${csudo}bash -c "echo >> ${service_config}" + ${csudo}bash -c "echo '[Service]' >> ${service_config}" + ${csudo}bash -c "echo 'Type=simple' >> ${service_config}" + ${csudo}bash -c "echo 'ExecStart=/usr/bin/jh_taosd' >> ${service_config}" + ${csudo}bash -c "echo 'ExecStartPre=/usr/local/jh_taos/bin/startPre.sh' >> ${service_config}" + ${csudo}bash -c "echo 'TimeoutStopSec=1000000s' >> ${service_config}" + ${csudo}bash -c "echo 'LimitNOFILE=infinity' >> ${service_config}" + ${csudo}bash -c "echo 'LimitNPROC=infinity' >> ${service_config}" + ${csudo}bash -c "echo 'LimitCORE=infinity' >> ${service_config}" + ${csudo}bash -c "echo 'TimeoutStartSec=0' >> ${service_config}" + ${csudo}bash -c "echo 'StandardOutput=null' >> ${service_config}" + ${csudo}bash -c "echo 'Restart=always' >> ${service_config}" + ${csudo}bash -c "echo 'StartLimitBurst=3' >> ${service_config}" + ${csudo}bash -c "echo 'StartLimitInterval=60s' >> ${service_config}" + ${csudo}bash -c "echo >> ${service_config}" + ${csudo}bash -c "echo '[Install]' >> ${service_config}" + ${csudo}bash -c "echo 'WantedBy=multi-user.target' >> ${service_config}" + ${csudo}systemctl enable jh_taosd tarbitratord_service_config="${service_config_dir}/tarbitratord.service" - ${csudo} bash -c "echo '[Unit]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Description=jh_iot arbitrator service' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'After=network-online.target' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Wants=network-online.target' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo '[Service]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Type=simple' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'ExecStart=/usr/bin/tarbitrator' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitCORE=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StandardOutput=null' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Restart=always' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StartLimitBurst=3' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo '[Install]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${tarbitratord_service_config}" - #${csudo} systemctl enable tarbitratord + ${csudo}bash -c "echo '[Unit]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Description=jh_iot arbitrator service' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'After=network-online.target' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Wants=network-online.target' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo '[Service]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Type=simple' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'ExecStart=/usr/bin/tarbitrator' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'TimeoutStopSec=1000000s' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitNOFILE=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitNPROC=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitCORE=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'TimeoutStartSec=0' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StandardOutput=null' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Restart=always' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StartLimitBurst=3' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StartLimitInterval=60s' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo '[Install]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'WantedBy=multi-user.target' >> ${tarbitratord_service_config}" + #${csudo}systemctl enable tarbitratord if [ "$verMode" == "cluster" ]; then nginx_service_config="${service_config_dir}/nginxd.service" - ${csudo} bash -c "echo '[Unit]' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'Description=Nginx For jh_iot Service' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'After=network-online.target' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'Wants=network-online.target' >> ${nginx_service_config}" - ${csudo} bash -c "echo >> ${nginx_service_config}" - ${csudo} bash -c "echo '[Service]' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'Type=forking' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'PIDFile=/usr/local/nginxd/logs/nginx.pid' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'ExecStart=/usr/local/nginxd/sbin/nginx' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'ExecStop=/usr/local/nginxd/sbin/nginx -s stop' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'LimitCORE=infinity' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'StandardOutput=null' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'Restart=always' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'StartLimitBurst=3' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${nginx_service_config}" - ${csudo} bash -c "echo >> ${nginx_service_config}" - ${csudo} bash -c "echo '[Install]' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${nginx_service_config}" - if ! ${csudo} systemctl enable nginxd &> /dev/null; then - ${csudo} systemctl daemon-reexec - ${csudo} systemctl enable nginxd + ${csudo}bash -c "echo '[Unit]' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'Description=Nginx For jh_iot Service' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'After=network-online.target' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'Wants=network-online.target' >> ${nginx_service_config}" + ${csudo}bash -c "echo >> ${nginx_service_config}" + ${csudo}bash -c "echo '[Service]' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'Type=forking' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'PIDFile=/usr/local/nginxd/logs/nginx.pid' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'ExecStart=/usr/local/nginxd/sbin/nginx' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'ExecStop=/usr/local/nginxd/sbin/nginx -s stop' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'TimeoutStopSec=1000000s' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'LimitNOFILE=infinity' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'LimitNPROC=infinity' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'LimitCORE=infinity' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'TimeoutStartSec=0' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'StandardOutput=null' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'Restart=always' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'StartLimitBurst=3' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'StartLimitInterval=60s' >> ${nginx_service_config}" + ${csudo}bash -c "echo >> ${nginx_service_config}" + ${csudo}bash -c "echo '[Install]' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'WantedBy=multi-user.target' >> ${nginx_service_config}" + if ! ${csudo}systemctl enable nginxd &> /dev/null; then + ${csudo}systemctl daemon-reexec + ${csudo}systemctl enable nginxd fi - ${csudo} systemctl start nginxd + ${csudo}systemctl start nginxd fi } @@ -755,9 +755,9 @@ function update() { # Stop the service if running if pidof jh_taosd &> /dev/null; then if ((${service_mod}==0)); then - ${csudo} systemctl stop jh_taosd || : + ${csudo}systemctl stop jh_taosd || : elif ((${service_mod}==1)); then - ${csudo} service jh_taosd stop || : + ${csudo}service jh_taosd stop || : else kill_process jh_taosd fi @@ -766,9 +766,9 @@ function update() { if [ "$verMode" == "cluster" ]; then if pidof nginx &> /dev/null; then if ((${service_mod}==0)); then - ${csudo} systemctl stop nginxd || : + ${csudo}systemctl stop nginxd || : elif ((${service_mod}==1)); then - ${csudo} service nginxd stop || : + ${csudo}service nginxd stop || : else kill_process nginx fi @@ -809,9 +809,9 @@ function update() { echo echo -e "${GREEN_DARK}To configure jh_iot ${NC}: edit /etc/jh_taos/taos.cfg" if ((${service_mod}==0)); then - echo -e "${GREEN_DARK}To start jh_iot ${NC}: ${csudo} systemctl start jh_taosd${NC}" + echo -e "${GREEN_DARK}To start jh_iot ${NC}: ${csudo}systemctl start jh_taosd${NC}" elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start jh_iot ${NC}: ${csudo} service jh_taosd start${NC}" + echo -e "${GREEN_DARK}To start jh_iot ${NC}: ${csudo}service jh_taosd start${NC}" else echo -e "${GREEN_DARK}To start jh_iot ${NC}: ./jh_taosd${NC}" fi @@ -886,9 +886,9 @@ function install() { echo echo -e "${GREEN_DARK}To configure jh_iot ${NC}: edit /etc/jh_taos/taos.cfg" if ((${service_mod}==0)); then - echo -e "${GREEN_DARK}To start jh_iot ${NC}: ${csudo} systemctl start jh_taosd${NC}" + echo -e "${GREEN_DARK}To start jh_iot ${NC}: ${csudo}systemctl start jh_taosd${NC}" elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start jh_iot ${NC}: ${csudo} service jh_taosd start${NC}" + echo -e "${GREEN_DARK}To start jh_iot ${NC}: ${csudo}service jh_taosd start${NC}" else echo -e "${GREEN_DARK}To start jh_iot ${NC}: jh_taosd${NC}" fi diff --git a/packaging/tools/install_kh.sh b/packaging/tools/install_kh.sh index e53e014351ff9ae64e727151c72f3157a2077043..8adad4dbbe32c6e052721f8657425b19d7338c4e 100755 --- a/packaging/tools/install_kh.sh +++ b/packaging/tools/install_kh.sh @@ -46,7 +46,7 @@ NC='\033[0m' csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi update_flag=0 @@ -144,129 +144,129 @@ done function kill_process() { pid=$(ps -ef | grep "$1" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function install_main_path() { #create install main dir and all sub dir - ${csudo} rm -rf ${install_main_dir} || : - ${csudo} mkdir -p ${install_main_dir} - ${csudo} mkdir -p ${install_main_dir}/cfg - ${csudo} mkdir -p ${install_main_dir}/bin -# ${csudo} mkdir -p ${install_main_dir}/connector - ${csudo} mkdir -p ${install_main_dir}/driver -# ${csudo} mkdir -p ${install_main_dir}/examples - ${csudo} mkdir -p ${install_main_dir}/include - ${csudo} mkdir -p ${install_main_dir}/init.d + ${csudo}rm -rf ${install_main_dir} || : + ${csudo}mkdir -p ${install_main_dir} + ${csudo}mkdir -p ${install_main_dir}/cfg + ${csudo}mkdir -p ${install_main_dir}/bin +# ${csudo}mkdir -p ${install_main_dir}/connector + ${csudo}mkdir -p ${install_main_dir}/driver +# ${csudo}mkdir -p ${install_main_dir}/examples + ${csudo}mkdir -p ${install_main_dir}/include + ${csudo}mkdir -p ${install_main_dir}/init.d if [ "$verMode" == "cluster" ]; then - ${csudo} mkdir -p ${nginx_dir} + ${csudo}mkdir -p ${nginx_dir} fi } function install_bin() { # Remove links - ${csudo} rm -f ${bin_link_dir}/khclient || : - ${csudo} rm -f ${bin_link_dir}/khserver || : - ${csudo} rm -f ${bin_link_dir}/khdemo || : - ${csudo} rm -f ${bin_link_dir}/rmkh || : - ${csudo} rm -f ${bin_link_dir}/tarbitrator || : - ${csudo} rm -f ${bin_link_dir}/set_core || : - ${csudo} rm -f ${bin_link_dir}/run_taosd.sh || : + ${csudo}rm -f ${bin_link_dir}/khclient || : + ${csudo}rm -f ${bin_link_dir}/khserver || : + ${csudo}rm -f ${bin_link_dir}/khdemo || : + ${csudo}rm -f ${bin_link_dir}/rmkh || : + ${csudo}rm -f ${bin_link_dir}/tarbitrator || : + ${csudo}rm -f ${bin_link_dir}/set_core || : + ${csudo}rm -f ${bin_link_dir}/run_taosd.sh || : - ${csudo} cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo} chmod 0555 ${install_main_dir}/bin/* + ${csudo}cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo}chmod 0555 ${install_main_dir}/bin/* #Make link - [ -x ${install_main_dir}/bin/khclient ] && ${csudo} ln -s ${install_main_dir}/bin/khclient ${bin_link_dir}/khclient || : - [ -x ${install_main_dir}/bin/khserver ] && ${csudo} ln -s ${install_main_dir}/bin/khserver ${bin_link_dir}/khserver || : - [ -x ${install_main_dir}/bin/khdemo ] && ${csudo} ln -s ${install_main_dir}/bin/khdemo ${bin_link_dir}/khdemo || : - [ -x ${install_main_dir}/bin/remove_kh.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove_kh.sh ${bin_link_dir}/rmkh || : - [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo} ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : - [ -x ${install_main_dir}/bin/run_taosd.sh ] && ${csudo} ln -s ${install_main_dir}/bin/run_taosd.sh ${bin_link_dir}/run_taosd.sh || : - [ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo} ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || : + [ -x ${install_main_dir}/bin/khclient ] && ${csudo}ln -s ${install_main_dir}/bin/khclient ${bin_link_dir}/khclient || : + [ -x ${install_main_dir}/bin/khserver ] && ${csudo}ln -s ${install_main_dir}/bin/khserver ${bin_link_dir}/khserver || : + [ -x ${install_main_dir}/bin/khdemo ] && ${csudo}ln -s ${install_main_dir}/bin/khdemo ${bin_link_dir}/khdemo || : + [ -x ${install_main_dir}/bin/remove_kh.sh ] && ${csudo}ln -s ${install_main_dir}/bin/remove_kh.sh ${bin_link_dir}/rmkh || : + [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo}ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : + [ -x ${install_main_dir}/bin/run_taosd.sh ] && ${csudo}ln -s ${install_main_dir}/bin/run_taosd.sh ${bin_link_dir}/run_taosd.sh || : + [ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo}ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || : if [ "$verMode" == "cluster" ]; then - ${csudo} cp -r ${script_dir}/nginxd/* ${nginx_dir} && ${csudo} chmod 0555 ${nginx_dir}/* - ${csudo} mkdir -p ${nginx_dir}/logs - ${csudo} chmod 777 ${nginx_dir}/sbin/nginx + ${csudo}cp -r ${script_dir}/nginxd/* ${nginx_dir} && ${csudo}chmod 0555 ${nginx_dir}/* + ${csudo}mkdir -p ${nginx_dir}/logs + ${csudo}chmod 777 ${nginx_dir}/sbin/nginx fi } function install_lib() { # Remove links - ${csudo} rm -f ${lib_link_dir}/libtaos.* || : - ${csudo} rm -f ${lib64_link_dir}/libtaos.* || : - ${csudo} cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo} chmod 777 ${install_main_dir}/driver/* + ${csudo}rm -f ${lib_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : + ${csudo}cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo}chmod 777 ${install_main_dir}/driver/* - ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 - ${csudo} ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so + ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 + ${csudo}ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so if [[ -d ${lib64_link_dir} && ! -e ${lib64_link_dir}/libtaos.so ]]; then - ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 || : - ${csudo} ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || : + ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 || : + ${csudo}ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || : fi if [ "$osType" != "Darwin" ]; then - ${csudo} ldconfig + ${csudo}ldconfig else - ${csudo} update_dyld_shared_cache + ${csudo}update_dyld_shared_cache fi } function install_header() { - ${csudo} rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taoserror.h || : - ${csudo} cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo} chmod 644 ${install_main_dir}/include/* - ${csudo} ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h - ${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h + ${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taoserror.h || : + ${csudo}cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo}chmod 644 ${install_main_dir}/include/* + ${csudo}ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h + ${csudo}ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h } function install_jemalloc() { jemalloc_dir=${script_dir}/jemalloc if [ -d ${jemalloc_dir} ]; then - ${csudo} /usr/bin/install -c -d /usr/local/bin + ${csudo}/usr/bin/install -c -d /usr/local/bin if [ -f ${jemalloc_dir}/bin/jemalloc-config ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc-config /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc-config /usr/local/bin fi if [ -f ${jemalloc_dir}/bin/jemalloc.sh ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc.sh /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc.sh /usr/local/bin fi if [ -f ${jemalloc_dir}/bin/jeprof ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jeprof /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jeprof /usr/local/bin fi if [ -f ${jemalloc_dir}/include/jemalloc/jemalloc.h ]; then - ${csudo} /usr/bin/install -c -d /usr/local/include/jemalloc - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/include/jemalloc/jemalloc.h /usr/local/include/jemalloc + ${csudo}/usr/bin/install -c -d /usr/local/include/jemalloc + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/include/jemalloc/jemalloc.h /usr/local/include/jemalloc fi if [ -f ${jemalloc_dir}/lib/libjemalloc.so.2 ]; then - ${csudo} /usr/bin/install -c -d /usr/local/lib - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.so.2 /usr/local/lib - ${csudo} ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so - ${csudo} /usr/bin/install -c -d /usr/local/lib + ${csudo}/usr/bin/install -c -d /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.so.2 /usr/local/lib + ${csudo}ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so + ${csudo}/usr/bin/install -c -d /usr/local/lib if [ -f ${jemalloc_dir}/lib/libjemalloc.a ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.a /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.a /usr/local/lib fi if [ -f ${jemalloc_dir}/lib/libjemalloc_pic.a ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc_pic.a /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc_pic.a /usr/local/lib fi if [ -f ${jemalloc_dir}/lib/libjemalloc_pic.a ]; then - ${csudo} /usr/bin/install -c -d /usr/local/lib/pkgconfig - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/lib/pkgconfig/jemalloc.pc /usr/local/lib/pkgconfig + ${csudo}/usr/bin/install -c -d /usr/local/lib/pkgconfig + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/lib/pkgconfig/jemalloc.pc /usr/local/lib/pkgconfig fi fi if [ -f ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html ]; then - ${csudo} /usr/bin/install -c -d /usr/local/share/doc/jemalloc - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html /usr/local/share/doc/jemalloc + ${csudo}/usr/bin/install -c -d /usr/local/share/doc/jemalloc + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html /usr/local/share/doc/jemalloc fi if [ -f ${jemalloc_dir}/share/man/man3/jemalloc.3 ]; then - ${csudo} /usr/bin/install -c -d /usr/local/share/man/man3 - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/share/man/man3/jemalloc.3 /usr/local/share/man/man3 + ${csudo}/usr/bin/install -c -d /usr/local/share/man/man3 + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/share/man/man3/jemalloc.3 /usr/local/share/man/man3 fi if [ -d /etc/ld.so.conf.d ]; then - echo "/usr/local/lib" | ${csudo} tee /etc/ld.so.conf.d/jemalloc.conf > /dev/null || echo -e "failed to write /etc/ld.so.conf.d/jemalloc.conf" - ${csudo} ldconfig + echo "/usr/local/lib" | ${csudo}tee /etc/ld.so.conf.d/jemalloc.conf > /dev/null || echo -e "failed to write /etc/ld.so.conf.d/jemalloc.conf" + ${csudo}ldconfig else echo "/etc/ld.so.conf.d not found!" fi @@ -286,7 +286,7 @@ function add_newHostname_to_hosts() { return fi done - ${csudo} echo "127.0.0.1 $1" >> /etc/hosts ||: + ${csudo}echo "127.0.0.1 $1" >> /etc/hosts ||: } function set_hostname() { @@ -300,7 +300,7 @@ function set_hostname() { fi done - ${csudo} hostname $newHostname ||: + ${csudo}hostname $newHostname ||: retval=`echo $?` if [[ $retval != 0 ]]; then echo @@ -310,15 +310,15 @@ function set_hostname() { #ubuntu/centos /etc/hostname if [[ -e /etc/hostname ]]; then - ${csudo} echo $newHostname > /etc/hostname ||: + ${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 ||: + ${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}/kinghistorian.cfg + ${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$newHostname/" ${cfg_install_dir}/kinghistorian.cfg serverFqdn=$newHostname if [[ -e /etc/hosts ]]; then @@ -353,7 +353,7 @@ 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}/kinghistorian.cfg + ${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${cfg_install_dir}/kinghistorian.cfg serverFqdn=$localFqdn echo return @@ -375,7 +375,7 @@ function set_ipAsFqdn() { 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}/kinghistorian.cfg + ${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${cfg_install_dir}/kinghistorian.cfg serverFqdn=$localFqdn break fi @@ -423,13 +423,13 @@ function local_fqdn_check() { function install_config() { if [ ! -f ${cfg_install_dir}/kinghistorian.cfg ]; then - ${csudo} mkdir -p ${cfg_install_dir} - [ -f ${script_dir}/cfg/kinghistorian.cfg ] && ${csudo} cp ${script_dir}/cfg/kinghistorian.cfg ${cfg_install_dir} - ${csudo} chmod 644 ${cfg_install_dir}/* + ${csudo}mkdir -p ${cfg_install_dir} + [ -f ${script_dir}/cfg/kinghistorian.cfg ] && ${csudo}cp ${script_dir}/cfg/kinghistorian.cfg ${cfg_install_dir} + ${csudo}chmod 644 ${cfg_install_dir}/* fi - ${csudo} cp -f ${script_dir}/cfg/kinghistorian.cfg ${install_main_dir}/cfg/kinghistorian.cfg.org - ${csudo} ln -s ${cfg_install_dir}/kinghistorian.cfg ${install_main_dir}/cfg + ${csudo}cp -f ${script_dir}/cfg/kinghistorian.cfg ${install_main_dir}/cfg/kinghistorian.cfg.org + ${csudo}ln -s ${cfg_install_dir}/kinghistorian.cfg ${install_main_dir}/cfg [ ! -z $1 ] && return 0 || : # only install client @@ -459,7 +459,7 @@ function install_config() { # check the format of the firstEp #if [[ $firstEp == $FQDN_PATTERN ]]; then # Write the first FQDN to configuration file - ${csudo} sed -i -r "s/#*\s*(firstEp\s*).*/\1$firstEp/" ${cfg_install_dir}/kinghistorian.cfg + ${csudo}sed -i -r "s/#*\s*(firstEp\s*).*/\1$firstEp/" ${cfg_install_dir}/kinghistorian.cfg break #else # read -p "Please enter the correct FQDN:port: " firstEp @@ -472,66 +472,66 @@ function install_config() { function install_log() { - ${csudo} rm -rf ${log_dir} || : - ${csudo} mkdir -p ${log_dir} && ${csudo} chmod 777 ${log_dir} + ${csudo}rm -rf ${log_dir} || : + ${csudo}mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir} - ${csudo} ln -s ${log_dir} ${install_main_dir}/log + ${csudo}ln -s ${log_dir} ${install_main_dir}/log } function install_data() { - ${csudo} mkdir -p ${data_dir} + ${csudo}mkdir -p ${data_dir} - ${csudo} ln -s ${data_dir} ${install_main_dir}/data + ${csudo}ln -s ${data_dir} ${install_main_dir}/data } function install_connector() { - ${csudo} cp -rf ${script_dir}/connector/* ${install_main_dir}/connector + ${csudo}cp -rf ${script_dir}/connector/* ${install_main_dir}/connector } function install_examples() { if [ -d ${script_dir}/examples ]; then - ${csudo} cp -rf ${script_dir}/examples/* ${install_main_dir}/examples + ${csudo}cp -rf ${script_dir}/examples/* ${install_main_dir}/examples fi } function clean_service_on_sysvinit() { if pidof khserver &> /dev/null; then - ${csudo} service khserver stop || : + ${csudo}service khserver stop || : fi if pidof tarbitrator &> /dev/null; then - ${csudo} service tarbitratord stop || : + ${csudo}service tarbitratord stop || : fi if ((${initd_mod}==1)); then if [ -e ${service_config_dir}/khserver ]; then - ${csudo} chkconfig --del khserver || : + ${csudo}chkconfig --del khserver || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} chkconfig --del tarbitratord || : + ${csudo}chkconfig --del tarbitratord || : fi elif ((${initd_mod}==2)); then if [ -e ${service_config_dir}/khserver ]; then - ${csudo} insserv -r khserver || : + ${csudo}insserv -r khserver || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} insserv -r tarbitratord || : + ${csudo}insserv -r tarbitratord || : fi elif ((${initd_mod}==3)); then if [ -e ${service_config_dir}/khserver ]; then - ${csudo} update-rc.d -f khserver remove || : + ${csudo}update-rc.d -f khserver remove || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} update-rc.d -f tarbitratord remove || : + ${csudo}update-rc.d -f tarbitratord remove || : fi fi - ${csudo} rm -f ${service_config_dir}/khserver || : - ${csudo} rm -f ${service_config_dir}/tarbitratord || : + ${csudo}rm -f ${service_config_dir}/khserver || : + ${csudo}rm -f ${service_config_dir}/tarbitratord || : if $(which init &> /dev/null); then - ${csudo} init q || : + ${csudo}init q || : fi } @@ -542,30 +542,30 @@ function install_service_on_sysvinit() { # Install khserver service if ((${os_type}==1)); then - ${csudo} cp -f ${script_dir}/init.d/khserver.deb ${install_main_dir}/init.d/khserver - ${csudo} cp ${script_dir}/init.d/khserver.deb ${service_config_dir}/khserver && ${csudo} chmod a+x ${service_config_dir}/khserver - ${csudo} cp -f ${script_dir}/init.d/tarbitratord.deb ${install_main_dir}/init.d/tarbitratord - ${csudo} cp ${script_dir}/init.d/tarbitratord.deb ${service_config_dir}/tarbitratord && ${csudo} chmod a+x ${service_config_dir}/tarbitratord + ${csudo}cp -f ${script_dir}/init.d/khserver.deb ${install_main_dir}/init.d/khserver + ${csudo}cp ${script_dir}/init.d/khserver.deb ${service_config_dir}/khserver && ${csudo}chmod a+x ${service_config_dir}/khserver + ${csudo}cp -f ${script_dir}/init.d/tarbitratord.deb ${install_main_dir}/init.d/tarbitratord + ${csudo}cp ${script_dir}/init.d/tarbitratord.deb ${service_config_dir}/tarbitratord && ${csudo}chmod a+x ${service_config_dir}/tarbitratord elif ((${os_type}==2)); then - ${csudo} cp -f ${script_dir}/init.d/khserver.rpm ${install_main_dir}/init.d/khserver - ${csudo} cp ${script_dir}/init.d/khserver.rpm ${service_config_dir}/khserver && ${csudo} chmod a+x ${service_config_dir}/khserver - ${csudo} cp -f ${script_dir}/init.d/tarbitratord.rpm ${install_main_dir}/init.d/tarbitratord - ${csudo} cp ${script_dir}/init.d/tarbitratord.rpm ${service_config_dir}/tarbitratord && ${csudo} chmod a+x ${service_config_dir}/tarbitratord + ${csudo}cp -f ${script_dir}/init.d/khserver.rpm ${install_main_dir}/init.d/khserver + ${csudo}cp ${script_dir}/init.d/khserver.rpm ${service_config_dir}/khserver && ${csudo}chmod a+x ${service_config_dir}/khserver + ${csudo}cp -f ${script_dir}/init.d/tarbitratord.rpm ${install_main_dir}/init.d/tarbitratord + ${csudo}cp ${script_dir}/init.d/tarbitratord.rpm ${service_config_dir}/tarbitratord && ${csudo}chmod a+x ${service_config_dir}/tarbitratord fi if ((${initd_mod}==1)); then - ${csudo} chkconfig --add khserver || : - ${csudo} chkconfig --level 2345 khserver on || : - ${csudo} chkconfig --add tarbitratord || : - ${csudo} chkconfig --level 2345 tarbitratord on || : + ${csudo}chkconfig --add khserver || : + ${csudo}chkconfig --level 2345 khserver on || : + ${csudo}chkconfig --add tarbitratord || : + ${csudo}chkconfig --level 2345 tarbitratord on || : elif ((${initd_mod}==2)); then - ${csudo} insserv khserver || : - ${csudo} insserv -d khserver || : - ${csudo} insserv tarbitratord || : - ${csudo} insserv -d tarbitratord || : + ${csudo}insserv khserver || : + ${csudo}insserv -d khserver || : + ${csudo}insserv tarbitratord || : + ${csudo}insserv -d tarbitratord || : elif ((${initd_mod}==3)); then - ${csudo} update-rc.d khserver defaults || : - ${csudo} update-rc.d tarbitratord defaults || : + ${csudo}update-rc.d khserver defaults || : + ${csudo}update-rc.d tarbitratord defaults || : fi } @@ -573,27 +573,27 @@ function clean_service_on_systemd() { khserver_service_config="${service_config_dir}/khserver.service" if systemctl is-active --quiet khserver; then echo "KingHistorian is running, stopping it..." - ${csudo} systemctl stop khserver &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop khserver &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable khserver &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${khserver_service_config} + ${csudo}systemctl disable khserver &> /dev/null || echo &> /dev/null + ${csudo}rm -f ${khserver_service_config} tarbitratord_service_config="${service_config_dir}/tarbitratord.service" if systemctl is-active --quiet tarbitratord; then echo "tarbitrator is running, stopping it..." - ${csudo} systemctl stop tarbitratord &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop tarbitratord &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable tarbitratord &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${tarbitratord_service_config} + ${csudo}systemctl disable tarbitratord &> /dev/null || echo &> /dev/null + ${csudo}rm -f ${tarbitratord_service_config} if [ "$verMode" == "cluster" ]; then nginx_service_config="${service_config_dir}/nginxd.service" if systemctl is-active --quiet nginxd; then echo "Nginx for KingHistorian is running, stopping it..." - ${csudo} systemctl stop nginxd &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop nginxd &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable nginxd &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${nginx_service_config} + ${csudo}systemctl disable nginxd &> /dev/null || echo &> /dev/null + ${csudo}rm -f ${nginx_service_config} fi } @@ -601,81 +601,81 @@ function install_service_on_systemd() { clean_service_on_systemd service_config="${service_config_dir}/khserver.service" - ${csudo} bash -c "echo '[Unit]' >> ${service_config}" - ${csudo} bash -c "echo 'Description=KingHistorian server service' >> ${service_config}" - ${csudo} bash -c "echo 'After=network-online.target' >> ${service_config}" - ${csudo} bash -c "echo 'Wants=network-online.target' >> ${service_config}" - ${csudo} bash -c "echo >> ${service_config}" - ${csudo} bash -c "echo '[Service]' >> ${service_config}" - ${csudo} bash -c "echo 'Type=simple' >> ${service_config}" - ${csudo} bash -c "echo 'ExecStart=/usr/bin/khserver' >> ${service_config}" - ${csudo} bash -c "echo 'ExecStartPre=/usr/local/kinghistorian/bin/startPre.sh' >> ${service_config}" - ${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${service_config}" - ${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${service_config}" - ${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${service_config}" - ${csudo} bash -c "echo 'LimitCORE=infinity' >> ${service_config}" - ${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${service_config}" - ${csudo} bash -c "echo 'StandardOutput=null' >> ${service_config}" - ${csudo} bash -c "echo 'Restart=always' >> ${service_config}" - ${csudo} bash -c "echo 'StartLimitBurst=3' >> ${service_config}" - ${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${service_config}" - ${csudo} bash -c "echo >> ${service_config}" - ${csudo} bash -c "echo '[Install]' >> ${service_config}" - ${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${service_config}" - ${csudo} systemctl enable khserver + ${csudo}bash -c "echo '[Unit]' >> ${service_config}" + ${csudo}bash -c "echo 'Description=KingHistorian server service' >> ${service_config}" + ${csudo}bash -c "echo 'After=network-online.target' >> ${service_config}" + ${csudo}bash -c "echo 'Wants=network-online.target' >> ${service_config}" + ${csudo}bash -c "echo >> ${service_config}" + ${csudo}bash -c "echo '[Service]' >> ${service_config}" + ${csudo}bash -c "echo 'Type=simple' >> ${service_config}" + ${csudo}bash -c "echo 'ExecStart=/usr/bin/khserver' >> ${service_config}" + ${csudo}bash -c "echo 'ExecStartPre=/usr/local/kinghistorian/bin/startPre.sh' >> ${service_config}" + ${csudo}bash -c "echo 'TimeoutStopSec=1000000s' >> ${service_config}" + ${csudo}bash -c "echo 'LimitNOFILE=infinity' >> ${service_config}" + ${csudo}bash -c "echo 'LimitNPROC=infinity' >> ${service_config}" + ${csudo}bash -c "echo 'LimitCORE=infinity' >> ${service_config}" + ${csudo}bash -c "echo 'TimeoutStartSec=0' >> ${service_config}" + ${csudo}bash -c "echo 'StandardOutput=null' >> ${service_config}" + ${csudo}bash -c "echo 'Restart=always' >> ${service_config}" + ${csudo}bash -c "echo 'StartLimitBurst=3' >> ${service_config}" + ${csudo}bash -c "echo 'StartLimitInterval=60s' >> ${service_config}" + ${csudo}bash -c "echo >> ${service_config}" + ${csudo}bash -c "echo '[Install]' >> ${service_config}" + ${csudo}bash -c "echo 'WantedBy=multi-user.target' >> ${service_config}" + ${csudo}systemctl enable khserver tarbitratord_service_config="${service_config_dir}/tarbitratord.service" - ${csudo} bash -c "echo '[Unit]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Description=KingHistorian arbitrator service' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'After=network-online.target' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Wants=network-online.target' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo '[Service]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Type=simple' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'ExecStart=/usr/bin/tarbitrator' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitCORE=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StandardOutput=null' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Restart=always' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StartLimitBurst=3' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo '[Install]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${tarbitratord_service_config}" - #${csudo} systemctl enable tarbitratord + ${csudo}bash -c "echo '[Unit]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Description=KingHistorian arbitrator service' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'After=network-online.target' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Wants=network-online.target' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo '[Service]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Type=simple' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'ExecStart=/usr/bin/tarbitrator' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'TimeoutStopSec=1000000s' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitNOFILE=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitNPROC=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitCORE=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'TimeoutStartSec=0' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StandardOutput=null' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Restart=always' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StartLimitBurst=3' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StartLimitInterval=60s' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo '[Install]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'WantedBy=multi-user.target' >> ${tarbitratord_service_config}" + #${csudo}systemctl enable tarbitratord if [ "$verMode" == "cluster" ]; then nginx_service_config="${service_config_dir}/nginxd.service" - ${csudo} bash -c "echo '[Unit]' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'Description=Nginx For KingHistorian Service' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'After=network-online.target' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'Wants=network-online.target' >> ${nginx_service_config}" - ${csudo} bash -c "echo >> ${nginx_service_config}" - ${csudo} bash -c "echo '[Service]' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'Type=forking' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'PIDFile=/usr/local/nginxd/logs/nginx.pid' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'ExecStart=/usr/local/nginxd/sbin/nginx' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'ExecStop=/usr/local/nginxd/sbin/nginx -s stop' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'LimitCORE=infinity' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'StandardOutput=null' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'Restart=always' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'StartLimitBurst=3' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${nginx_service_config}" - ${csudo} bash -c "echo >> ${nginx_service_config}" - ${csudo} bash -c "echo '[Install]' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${nginx_service_config}" - if ! ${csudo} systemctl enable nginxd &> /dev/null; then - ${csudo} systemctl daemon-reexec - ${csudo} systemctl enable nginxd + ${csudo}bash -c "echo '[Unit]' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'Description=Nginx For KingHistorian Service' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'After=network-online.target' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'Wants=network-online.target' >> ${nginx_service_config}" + ${csudo}bash -c "echo >> ${nginx_service_config}" + ${csudo}bash -c "echo '[Service]' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'Type=forking' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'PIDFile=/usr/local/nginxd/logs/nginx.pid' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'ExecStart=/usr/local/nginxd/sbin/nginx' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'ExecStop=/usr/local/nginxd/sbin/nginx -s stop' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'TimeoutStopSec=1000000s' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'LimitNOFILE=infinity' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'LimitNPROC=infinity' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'LimitCORE=infinity' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'TimeoutStartSec=0' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'StandardOutput=null' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'Restart=always' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'StartLimitBurst=3' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'StartLimitInterval=60s' >> ${nginx_service_config}" + ${csudo}bash -c "echo >> ${nginx_service_config}" + ${csudo}bash -c "echo '[Install]' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'WantedBy=multi-user.target' >> ${nginx_service_config}" + if ! ${csudo}systemctl enable nginxd &> /dev/null; then + ${csudo}systemctl daemon-reexec + ${csudo}systemctl enable nginxd fi - ${csudo} systemctl start nginxd + ${csudo}systemctl start nginxd fi } @@ -755,9 +755,9 @@ function update() { # Stop the service if running if pidof khserver &> /dev/null; then if ((${service_mod}==0)); then - ${csudo} systemctl stop khserver || : + ${csudo}systemctl stop khserver || : elif ((${service_mod}==1)); then - ${csudo} service khserver stop || : + ${csudo}service khserver stop || : else kill_process khserver fi @@ -766,9 +766,9 @@ function update() { if [ "$verMode" == "cluster" ]; then if pidof nginx &> /dev/null; then if ((${service_mod}==0)); then - ${csudo} systemctl stop nginxd || : + ${csudo}systemctl stop nginxd || : elif ((${service_mod}==1)); then - ${csudo} service nginxd stop || : + ${csudo}service nginxd stop || : else kill_process nginx fi @@ -809,9 +809,9 @@ function update() { echo echo -e "${GREEN_DARK}To configure KingHistorian ${NC}: edit /etc/kinghistorian/kinghistorian.cfg" if ((${service_mod}==0)); then - echo -e "${GREEN_DARK}To start KingHistorian ${NC}: ${csudo} systemctl start khserver${NC}" + echo -e "${GREEN_DARK}To start KingHistorian ${NC}: ${csudo}systemctl start khserver${NC}" elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start KingHistorian ${NC}: ${csudo} service khserver start${NC}" + echo -e "${GREEN_DARK}To start KingHistorian ${NC}: ${csudo}service khserver start${NC}" else echo -e "${GREEN_DARK}To start KingHistorian ${NC}: ./khserver${NC}" fi @@ -886,9 +886,9 @@ function install() { echo echo -e "${GREEN_DARK}To configure KingHistorian ${NC}: edit /etc/kinghistorian/kinghistorian.cfg" if ((${service_mod}==0)); then - echo -e "${GREEN_DARK}To start KingHistorian ${NC}: ${csudo} systemctl start khserver${NC}" + echo -e "${GREEN_DARK}To start KingHistorian ${NC}: ${csudo}systemctl start khserver${NC}" elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start KingHistorian ${NC}: ${csudo} service khserver start${NC}" + echo -e "${GREEN_DARK}To start KingHistorian ${NC}: ${csudo}service khserver start${NC}" else echo -e "${GREEN_DARK}To start KingHistorian ${NC}: khserver${NC}" fi diff --git a/packaging/tools/install_power.sh b/packaging/tools/install_power.sh index cde33f9b368041d7072bc851d54b68e30a067a95..705c86432569c3e59145f8d887e55b78b111a4a8 100755 --- a/packaging/tools/install_power.sh +++ b/packaging/tools/install_power.sh @@ -49,7 +49,7 @@ NC='\033[0m' csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi update_flag=0 @@ -149,119 +149,119 @@ done function kill_process() { pid=$(ps -ef | grep "$1" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function install_main_path() { #create install main dir and all sub dir - ${csudo} rm -rf ${install_main_dir} || : - ${csudo} mkdir -p ${install_main_dir} - ${csudo} mkdir -p ${install_main_dir}/cfg - ${csudo} mkdir -p ${install_main_dir}/bin - ${csudo} mkdir -p ${install_main_dir}/connector - ${csudo} mkdir -p ${install_main_dir}/driver - ${csudo} mkdir -p ${install_main_dir}/examples - ${csudo} mkdir -p ${install_main_dir}/include - ${csudo} mkdir -p ${install_main_dir}/init.d + ${csudo}rm -rf ${install_main_dir} || : + ${csudo}mkdir -p ${install_main_dir} + ${csudo}mkdir -p ${install_main_dir}/cfg + ${csudo}mkdir -p ${install_main_dir}/bin + ${csudo}mkdir -p ${install_main_dir}/connector + ${csudo}mkdir -p ${install_main_dir}/driver + ${csudo}mkdir -p ${install_main_dir}/examples + ${csudo}mkdir -p ${install_main_dir}/include + ${csudo}mkdir -p ${install_main_dir}/init.d if [ "$verMode" == "cluster" ]; then - ${csudo} mkdir -p ${nginx_dir} + ${csudo}mkdir -p ${nginx_dir} fi } function install_bin() { # Remove links - ${csudo} rm -f ${bin_link_dir}/power || : - ${csudo} rm -f ${bin_link_dir}/powerd || : - ${csudo} rm -f ${bin_link_dir}/powerdemo || : - ${csudo} rm -f ${bin_link_dir}/rmpower || : - ${csudo} rm -f ${bin_link_dir}/tarbitrator || : - ${csudo} rm -f ${bin_link_dir}/set_core || : - ${csudo} rm -f ${bin_link_dir}/run_taosd.sh || : + ${csudo}rm -f ${bin_link_dir}/power || : + ${csudo}rm -f ${bin_link_dir}/powerd || : + ${csudo}rm -f ${bin_link_dir}/powerdemo || : + ${csudo}rm -f ${bin_link_dir}/rmpower || : + ${csudo}rm -f ${bin_link_dir}/tarbitrator || : + ${csudo}rm -f ${bin_link_dir}/set_core || : + ${csudo}rm -f ${bin_link_dir}/run_taosd.sh || : - ${csudo} cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo} chmod 0555 ${install_main_dir}/bin/* + ${csudo}cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo}chmod 0555 ${install_main_dir}/bin/* #Make link - [ -x ${install_main_dir}/bin/power ] && ${csudo} ln -s ${install_main_dir}/bin/power ${bin_link_dir}/power || : - [ -x ${install_main_dir}/bin/powerd ] && ${csudo} ln -s ${install_main_dir}/bin/powerd ${bin_link_dir}/powerd || : - [ -x ${install_main_dir}/bin/powerdemo ] && ${csudo} ln -s ${install_main_dir}/bin/powerdemo ${bin_link_dir}/powerdemo || : - [ -x ${install_main_dir}/bin/remove_power.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove_power.sh ${bin_link_dir}/rmpower || : - [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo} ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : - [ -x ${install_main_dir}/bin/run_taosd.sh ] && ${csudo} ln -s ${install_main_dir}/bin/run_taosd.sh ${bin_link_dir}/run_taosd.sh || : - [ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo} ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || : + [ -x ${install_main_dir}/bin/power ] && ${csudo}ln -s ${install_main_dir}/bin/power ${bin_link_dir}/power || : + [ -x ${install_main_dir}/bin/powerd ] && ${csudo}ln -s ${install_main_dir}/bin/powerd ${bin_link_dir}/powerd || : + [ -x ${install_main_dir}/bin/powerdemo ] && ${csudo}ln -s ${install_main_dir}/bin/powerdemo ${bin_link_dir}/powerdemo || : + [ -x ${install_main_dir}/bin/remove_power.sh ] && ${csudo}ln -s ${install_main_dir}/bin/remove_power.sh ${bin_link_dir}/rmpower || : + [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo}ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : + [ -x ${install_main_dir}/bin/run_taosd.sh ] && ${csudo}ln -s ${install_main_dir}/bin/run_taosd.sh ${bin_link_dir}/run_taosd.sh || : + [ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo}ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || : if [ "$verMode" == "cluster" ]; then - ${csudo} cp -r ${script_dir}/nginxd/* ${nginx_dir} && ${csudo} chmod 0555 ${nginx_dir}/* - ${csudo} mkdir -p ${nginx_dir}/logs - ${csudo} chmod 777 ${nginx_dir}/sbin/nginx + ${csudo}cp -r ${script_dir}/nginxd/* ${nginx_dir} && ${csudo}chmod 0555 ${nginx_dir}/* + ${csudo}mkdir -p ${nginx_dir}/logs + ${csudo}chmod 777 ${nginx_dir}/sbin/nginx fi } function install_lib() { # Remove links - ${csudo} rm -f ${lib_link_dir}/libtaos.* || : - ${csudo} rm -f ${lib64_link_dir}/libtaos.* || : - #${csudo} rm -rf ${v15_java_app_dir} || : - ${csudo} cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo} chmod 777 ${install_main_dir}/driver/* + ${csudo}rm -f ${lib_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : + #${csudo}rm -rf ${v15_java_app_dir} || : + ${csudo}cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo}chmod 777 ${install_main_dir}/driver/* - ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 - ${csudo} ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so + ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 + ${csudo}ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so if [[ -d ${lib64_link_dir} && ! -e ${lib64_link_dir}/libtaos.so ]]; then - ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 || : - ${csudo} ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || : + ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 || : + ${csudo}ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || : fi - ${csudo} ldconfig + ${csudo}ldconfig } function install_jemalloc() { jemalloc_dir=${script_dir}/jemalloc if [ -d ${jemalloc_dir} ]; then - ${csudo} /usr/bin/install -c -d /usr/local/bin + ${csudo}/usr/bin/install -c -d /usr/local/bin if [ -f ${jemalloc_dir}/bin/jemalloc-config ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc-config /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc-config /usr/local/bin fi if [ -f ${jemalloc_dir}/bin/jemalloc.sh ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc.sh /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc.sh /usr/local/bin fi if [ -f ${jemalloc_dir}/bin/jeprof ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jeprof /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jeprof /usr/local/bin fi if [ -f ${jemalloc_dir}/include/jemalloc/jemalloc.h ]; then - ${csudo} /usr/bin/install -c -d /usr/local/include/jemalloc - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/include/jemalloc/jemalloc.h /usr/local/include/jemalloc + ${csudo}/usr/bin/install -c -d /usr/local/include/jemalloc + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/include/jemalloc/jemalloc.h /usr/local/include/jemalloc fi if [ -f ${jemalloc_dir}/lib/libjemalloc.so.2 ]; then - ${csudo} /usr/bin/install -c -d /usr/local/lib - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.so.2 /usr/local/lib - ${csudo} ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so - ${csudo} /usr/bin/install -c -d /usr/local/lib + ${csudo}/usr/bin/install -c -d /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.so.2 /usr/local/lib + ${csudo}ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so + ${csudo}/usr/bin/install -c -d /usr/local/lib if [ -f ${jemalloc_dir}/lib/libjemalloc.a ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.a /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.a /usr/local/lib fi if [ -f ${jemalloc_dir}/lib/libjemalloc_pic.a ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc_pic.a /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc_pic.a /usr/local/lib fi if [ -f ${jemalloc_dir}/lib/libjemalloc_pic.a ]; then - ${csudo} /usr/bin/install -c -d /usr/local/lib/pkgconfig - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/lib/pkgconfig/jemalloc.pc /usr/local/lib/pkgconfig + ${csudo}/usr/bin/install -c -d /usr/local/lib/pkgconfig + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/lib/pkgconfig/jemalloc.pc /usr/local/lib/pkgconfig fi fi if [ -f ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html ]; then - ${csudo} /usr/bin/install -c -d /usr/local/share/doc/jemalloc - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html /usr/local/share/doc/jemalloc + ${csudo}/usr/bin/install -c -d /usr/local/share/doc/jemalloc + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html /usr/local/share/doc/jemalloc fi if [ -f ${jemalloc_dir}/share/man/man3/jemalloc.3 ]; then - ${csudo} /usr/bin/install -c -d /usr/local/share/man/man3 - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/share/man/man3/jemalloc.3 /usr/local/share/man/man3 + ${csudo}/usr/bin/install -c -d /usr/local/share/man/man3 + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/share/man/man3/jemalloc.3 /usr/local/share/man/man3 fi if [ -d /etc/ld.so.conf.d ]; then - echo "/usr/local/lib" | ${csudo} tee /etc/ld.so.conf.d/jemalloc.conf > /dev/null || echo -e "failed to write /etc/ld.so.conf.d/jemalloc.conf" - ${csudo} ldconfig + echo "/usr/local/lib" | ${csudo}tee /etc/ld.so.conf.d/jemalloc.conf > /dev/null || echo -e "failed to write /etc/ld.so.conf.d/jemalloc.conf" + ${csudo}ldconfig else echo "/etc/ld.so.conf.d not found!" fi @@ -269,11 +269,11 @@ function install_jemalloc() { } function install_header() { - ${csudo} rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h || : - ${csudo} cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo} chmod 644 ${install_main_dir}/include/* - ${csudo} ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h - ${csudo} ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h - ${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h + ${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h || : + ${csudo}cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo}chmod 644 ${install_main_dir}/include/* + ${csudo}ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h + ${csudo}ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h + ${csudo}ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h } function add_newHostname_to_hosts() { @@ -289,7 +289,7 @@ function add_newHostname_to_hosts() { return fi done - ${csudo} echo "127.0.0.1 $1" >> /etc/hosts ||: + ${csudo}echo "127.0.0.1 $1" >> /etc/hosts ||: } function set_hostname() { @@ -303,7 +303,7 @@ function set_hostname() { fi done - ${csudo} hostname $newHostname ||: + ${csudo}hostname $newHostname ||: retval=`echo $?` if [[ $retval != 0 ]]; then echo @@ -316,15 +316,15 @@ function set_hostname() { #ubuntu/centos /etc/hostname if [[ -e /etc/hostname ]]; then - ${csudo} echo $newHostname > /etc/hostname ||: + ${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 ||: + ${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}/power.cfg + ${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$newHostname/" ${cfg_install_dir}/power.cfg serverFqdn=$newHostname if [[ -e /etc/hosts ]]; then @@ -359,7 +359,7 @@ 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}/power.cfg + ${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${cfg_install_dir}/power.cfg serverFqdn=$localFqdn echo return @@ -381,7 +381,7 @@ function set_ipAsFqdn() { 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}/power.cfg + ${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${cfg_install_dir}/power.cfg serverFqdn=$localFqdn break fi @@ -429,13 +429,13 @@ function local_fqdn_check() { function install_config() { if [ ! -f ${cfg_install_dir}/power.cfg ]; then - ${csudo} mkdir -p ${cfg_install_dir} - [ -f ${script_dir}/cfg/power.cfg ] && ${csudo} cp ${script_dir}/cfg/power.cfg ${cfg_install_dir} - ${csudo} chmod 644 ${cfg_install_dir}/* + ${csudo}mkdir -p ${cfg_install_dir} + [ -f ${script_dir}/cfg/power.cfg ] && ${csudo}cp ${script_dir}/cfg/power.cfg ${cfg_install_dir} + ${csudo}chmod 644 ${cfg_install_dir}/* fi - ${csudo} cp -f ${script_dir}/cfg/power.cfg ${install_main_dir}/cfg/power.cfg.org - ${csudo} ln -s ${cfg_install_dir}/power.cfg ${install_main_dir}/cfg + ${csudo}cp -f ${script_dir}/cfg/power.cfg ${install_main_dir}/cfg/power.cfg.org + ${csudo}ln -s ${cfg_install_dir}/power.cfg ${install_main_dir}/cfg [ ! -z $1 ] && return 0 || : # only install client @@ -465,7 +465,7 @@ function install_config() { # check the format of the firstEp #if [[ $firstEp == $FQDN_PATTERN ]]; then # Write the first FQDN to configuration file - ${csudo} sed -i -r "s/#*\s*(firstEp\s*).*/\1$firstEp/" ${cfg_install_dir}/power.cfg + ${csudo}sed -i -r "s/#*\s*(firstEp\s*).*/\1$firstEp/" ${cfg_install_dir}/power.cfg break #else # read -p "Please enter the correct FQDN:port: " firstEp @@ -478,69 +478,69 @@ function install_config() { function install_log() { - ${csudo} rm -rf ${log_dir} || : - ${csudo} mkdir -p ${log_dir} && ${csudo} chmod 777 ${log_dir} + ${csudo}rm -rf ${log_dir} || : + ${csudo}mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir} - ${csudo} ln -s ${log_dir} ${install_main_dir}/log + ${csudo}ln -s ${log_dir} ${install_main_dir}/log } function install_data() { - ${csudo} mkdir -p ${data_dir} + ${csudo}mkdir -p ${data_dir} - ${csudo} ln -s ${data_dir} ${install_main_dir}/data + ${csudo}ln -s ${data_dir} ${install_main_dir}/data } function install_connector() { - ${csudo} cp -rf ${script_dir}/connector/* ${install_main_dir}/connector + ${csudo}cp -rf ${script_dir}/connector/* ${install_main_dir}/connector } function install_examples() { if [ -d ${script_dir}/examples ]; then - ${csudo} cp -rf ${script_dir}/examples/* ${install_main_dir}/examples + ${csudo}cp -rf ${script_dir}/examples/* ${install_main_dir}/examples fi } function clean_service_on_sysvinit() { #restart_config_str="power:2345:respawn:${service_config_dir}/powerd start" - #${csudo} sed -i "\|${restart_config_str}|d" /etc/inittab || : + #${csudo}sed -i "\|${restart_config_str}|d" /etc/inittab || : if pidof powerd &> /dev/null; then - ${csudo} service powerd stop || : + ${csudo}service powerd stop || : fi if pidof tarbitrator &> /dev/null; then - ${csudo} service tarbitratord stop || : + ${csudo}service tarbitratord stop || : fi if ((${initd_mod}==1)); then if [ -e ${service_config_dir}/powerd ]; then - ${csudo} chkconfig --del powerd || : + ${csudo}chkconfig --del powerd || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} chkconfig --del tarbitratord || : + ${csudo}chkconfig --del tarbitratord || : fi elif ((${initd_mod}==2)); then if [ -e ${service_config_dir}/powerd ]; then - ${csudo} insserv -r powerd || : + ${csudo}insserv -r powerd || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} insserv -r tarbitratord || : + ${csudo}insserv -r tarbitratord || : fi elif ((${initd_mod}==3)); then if [ -e ${service_config_dir}/powerd ]; then - ${csudo} update-rc.d -f powerd remove || : + ${csudo}update-rc.d -f powerd remove || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} update-rc.d -f tarbitratord remove || : + ${csudo}update-rc.d -f tarbitratord remove || : fi fi - ${csudo} rm -f ${service_config_dir}/powerd || : - ${csudo} rm -f ${service_config_dir}/tarbitratord || : + ${csudo}rm -f ${service_config_dir}/powerd || : + ${csudo}rm -f ${service_config_dir}/tarbitratord || : if $(which init &> /dev/null); then - ${csudo} init q || : + ${csudo}init q || : fi } @@ -551,33 +551,33 @@ function install_service_on_sysvinit() { # Install powerd service if ((${os_type}==1)); then - ${csudo} cp -f ${script_dir}/init.d/powerd.deb ${install_main_dir}/init.d/powerd - ${csudo} cp ${script_dir}/init.d/powerd.deb ${service_config_dir}/powerd && ${csudo} chmod a+x ${service_config_dir}/powerd - ${csudo} cp -f ${script_dir}/init.d/tarbitratord.deb ${install_main_dir}/init.d/tarbitratord - ${csudo} cp ${script_dir}/init.d/tarbitratord.deb ${service_config_dir}/tarbitratord && ${csudo} chmod a+x ${service_config_dir}/tarbitratord + ${csudo}cp -f ${script_dir}/init.d/powerd.deb ${install_main_dir}/init.d/powerd + ${csudo}cp ${script_dir}/init.d/powerd.deb ${service_config_dir}/powerd && ${csudo}chmod a+x ${service_config_dir}/powerd + ${csudo}cp -f ${script_dir}/init.d/tarbitratord.deb ${install_main_dir}/init.d/tarbitratord + ${csudo}cp ${script_dir}/init.d/tarbitratord.deb ${service_config_dir}/tarbitratord && ${csudo}chmod a+x ${service_config_dir}/tarbitratord elif ((${os_type}==2)); then - ${csudo} cp -f ${script_dir}/init.d/powerd.rpm ${install_main_dir}/init.d/powerd - ${csudo} cp ${script_dir}/init.d/powerd.rpm ${service_config_dir}/powerd && ${csudo} chmod a+x ${service_config_dir}/powerd - ${csudo} cp -f ${script_dir}/init.d/tarbitratord.rpm ${install_main_dir}/init.d/tarbitratord - ${csudo} cp ${script_dir}/init.d/tarbitratord.rpm ${service_config_dir}/tarbitratord && ${csudo} chmod a+x ${service_config_dir}/tarbitratord + ${csudo}cp -f ${script_dir}/init.d/powerd.rpm ${install_main_dir}/init.d/powerd + ${csudo}cp ${script_dir}/init.d/powerd.rpm ${service_config_dir}/powerd && ${csudo}chmod a+x ${service_config_dir}/powerd + ${csudo}cp -f ${script_dir}/init.d/tarbitratord.rpm ${install_main_dir}/init.d/tarbitratord + ${csudo}cp ${script_dir}/init.d/tarbitratord.rpm ${service_config_dir}/tarbitratord && ${csudo}chmod a+x ${service_config_dir}/tarbitratord fi #restart_config_str="power:2345:respawn:${service_config_dir}/powerd start" - #${csudo} grep -q -F "$restart_config_str" /etc/inittab || ${csudo} bash -c "echo '${restart_config_str}' >> /etc/inittab" + #${csudo}grep -q -F "$restart_config_str" /etc/inittab || ${csudo}bash -c "echo '${restart_config_str}' >> /etc/inittab" if ((${initd_mod}==1)); then - ${csudo} chkconfig --add powerd || : - ${csudo} chkconfig --level 2345 powerd on || : - ${csudo} chkconfig --add tarbitratord || : - ${csudo} chkconfig --level 2345 tarbitratord on || : + ${csudo}chkconfig --add powerd || : + ${csudo}chkconfig --level 2345 powerd on || : + ${csudo}chkconfig --add tarbitratord || : + ${csudo}chkconfig --level 2345 tarbitratord on || : elif ((${initd_mod}==2)); then - ${csudo} insserv powerd || : - ${csudo} insserv -d powerd || : - ${csudo} insserv tarbitratord || : - ${csudo} insserv -d tarbitratord || : + ${csudo}insserv powerd || : + ${csudo}insserv -d powerd || : + ${csudo}insserv tarbitratord || : + ${csudo}insserv -d tarbitratord || : elif ((${initd_mod}==3)); then - ${csudo} update-rc.d powerd defaults || : - ${csudo} update-rc.d tarbitratord defaults || : + ${csudo}update-rc.d powerd defaults || : + ${csudo}update-rc.d tarbitratord defaults || : fi } @@ -585,27 +585,27 @@ function clean_service_on_systemd() { powerd_service_config="${service_config_dir}/powerd.service" if systemctl is-active --quiet powerd; then echo "PowerDB is running, stopping it..." - ${csudo} systemctl stop powerd &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop powerd &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable powerd &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${powerd_service_config} + ${csudo}systemctl disable powerd &> /dev/null || echo &> /dev/null + ${csudo}rm -f ${powerd_service_config} tarbitratord_service_config="${service_config_dir}/tarbitratord.service" if systemctl is-active --quiet tarbitratord; then echo "tarbitrator is running, stopping it..." - ${csudo} systemctl stop tarbitratord &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop tarbitratord &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable tarbitratord &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${tarbitratord_service_config} + ${csudo}systemctl disable tarbitratord &> /dev/null || echo &> /dev/null + ${csudo}rm -f ${tarbitratord_service_config} if [ "$verMode" == "cluster" ]; then nginx_service_config="${service_config_dir}/nginxd.service" if systemctl is-active --quiet nginxd; then echo "Nginx for PowerDB is running, stopping it..." - ${csudo} systemctl stop nginxd &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop nginxd &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable nginxd &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${nginx_service_config} + ${csudo}systemctl disable nginxd &> /dev/null || echo &> /dev/null + ${csudo}rm -f ${nginx_service_config} fi } @@ -615,81 +615,81 @@ function install_service_on_systemd() { clean_service_on_systemd powerd_service_config="${service_config_dir}/powerd.service" - ${csudo} bash -c "echo '[Unit]' >> ${powerd_service_config}" - ${csudo} bash -c "echo 'Description=PowerDB server service' >> ${powerd_service_config}" - ${csudo} bash -c "echo 'After=network-online.target' >> ${powerd_service_config}" - ${csudo} bash -c "echo 'Wants=network-online.target' >> ${powerd_service_config}" - ${csudo} bash -c "echo >> ${powerd_service_config}" - ${csudo} bash -c "echo '[Service]' >> ${powerd_service_config}" - ${csudo} bash -c "echo 'Type=simple' >> ${powerd_service_config}" - ${csudo} bash -c "echo 'ExecStart=/usr/bin/powerd' >> ${powerd_service_config}" - ${csudo} bash -c "echo 'ExecStartPre=/usr/local/power/bin/startPre.sh' >> ${powerd_service_config}" - ${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${powerd_service_config}" - ${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${powerd_service_config}" - ${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${powerd_service_config}" - ${csudo} bash -c "echo 'LimitCORE=infinity' >> ${powerd_service_config}" - ${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${powerd_service_config}" - ${csudo} bash -c "echo 'StandardOutput=null' >> ${powerd_service_config}" - ${csudo} bash -c "echo 'Restart=always' >> ${powerd_service_config}" - ${csudo} bash -c "echo 'StartLimitBurst=3' >> ${powerd_service_config}" - ${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${powerd_service_config}" - ${csudo} bash -c "echo >> ${powerd_service_config}" - ${csudo} bash -c "echo '[Install]' >> ${powerd_service_config}" - ${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${powerd_service_config}" - ${csudo} systemctl enable powerd + ${csudo}bash -c "echo '[Unit]' >> ${powerd_service_config}" + ${csudo}bash -c "echo 'Description=PowerDB server service' >> ${powerd_service_config}" + ${csudo}bash -c "echo 'After=network-online.target' >> ${powerd_service_config}" + ${csudo}bash -c "echo 'Wants=network-online.target' >> ${powerd_service_config}" + ${csudo}bash -c "echo >> ${powerd_service_config}" + ${csudo}bash -c "echo '[Service]' >> ${powerd_service_config}" + ${csudo}bash -c "echo 'Type=simple' >> ${powerd_service_config}" + ${csudo}bash -c "echo 'ExecStart=/usr/bin/powerd' >> ${powerd_service_config}" + ${csudo}bash -c "echo 'ExecStartPre=/usr/local/power/bin/startPre.sh' >> ${powerd_service_config}" + ${csudo}bash -c "echo 'TimeoutStopSec=1000000s' >> ${powerd_service_config}" + ${csudo}bash -c "echo 'LimitNOFILE=infinity' >> ${powerd_service_config}" + ${csudo}bash -c "echo 'LimitNPROC=infinity' >> ${powerd_service_config}" + ${csudo}bash -c "echo 'LimitCORE=infinity' >> ${powerd_service_config}" + ${csudo}bash -c "echo 'TimeoutStartSec=0' >> ${powerd_service_config}" + ${csudo}bash -c "echo 'StandardOutput=null' >> ${powerd_service_config}" + ${csudo}bash -c "echo 'Restart=always' >> ${powerd_service_config}" + ${csudo}bash -c "echo 'StartLimitBurst=3' >> ${powerd_service_config}" + ${csudo}bash -c "echo 'StartLimitInterval=60s' >> ${powerd_service_config}" + ${csudo}bash -c "echo >> ${powerd_service_config}" + ${csudo}bash -c "echo '[Install]' >> ${powerd_service_config}" + ${csudo}bash -c "echo 'WantedBy=multi-user.target' >> ${powerd_service_config}" + ${csudo}systemctl enable powerd tarbitratord_service_config="${service_config_dir}/tarbitratord.service" - ${csudo} bash -c "echo '[Unit]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Description=PowerDB arbitrator service' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'After=network-online.target' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Wants=network-online.target' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo '[Service]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Type=simple' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'ExecStart=/usr/bin/tarbitrator' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitCORE=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StandardOutput=null' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Restart=always' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StartLimitBurst=3' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo '[Install]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${tarbitratord_service_config}" - #${csudo} systemctl enable tarbitratord + ${csudo}bash -c "echo '[Unit]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Description=PowerDB arbitrator service' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'After=network-online.target' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Wants=network-online.target' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo '[Service]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Type=simple' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'ExecStart=/usr/bin/tarbitrator' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'TimeoutStopSec=1000000s' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitNOFILE=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitNPROC=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitCORE=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'TimeoutStartSec=0' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StandardOutput=null' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Restart=always' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StartLimitBurst=3' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StartLimitInterval=60s' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo '[Install]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'WantedBy=multi-user.target' >> ${tarbitratord_service_config}" + #${csudo}systemctl enable tarbitratord if [ "$verMode" == "cluster" ]; then nginx_service_config="${service_config_dir}/nginxd.service" - ${csudo} bash -c "echo '[Unit]' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'Description=Nginx For PowrDB Service' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'After=network-online.target' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'Wants=network-online.target' >> ${nginx_service_config}" - ${csudo} bash -c "echo >> ${nginx_service_config}" - ${csudo} bash -c "echo '[Service]' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'Type=forking' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'PIDFile=/usr/local/nginxd/logs/nginx.pid' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'ExecStart=/usr/local/nginxd/sbin/nginx' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'ExecStop=/usr/local/nginxd/sbin/nginx -s stop' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'LimitCORE=infinity' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'StandardOutput=null' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'Restart=always' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'StartLimitBurst=3' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${nginx_service_config}" - ${csudo} bash -c "echo >> ${nginx_service_config}" - ${csudo} bash -c "echo '[Install]' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${nginx_service_config}" - if ! ${csudo} systemctl enable nginxd &> /dev/null; then - ${csudo} systemctl daemon-reexec - ${csudo} systemctl enable nginxd + ${csudo}bash -c "echo '[Unit]' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'Description=Nginx For PowrDB Service' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'After=network-online.target' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'Wants=network-online.target' >> ${nginx_service_config}" + ${csudo}bash -c "echo >> ${nginx_service_config}" + ${csudo}bash -c "echo '[Service]' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'Type=forking' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'PIDFile=/usr/local/nginxd/logs/nginx.pid' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'ExecStart=/usr/local/nginxd/sbin/nginx' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'ExecStop=/usr/local/nginxd/sbin/nginx -s stop' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'TimeoutStopSec=1000000s' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'LimitNOFILE=infinity' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'LimitNPROC=infinity' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'LimitCORE=infinity' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'TimeoutStartSec=0' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'StandardOutput=null' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'Restart=always' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'StartLimitBurst=3' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'StartLimitInterval=60s' >> ${nginx_service_config}" + ${csudo}bash -c "echo >> ${nginx_service_config}" + ${csudo}bash -c "echo '[Install]' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'WantedBy=multi-user.target' >> ${nginx_service_config}" + if ! ${csudo}systemctl enable nginxd &> /dev/null; then + ${csudo}systemctl daemon-reexec + ${csudo}systemctl enable nginxd fi - ${csudo} systemctl start nginxd + ${csudo}systemctl start nginxd fi } @@ -770,9 +770,9 @@ function update_PowerDB() { # Stop the service if running if pidof powerd &> /dev/null; then if ((${service_mod}==0)); then - ${csudo} systemctl stop powerd || : + ${csudo}systemctl stop powerd || : elif ((${service_mod}==1)); then - ${csudo} service powerd stop || : + ${csudo}service powerd stop || : else kill_process powerd fi @@ -781,9 +781,9 @@ function update_PowerDB() { if [ "$verMode" == "cluster" ]; then if pidof nginx &> /dev/null; then if ((${service_mod}==0)); then - ${csudo} systemctl stop nginxd || : + ${csudo}systemctl stop nginxd || : elif ((${service_mod}==1)); then - ${csudo} service nginxd stop || : + ${csudo}service nginxd stop || : else kill_process nginx fi @@ -824,9 +824,9 @@ function update_PowerDB() { echo echo -e "${GREEN_DARK}To configure PowerDB ${NC}: edit /etc/power/power.cfg" if ((${service_mod}==0)); then - echo -e "${GREEN_DARK}To start PowerDB ${NC}: ${csudo} systemctl start powerd${NC}" + echo -e "${GREEN_DARK}To start PowerDB ${NC}: ${csudo}systemctl start powerd${NC}" elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start PowerDB ${NC}: ${csudo} service powerd start${NC}" + echo -e "${GREEN_DARK}To start PowerDB ${NC}: ${csudo}service powerd start${NC}" else echo -e "${GREEN_DARK}To start PowerDB ${NC}: ./powerd${NC}" fi @@ -901,9 +901,9 @@ function install_PowerDB() { echo echo -e "${GREEN_DARK}To configure PowerDB ${NC}: edit /etc/power/power.cfg" if ((${service_mod}==0)); then - echo -e "${GREEN_DARK}To start PowerDB ${NC}: ${csudo} systemctl start powerd${NC}" + echo -e "${GREEN_DARK}To start PowerDB ${NC}: ${csudo}systemctl start powerd${NC}" elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start PowerDB ${NC}: ${csudo} service powerd start${NC}" + echo -e "${GREEN_DARK}To start PowerDB ${NC}: ${csudo}service powerd start${NC}" else echo -e "${GREEN_DARK}To start PowerDB ${NC}: powerd${NC}" fi diff --git a/packaging/tools/install_pro.sh b/packaging/tools/install_pro.sh index 44a21abc19f19a1bffc2be42e71db30157d4e220..f1c71985f1464e3074c006b1eec7597f5990bf9d 100755 --- a/packaging/tools/install_pro.sh +++ b/packaging/tools/install_pro.sh @@ -46,7 +46,7 @@ NC='\033[0m' csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi update_flag=0 @@ -144,130 +144,130 @@ done function kill_process() { pid=$(ps -ef | grep "$1" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function install_main_path() { #create install main dir and all sub dir - ${csudo} rm -rf ${install_main_dir} || : - ${csudo} mkdir -p ${install_main_dir} - ${csudo} mkdir -p ${install_main_dir}/cfg - ${csudo} mkdir -p ${install_main_dir}/bin -# ${csudo} mkdir -p ${install_main_dir}/connector - ${csudo} mkdir -p ${install_main_dir}/driver -# ${csudo} mkdir -p ${install_main_dir}/examples - ${csudo} mkdir -p ${install_main_dir}/include - ${csudo} mkdir -p ${install_main_dir}/init.d + ${csudo}rm -rf ${install_main_dir} || : + ${csudo}mkdir -p ${install_main_dir} + ${csudo}mkdir -p ${install_main_dir}/cfg + ${csudo}mkdir -p ${install_main_dir}/bin +# ${csudo}mkdir -p ${install_main_dir}/connector + ${csudo}mkdir -p ${install_main_dir}/driver +# ${csudo}mkdir -p ${install_main_dir}/examples + ${csudo}mkdir -p ${install_main_dir}/include + ${csudo}mkdir -p ${install_main_dir}/init.d if [ "$verMode" == "cluster" ]; then - ${csudo} mkdir -p ${nginx_dir} + ${csudo}mkdir -p ${nginx_dir} fi } function install_bin() { # Remove links - ${csudo} rm -f ${bin_link_dir}/prodbc || : - ${csudo} rm -f ${bin_link_dir}/prodbs || : - ${csudo} rm -f ${bin_link_dir}/prodemo || : - ${csudo} rm -f ${bin_link_dir}/rmprodb || : - ${csudo} rm -f ${bin_link_dir}/tarbitrator || : - ${csudo} rm -f ${bin_link_dir}/set_core || : - ${csudo} rm -f ${bin_link_dir}/run_taosd.sh || : + ${csudo}rm -f ${bin_link_dir}/prodbc || : + ${csudo}rm -f ${bin_link_dir}/prodbs || : + ${csudo}rm -f ${bin_link_dir}/prodemo || : + ${csudo}rm -f ${bin_link_dir}/rmprodb || : + ${csudo}rm -f ${bin_link_dir}/tarbitrator || : + ${csudo}rm -f ${bin_link_dir}/set_core || : + ${csudo}rm -f ${bin_link_dir}/run_taosd.sh || : - ${csudo} cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo} chmod 0555 ${install_main_dir}/bin/* + ${csudo}cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo}chmod 0555 ${install_main_dir}/bin/* #Make link - [ -x ${install_main_dir}/bin/prodbc ] && ${csudo} ln -s ${install_main_dir}/bin/prodbc ${bin_link_dir}/prodbc || : - [ -x ${install_main_dir}/bin/prodbs ] && ${csudo} ln -s ${install_main_dir}/bin/prodbs ${bin_link_dir}/prodbs || : - [ -x ${install_main_dir}/bin/prodemo ] && ${csudo} ln -s ${install_main_dir}/bin/prodemo ${bin_link_dir}/prodemo || : - [ -x ${install_main_dir}/bin/remove_pro.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove_pro.sh ${bin_link_dir}/rmprodb || : - [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo} ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : - [ -x ${install_main_dir}/bin/run_taosd.sh ] && ${csudo} ln -s ${install_main_dir}/bin/run_taosd.sh ${bin_link_dir}/run_taosd.sh || : - [ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo} ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || : + [ -x ${install_main_dir}/bin/prodbc ] && ${csudo}ln -s ${install_main_dir}/bin/prodbc ${bin_link_dir}/prodbc || : + [ -x ${install_main_dir}/bin/prodbs ] && ${csudo}ln -s ${install_main_dir}/bin/prodbs ${bin_link_dir}/prodbs || : + [ -x ${install_main_dir}/bin/prodemo ] && ${csudo}ln -s ${install_main_dir}/bin/prodemo ${bin_link_dir}/prodemo || : + [ -x ${install_main_dir}/bin/remove_pro.sh ] && ${csudo}ln -s ${install_main_dir}/bin/remove_pro.sh ${bin_link_dir}/rmprodb || : + [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo}ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : + [ -x ${install_main_dir}/bin/run_taosd.sh ] && ${csudo}ln -s ${install_main_dir}/bin/run_taosd.sh ${bin_link_dir}/run_taosd.sh || : + [ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo}ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || : if [ "$verMode" == "cluster" ]; then - ${csudo} cp -r ${script_dir}/nginxd/* ${nginx_dir} && ${csudo} chmod 0555 ${nginx_dir}/* - ${csudo} mkdir -p ${nginx_dir}/logs - ${csudo} chmod 777 ${nginx_dir}/sbin/nginx + ${csudo}cp -r ${script_dir}/nginxd/* ${nginx_dir} && ${csudo}chmod 0555 ${nginx_dir}/* + ${csudo}mkdir -p ${nginx_dir}/logs + ${csudo}chmod 777 ${nginx_dir}/sbin/nginx fi } function install_lib() { # Remove links - ${csudo} rm -f ${lib_link_dir}/libtaos.* || : - ${csudo} rm -f ${lib64_link_dir}/libtaos.* || : - ${csudo} cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo} chmod 777 ${install_main_dir}/driver/* + ${csudo}rm -f ${lib_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : + ${csudo}cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo}chmod 777 ${install_main_dir}/driver/* - ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 - ${csudo} ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so + ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 + ${csudo}ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so if [[ -d ${lib64_link_dir} && ! -e ${lib64_link_dir}/libtaos.so ]]; then - ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 || : - ${csudo} ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || : + ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 || : + ${csudo}ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || : fi if [ "$osType" != "Darwin" ]; then - ${csudo} ldconfig + ${csudo}ldconfig else - ${csudo} update_dyld_shared_cache + ${csudo}update_dyld_shared_cache fi } function install_header() { - ${csudo} rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h || : - ${csudo} cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo} chmod 644 ${install_main_dir}/include/* - ${csudo} ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h - ${csudo} ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h - ${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h + ${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h || : + ${csudo}cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo}chmod 644 ${install_main_dir}/include/* + ${csudo}ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h + ${csudo}ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h + ${csudo}ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h } function install_jemalloc() { jemalloc_dir=${script_dir}/jemalloc if [ -d ${jemalloc_dir} ]; then - ${csudo} /usr/bin/install -c -d /usr/local/bin + ${csudo}/usr/bin/install -c -d /usr/local/bin if [ -f ${jemalloc_dir}/bin/jemalloc-config ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc-config /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc-config /usr/local/bin fi if [ -f ${jemalloc_dir}/bin/jemalloc.sh ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc.sh /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc.sh /usr/local/bin fi if [ -f ${jemalloc_dir}/bin/jeprof ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jeprof /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jeprof /usr/local/bin fi if [ -f ${jemalloc_dir}/include/jemalloc/jemalloc.h ]; then - ${csudo} /usr/bin/install -c -d /usr/local/include/jemalloc - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/include/jemalloc/jemalloc.h /usr/local/include/jemalloc + ${csudo}/usr/bin/install -c -d /usr/local/include/jemalloc + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/include/jemalloc/jemalloc.h /usr/local/include/jemalloc fi if [ -f ${jemalloc_dir}/lib/libjemalloc.so.2 ]; then - ${csudo} /usr/bin/install -c -d /usr/local/lib - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.so.2 /usr/local/lib - ${csudo} ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so - ${csudo} /usr/bin/install -c -d /usr/local/lib + ${csudo}/usr/bin/install -c -d /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.so.2 /usr/local/lib + ${csudo}ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so + ${csudo}/usr/bin/install -c -d /usr/local/lib if [ -f ${jemalloc_dir}/lib/libjemalloc.a ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.a /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.a /usr/local/lib fi if [ -f ${jemalloc_dir}/lib/libjemalloc_pic.a ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc_pic.a /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc_pic.a /usr/local/lib fi if [ -f ${jemalloc_dir}/lib/libjemalloc_pic.a ]; then - ${csudo} /usr/bin/install -c -d /usr/local/lib/pkgconfig - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/lib/pkgconfig/jemalloc.pc /usr/local/lib/pkgconfig + ${csudo}/usr/bin/install -c -d /usr/local/lib/pkgconfig + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/lib/pkgconfig/jemalloc.pc /usr/local/lib/pkgconfig fi fi if [ -f ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html ]; then - ${csudo} /usr/bin/install -c -d /usr/local/share/doc/jemalloc - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html /usr/local/share/doc/jemalloc + ${csudo}/usr/bin/install -c -d /usr/local/share/doc/jemalloc + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html /usr/local/share/doc/jemalloc fi if [ -f ${jemalloc_dir}/share/man/man3/jemalloc.3 ]; then - ${csudo} /usr/bin/install -c -d /usr/local/share/man/man3 - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/share/man/man3/jemalloc.3 /usr/local/share/man/man3 + ${csudo}/usr/bin/install -c -d /usr/local/share/man/man3 + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/share/man/man3/jemalloc.3 /usr/local/share/man/man3 fi if [ -d /etc/ld.so.conf.d ]; then - echo "/usr/local/lib" | ${csudo} tee /etc/ld.so.conf.d/jemalloc.conf > /dev/null || echo -e "failed to write /etc/ld.so.conf.d/jemalloc.conf" - ${csudo} ldconfig + echo "/usr/local/lib" | ${csudo}tee /etc/ld.so.conf.d/jemalloc.conf > /dev/null || echo -e "failed to write /etc/ld.so.conf.d/jemalloc.conf" + ${csudo}ldconfig else echo "/etc/ld.so.conf.d not found!" fi @@ -287,7 +287,7 @@ function add_newHostname_to_hosts() { return fi done - ${csudo} echo "127.0.0.1 $1" >> /etc/hosts ||: + ${csudo}echo "127.0.0.1 $1" >> /etc/hosts ||: } function set_hostname() { @@ -301,7 +301,7 @@ function set_hostname() { fi done - ${csudo} hostname $newHostname ||: + ${csudo}hostname $newHostname ||: retval=`echo $?` if [[ $retval != 0 ]]; then echo @@ -311,15 +311,15 @@ function set_hostname() { #ubuntu/centos /etc/hostname if [[ -e /etc/hostname ]]; then - ${csudo} echo $newHostname > /etc/hostname ||: + ${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 ||: + ${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}/prodb.cfg + ${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$newHostname/" ${cfg_install_dir}/prodb.cfg serverFqdn=$newHostname if [[ -e /etc/hosts ]]; then @@ -354,7 +354,7 @@ 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}/prodb.cfg + ${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${cfg_install_dir}/prodb.cfg serverFqdn=$localFqdn echo return @@ -376,7 +376,7 @@ function set_ipAsFqdn() { 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}/prodb.cfg + ${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${cfg_install_dir}/prodb.cfg serverFqdn=$localFqdn break fi @@ -424,13 +424,13 @@ function local_fqdn_check() { function install_config() { if [ ! -f ${cfg_install_dir}/prodb.cfg ]; then - ${csudo} mkdir -p ${cfg_install_dir} - [ -f ${script_dir}/cfg/prodb.cfg ] && ${csudo} cp ${script_dir}/cfg/prodb.cfg ${cfg_install_dir} - ${csudo} chmod 644 ${cfg_install_dir}/* + ${csudo}mkdir -p ${cfg_install_dir} + [ -f ${script_dir}/cfg/prodb.cfg ] && ${csudo}cp ${script_dir}/cfg/prodb.cfg ${cfg_install_dir} + ${csudo}chmod 644 ${cfg_install_dir}/* fi - ${csudo} cp -f ${script_dir}/cfg/prodb.cfg ${install_main_dir}/cfg/prodb.cfg.org - ${csudo} ln -s ${cfg_install_dir}/prodb.cfg ${install_main_dir}/cfg + ${csudo}cp -f ${script_dir}/cfg/prodb.cfg ${install_main_dir}/cfg/prodb.cfg.org + ${csudo}ln -s ${cfg_install_dir}/prodb.cfg ${install_main_dir}/cfg [ ! -z $1 ] && return 0 || : # only install client @@ -460,7 +460,7 @@ function install_config() { # check the format of the firstEp #if [[ $firstEp == $FQDN_PATTERN ]]; then # Write the first FQDN to configuration file - ${csudo} sed -i -r "s/#*\s*(firstEp\s*).*/\1$firstEp/" ${cfg_install_dir}/prodb.cfg + ${csudo}sed -i -r "s/#*\s*(firstEp\s*).*/\1$firstEp/" ${cfg_install_dir}/prodb.cfg break #else # read -p "Please enter the correct FQDN:port: " firstEp @@ -473,66 +473,66 @@ function install_config() { function install_log() { - ${csudo} rm -rf ${log_dir} || : - ${csudo} mkdir -p ${log_dir} && ${csudo} chmod 777 ${log_dir} + ${csudo}rm -rf ${log_dir} || : + ${csudo}mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir} - ${csudo} ln -s ${log_dir} ${install_main_dir}/log + ${csudo}ln -s ${log_dir} ${install_main_dir}/log } function install_data() { - ${csudo} mkdir -p ${data_dir} + ${csudo}mkdir -p ${data_dir} - ${csudo} ln -s ${data_dir} ${install_main_dir}/data + ${csudo}ln -s ${data_dir} ${install_main_dir}/data } function install_connector() { - ${csudo} cp -rf ${script_dir}/connector/* ${install_main_dir}/connector + ${csudo}cp -rf ${script_dir}/connector/* ${install_main_dir}/connector } function install_examples() { if [ -d ${script_dir}/examples ]; then - ${csudo} cp -rf ${script_dir}/examples/* ${install_main_dir}/examples + ${csudo}cp -rf ${script_dir}/examples/* ${install_main_dir}/examples fi } function clean_service_on_sysvinit() { if pidof prodbs &> /dev/null; then - ${csudo} service prodbs stop || : + ${csudo}service prodbs stop || : fi if pidof tarbitrator &> /dev/null; then - ${csudo} service tarbitratord stop || : + ${csudo}service tarbitratord stop || : fi if ((${initd_mod}==1)); then if [ -e ${service_config_dir}/prodbs ]; then - ${csudo} chkconfig --del prodbs || : + ${csudo}chkconfig --del prodbs || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} chkconfig --del tarbitratord || : + ${csudo}chkconfig --del tarbitratord || : fi elif ((${initd_mod}==2)); then if [ -e ${service_config_dir}/prodbs ]; then - ${csudo} insserv -r prodbs || : + ${csudo}insserv -r prodbs || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} insserv -r tarbitratord || : + ${csudo}insserv -r tarbitratord || : fi elif ((${initd_mod}==3)); then if [ -e ${service_config_dir}/prodbs ]; then - ${csudo} update-rc.d -f prodbs remove || : + ${csudo}update-rc.d -f prodbs remove || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} update-rc.d -f tarbitratord remove || : + ${csudo}update-rc.d -f tarbitratord remove || : fi fi - ${csudo} rm -f ${service_config_dir}/prodbs || : - ${csudo} rm -f ${service_config_dir}/tarbitratord || : + ${csudo}rm -f ${service_config_dir}/prodbs || : + ${csudo}rm -f ${service_config_dir}/tarbitratord || : if $(which init &> /dev/null); then - ${csudo} init q || : + ${csudo}init q || : fi } @@ -543,30 +543,30 @@ function install_service_on_sysvinit() { # Install prodbs service if ((${os_type}==1)); then - ${csudo} cp -f ${script_dir}/init.d/prodbs.deb ${install_main_dir}/init.d/prodbs - ${csudo} cp ${script_dir}/init.d/prodbs.deb ${service_config_dir}/prodbs && ${csudo} chmod a+x ${service_config_dir}/prodbs - ${csudo} cp -f ${script_dir}/init.d/tarbitratord.deb ${install_main_dir}/init.d/tarbitratord - ${csudo} cp ${script_dir}/init.d/tarbitratord.deb ${service_config_dir}/tarbitratord && ${csudo} chmod a+x ${service_config_dir}/tarbitratord + ${csudo}cp -f ${script_dir}/init.d/prodbs.deb ${install_main_dir}/init.d/prodbs + ${csudo}cp ${script_dir}/init.d/prodbs.deb ${service_config_dir}/prodbs && ${csudo}chmod a+x ${service_config_dir}/prodbs + ${csudo}cp -f ${script_dir}/init.d/tarbitratord.deb ${install_main_dir}/init.d/tarbitratord + ${csudo}cp ${script_dir}/init.d/tarbitratord.deb ${service_config_dir}/tarbitratord && ${csudo}chmod a+x ${service_config_dir}/tarbitratord elif ((${os_type}==2)); then - ${csudo} cp -f ${script_dir}/init.d/prodbs.rpm ${install_main_dir}/init.d/prodbs - ${csudo} cp ${script_dir}/init.d/prodbs.rpm ${service_config_dir}/prodbs && ${csudo} chmod a+x ${service_config_dir}/prodbs - ${csudo} cp -f ${script_dir}/init.d/tarbitratord.rpm ${install_main_dir}/init.d/tarbitratord - ${csudo} cp ${script_dir}/init.d/tarbitratord.rpm ${service_config_dir}/tarbitratord && ${csudo} chmod a+x ${service_config_dir}/tarbitratord + ${csudo}cp -f ${script_dir}/init.d/prodbs.rpm ${install_main_dir}/init.d/prodbs + ${csudo}cp ${script_dir}/init.d/prodbs.rpm ${service_config_dir}/prodbs && ${csudo}chmod a+x ${service_config_dir}/prodbs + ${csudo}cp -f ${script_dir}/init.d/tarbitratord.rpm ${install_main_dir}/init.d/tarbitratord + ${csudo}cp ${script_dir}/init.d/tarbitratord.rpm ${service_config_dir}/tarbitratord && ${csudo}chmod a+x ${service_config_dir}/tarbitratord fi if ((${initd_mod}==1)); then - ${csudo} chkconfig --add prodbs || : - ${csudo} chkconfig --level 2345 prodbs on || : - ${csudo} chkconfig --add tarbitratord || : - ${csudo} chkconfig --level 2345 tarbitratord on || : + ${csudo}chkconfig --add prodbs || : + ${csudo}chkconfig --level 2345 prodbs on || : + ${csudo}chkconfig --add tarbitratord || : + ${csudo}chkconfig --level 2345 tarbitratord on || : elif ((${initd_mod}==2)); then - ${csudo} insserv prodbs || : - ${csudo} insserv -d prodbs || : - ${csudo} insserv tarbitratord || : - ${csudo} insserv -d tarbitratord || : + ${csudo}insserv prodbs || : + ${csudo}insserv -d prodbs || : + ${csudo}insserv tarbitratord || : + ${csudo}insserv -d tarbitratord || : elif ((${initd_mod}==3)); then - ${csudo} update-rc.d prodbs defaults || : - ${csudo} update-rc.d tarbitratord defaults || : + ${csudo}update-rc.d prodbs defaults || : + ${csudo}update-rc.d tarbitratord defaults || : fi } @@ -574,27 +574,27 @@ function clean_service_on_systemd() { prodbs_service_config="${service_config_dir}/prodbs.service" if systemctl is-active --quiet prodbs; then echo "ProDB is running, stopping it..." - ${csudo} systemctl stop prodbs &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop prodbs &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable prodbs &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${prodbs_service_config} + ${csudo}systemctl disable prodbs &> /dev/null || echo &> /dev/null + ${csudo}rm -f ${prodbs_service_config} tarbitratord_service_config="${service_config_dir}/tarbitratord.service" if systemctl is-active --quiet tarbitratord; then echo "tarbitrator is running, stopping it..." - ${csudo} systemctl stop tarbitratord &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop tarbitratord &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable tarbitratord &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${tarbitratord_service_config} + ${csudo}systemctl disable tarbitratord &> /dev/null || echo &> /dev/null + ${csudo}rm -f ${tarbitratord_service_config} if [ "$verMode" == "cluster" ]; then nginx_service_config="${service_config_dir}/nginxd.service" if systemctl is-active --quiet nginxd; then echo "Nginx for ProDB is running, stopping it..." - ${csudo} systemctl stop nginxd &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop nginxd &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable nginxd &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${nginx_service_config} + ${csudo}systemctl disable nginxd &> /dev/null || echo &> /dev/null + ${csudo}rm -f ${nginx_service_config} fi } @@ -602,81 +602,81 @@ function install_service_on_systemd() { clean_service_on_systemd prodbs_service_config="${service_config_dir}/prodbs.service" - ${csudo} bash -c "echo '[Unit]' >> ${prodbs_service_config}" - ${csudo} bash -c "echo 'Description=ProDB server service' >> ${prodbs_service_config}" - ${csudo} bash -c "echo 'After=network-online.target' >> ${prodbs_service_config}" - ${csudo} bash -c "echo 'Wants=network-online.target' >> ${prodbs_service_config}" - ${csudo} bash -c "echo >> ${prodbs_service_config}" - ${csudo} bash -c "echo '[Service]' >> ${prodbs_service_config}" - ${csudo} bash -c "echo 'Type=simple' >> ${prodbs_service_config}" - ${csudo} bash -c "echo 'ExecStart=/usr/bin/prodbs' >> ${prodbs_service_config}" - ${csudo} bash -c "echo 'ExecStartPre=/usr/local/ProDB/bin/startPre.sh' >> ${prodbs_service_config}" - ${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${prodbs_service_config}" - ${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${prodbs_service_config}" - ${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${prodbs_service_config}" - ${csudo} bash -c "echo 'LimitCORE=infinity' >> ${prodbs_service_config}" - ${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${prodbs_service_config}" - ${csudo} bash -c "echo 'StandardOutput=null' >> ${prodbs_service_config}" - ${csudo} bash -c "echo 'Restart=always' >> ${prodbs_service_config}" - ${csudo} bash -c "echo 'StartLimitBurst=3' >> ${prodbs_service_config}" - ${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${prodbs_service_config}" - ${csudo} bash -c "echo >> ${prodbs_service_config}" - ${csudo} bash -c "echo '[Install]' >> ${prodbs_service_config}" - ${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${prodbs_service_config}" - ${csudo} systemctl enable prodbs + ${csudo}bash -c "echo '[Unit]' >> ${prodbs_service_config}" + ${csudo}bash -c "echo 'Description=ProDB server service' >> ${prodbs_service_config}" + ${csudo}bash -c "echo 'After=network-online.target' >> ${prodbs_service_config}" + ${csudo}bash -c "echo 'Wants=network-online.target' >> ${prodbs_service_config}" + ${csudo}bash -c "echo >> ${prodbs_service_config}" + ${csudo}bash -c "echo '[Service]' >> ${prodbs_service_config}" + ${csudo}bash -c "echo 'Type=simple' >> ${prodbs_service_config}" + ${csudo}bash -c "echo 'ExecStart=/usr/bin/prodbs' >> ${prodbs_service_config}" + ${csudo}bash -c "echo 'ExecStartPre=/usr/local/ProDB/bin/startPre.sh' >> ${prodbs_service_config}" + ${csudo}bash -c "echo 'TimeoutStopSec=1000000s' >> ${prodbs_service_config}" + ${csudo}bash -c "echo 'LimitNOFILE=infinity' >> ${prodbs_service_config}" + ${csudo}bash -c "echo 'LimitNPROC=infinity' >> ${prodbs_service_config}" + ${csudo}bash -c "echo 'LimitCORE=infinity' >> ${prodbs_service_config}" + ${csudo}bash -c "echo 'TimeoutStartSec=0' >> ${prodbs_service_config}" + ${csudo}bash -c "echo 'StandardOutput=null' >> ${prodbs_service_config}" + ${csudo}bash -c "echo 'Restart=always' >> ${prodbs_service_config}" + ${csudo}bash -c "echo 'StartLimitBurst=3' >> ${prodbs_service_config}" + ${csudo}bash -c "echo 'StartLimitInterval=60s' >> ${prodbs_service_config}" + ${csudo}bash -c "echo >> ${prodbs_service_config}" + ${csudo}bash -c "echo '[Install]' >> ${prodbs_service_config}" + ${csudo}bash -c "echo 'WantedBy=multi-user.target' >> ${prodbs_service_config}" + ${csudo}systemctl enable prodbs tarbitratord_service_config="${service_config_dir}/tarbitratord.service" - ${csudo} bash -c "echo '[Unit]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Description=ProDB arbitrator service' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'After=network-online.target' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Wants=network-online.target' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo '[Service]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Type=simple' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'ExecStart=/usr/bin/tarbitrator' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitCORE=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StandardOutput=null' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Restart=always' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StartLimitBurst=3' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo '[Install]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${tarbitratord_service_config}" - #${csudo} systemctl enable tarbitratord + ${csudo}bash -c "echo '[Unit]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Description=ProDB arbitrator service' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'After=network-online.target' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Wants=network-online.target' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo '[Service]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Type=simple' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'ExecStart=/usr/bin/tarbitrator' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'TimeoutStopSec=1000000s' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitNOFILE=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitNPROC=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitCORE=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'TimeoutStartSec=0' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StandardOutput=null' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Restart=always' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StartLimitBurst=3' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StartLimitInterval=60s' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo '[Install]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'WantedBy=multi-user.target' >> ${tarbitratord_service_config}" + #${csudo}systemctl enable tarbitratord if [ "$verMode" == "cluster" ]; then nginx_service_config="${service_config_dir}/nginxd.service" - ${csudo} bash -c "echo '[Unit]' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'Description=Nginx For PowrDB Service' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'After=network-online.target' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'Wants=network-online.target' >> ${nginx_service_config}" - ${csudo} bash -c "echo >> ${nginx_service_config}" - ${csudo} bash -c "echo '[Service]' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'Type=forking' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'PIDFile=/usr/local/nginxd/logs/nginx.pid' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'ExecStart=/usr/local/nginxd/sbin/nginx' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'ExecStop=/usr/local/nginxd/sbin/nginx -s stop' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'LimitCORE=infinity' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'StandardOutput=null' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'Restart=always' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'StartLimitBurst=3' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${nginx_service_config}" - ${csudo} bash -c "echo >> ${nginx_service_config}" - ${csudo} bash -c "echo '[Install]' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${nginx_service_config}" - if ! ${csudo} systemctl enable nginxd &> /dev/null; then - ${csudo} systemctl daemon-reexec - ${csudo} systemctl enable nginxd + ${csudo}bash -c "echo '[Unit]' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'Description=Nginx For PowrDB Service' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'After=network-online.target' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'Wants=network-online.target' >> ${nginx_service_config}" + ${csudo}bash -c "echo >> ${nginx_service_config}" + ${csudo}bash -c "echo '[Service]' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'Type=forking' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'PIDFile=/usr/local/nginxd/logs/nginx.pid' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'ExecStart=/usr/local/nginxd/sbin/nginx' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'ExecStop=/usr/local/nginxd/sbin/nginx -s stop' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'TimeoutStopSec=1000000s' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'LimitNOFILE=infinity' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'LimitNPROC=infinity' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'LimitCORE=infinity' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'TimeoutStartSec=0' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'StandardOutput=null' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'Restart=always' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'StartLimitBurst=3' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'StartLimitInterval=60s' >> ${nginx_service_config}" + ${csudo}bash -c "echo >> ${nginx_service_config}" + ${csudo}bash -c "echo '[Install]' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'WantedBy=multi-user.target' >> ${nginx_service_config}" + if ! ${csudo}systemctl enable nginxd &> /dev/null; then + ${csudo}systemctl daemon-reexec + ${csudo}systemctl enable nginxd fi - ${csudo} systemctl start nginxd + ${csudo}systemctl start nginxd fi } @@ -756,9 +756,9 @@ function update_prodb() { # Stop the service if running if pidof prodbs &> /dev/null; then if ((${service_mod}==0)); then - ${csudo} systemctl stop prodbs || : + ${csudo}systemctl stop prodbs || : elif ((${service_mod}==1)); then - ${csudo} service prodbs stop || : + ${csudo}service prodbs stop || : else kill_process prodbs fi @@ -767,9 +767,9 @@ function update_prodb() { if [ "$verMode" == "cluster" ]; then if pidof nginx &> /dev/null; then if ((${service_mod}==0)); then - ${csudo} systemctl stop nginxd || : + ${csudo}systemctl stop nginxd || : elif ((${service_mod}==1)); then - ${csudo} service nginxd stop || : + ${csudo}service nginxd stop || : else kill_process nginx fi @@ -810,9 +810,9 @@ function update_prodb() { echo echo -e "${GREEN_DARK}To configure ProDB ${NC}: edit /etc/ProDB/prodb.cfg" if ((${service_mod}==0)); then - echo -e "${GREEN_DARK}To start ProDB ${NC}: ${csudo} systemctl start prodbs${NC}" + echo -e "${GREEN_DARK}To start ProDB ${NC}: ${csudo}systemctl start prodbs${NC}" elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start ProDB ${NC}: ${csudo} service prodbs start${NC}" + echo -e "${GREEN_DARK}To start ProDB ${NC}: ${csudo}service prodbs start${NC}" else echo -e "${GREEN_DARK}To start ProDB ${NC}: ./prodbs${NC}" fi @@ -887,9 +887,9 @@ function install_prodb() { echo echo -e "${GREEN_DARK}To configure ProDB ${NC}: edit /etc/ProDB/prodb.cfg" if ((${service_mod}==0)); then - echo -e "${GREEN_DARK}To start ProDB ${NC}: ${csudo} systemctl start prodbs${NC}" + echo -e "${GREEN_DARK}To start ProDB ${NC}: ${csudo}systemctl start prodbs${NC}" elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start ProDB ${NC}: ${csudo} service prodbs start${NC}" + echo -e "${GREEN_DARK}To start ProDB ${NC}: ${csudo}service prodbs start${NC}" else echo -e "${GREEN_DARK}To start ProDB ${NC}: prodbs${NC}" fi diff --git a/packaging/tools/install_tq.sh b/packaging/tools/install_tq.sh index 481cbb19792b654710aab13d99c50ab4b5475be1..e74d5c7c4576f96608bc8a727b97aa84b9626817 100755 --- a/packaging/tools/install_tq.sh +++ b/packaging/tools/install_tq.sh @@ -49,7 +49,7 @@ NC='\033[0m' csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi update_flag=0 @@ -149,127 +149,127 @@ done function kill_process() { pid=$(ps -ef | grep "$1" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function install_main_path() { #create install main dir and all sub dir - ${csudo} rm -rf ${install_main_dir} || : - ${csudo} mkdir -p ${install_main_dir} - ${csudo} mkdir -p ${install_main_dir}/cfg - ${csudo} mkdir -p ${install_main_dir}/bin - ${csudo} mkdir -p ${install_main_dir}/connector - ${csudo} mkdir -p ${install_main_dir}/driver - ${csudo} mkdir -p ${install_main_dir}/examples - ${csudo} mkdir -p ${install_main_dir}/include - ${csudo} mkdir -p ${install_main_dir}/init.d + ${csudo}rm -rf ${install_main_dir} || : + ${csudo}mkdir -p ${install_main_dir} + ${csudo}mkdir -p ${install_main_dir}/cfg + ${csudo}mkdir -p ${install_main_dir}/bin + ${csudo}mkdir -p ${install_main_dir}/connector + ${csudo}mkdir -p ${install_main_dir}/driver + ${csudo}mkdir -p ${install_main_dir}/examples + ${csudo}mkdir -p ${install_main_dir}/include + ${csudo}mkdir -p ${install_main_dir}/init.d if [ "$verMode" == "cluster" ]; then - ${csudo} mkdir -p ${nginx_dir} + ${csudo}mkdir -p ${nginx_dir} fi } function install_bin() { # Remove links - ${csudo} rm -f ${bin_link_dir}/tq || : - ${csudo} rm -f ${bin_link_dir}/tqd || : - ${csudo} rm -f ${bin_link_dir}/tqdemo || : - ${csudo} rm -f ${bin_link_dir}/rmtq || : - ${csudo} rm -f ${bin_link_dir}/tarbitrator || : - ${csudo} rm -f ${bin_link_dir}/set_core || : - ${csudo} rm -f ${bin_link_dir}/run_taosd.sh || : + ${csudo}rm -f ${bin_link_dir}/tq || : + ${csudo}rm -f ${bin_link_dir}/tqd || : + ${csudo}rm -f ${bin_link_dir}/tqdemo || : + ${csudo}rm -f ${bin_link_dir}/rmtq || : + ${csudo}rm -f ${bin_link_dir}/tarbitrator || : + ${csudo}rm -f ${bin_link_dir}/set_core || : + ${csudo}rm -f ${bin_link_dir}/run_taosd.sh || : - ${csudo} cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo} chmod 0555 ${install_main_dir}/bin/* + ${csudo}cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo}chmod 0555 ${install_main_dir}/bin/* #Make link - [ -x ${install_main_dir}/bin/tq ] && ${csudo} ln -s ${install_main_dir}/bin/tq ${bin_link_dir}/tq || : - [ -x ${install_main_dir}/bin/tqd ] && ${csudo} ln -s ${install_main_dir}/bin/tqd ${bin_link_dir}/tqd || : - [ -x ${install_main_dir}/bin/tqdemo ] && ${csudo} ln -s ${install_main_dir}/bin/tqdemo ${bin_link_dir}/tqdemo || : - [ -x ${install_main_dir}/bin/remove_tq.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove_tq.sh ${bin_link_dir}/rmtq || : - [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo} ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : - [ -x ${install_main_dir}/bin/run_taosd.sh ] && ${csudo} ln -s ${install_main_dir}/bin/run_taosd.sh ${bin_link_dir}/run_taosd.sh || : - [ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo} ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || : + [ -x ${install_main_dir}/bin/tq ] && ${csudo}ln -s ${install_main_dir}/bin/tq ${bin_link_dir}/tq || : + [ -x ${install_main_dir}/bin/tqd ] && ${csudo}ln -s ${install_main_dir}/bin/tqd ${bin_link_dir}/tqd || : + [ -x ${install_main_dir}/bin/tqdemo ] && ${csudo}ln -s ${install_main_dir}/bin/tqdemo ${bin_link_dir}/tqdemo || : + [ -x ${install_main_dir}/bin/remove_tq.sh ] && ${csudo}ln -s ${install_main_dir}/bin/remove_tq.sh ${bin_link_dir}/rmtq || : + [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo}ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : + [ -x ${install_main_dir}/bin/run_taosd.sh ] && ${csudo}ln -s ${install_main_dir}/bin/run_taosd.sh ${bin_link_dir}/run_taosd.sh || : + [ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo}ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || : if [ "$verMode" == "cluster" ]; then - ${csudo} cp -r ${script_dir}/nginxd/* ${nginx_dir} && ${csudo} chmod 0555 ${nginx_dir}/* - ${csudo} mkdir -p ${nginx_dir}/logs - ${csudo} chmod 777 ${nginx_dir}/sbin/nginx + ${csudo}cp -r ${script_dir}/nginxd/* ${nginx_dir} && ${csudo}chmod 0555 ${nginx_dir}/* + ${csudo}mkdir -p ${nginx_dir}/logs + ${csudo}chmod 777 ${nginx_dir}/sbin/nginx fi } function install_lib() { # Remove links - ${csudo} rm -f ${lib_link_dir}/libtaos.* || : - ${csudo} rm -f ${lib64_link_dir}/libtaos.* || : - #${csudo} rm -rf ${v15_java_app_dir} || : - ${csudo} cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo} chmod 777 ${install_main_dir}/driver/* + ${csudo}rm -f ${lib_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : + #${csudo}rm -rf ${v15_java_app_dir} || : + ${csudo}cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo}chmod 777 ${install_main_dir}/driver/* - ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 - ${csudo} ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so + ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 + ${csudo}ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so if [[ -d ${lib64_link_dir} && ! -e ${lib64_link_dir}/libtaos.so ]]; then - ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 || : - ${csudo} ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || : + ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 || : + ${csudo}ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || : fi - ${csudo} ldconfig + ${csudo}ldconfig } function install_header() { - ${csudo} rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h || : - ${csudo} cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo} chmod 644 ${install_main_dir}/include/* - ${csudo} ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h - ${csudo} ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h - ${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h + ${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h || : + ${csudo}cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo}chmod 644 ${install_main_dir}/include/* + ${csudo}ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h + ${csudo}ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h + ${csudo}ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h } function install_jemalloc() { jemalloc_dir=${script_dir}/jemalloc if [ -d ${jemalloc_dir} ]; then - ${csudo} /usr/bin/install -c -d /usr/local/bin + ${csudo}/usr/bin/install -c -d /usr/local/bin if [ -f ${jemalloc_dir}/bin/jemalloc-config ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc-config /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc-config /usr/local/bin fi if [ -f ${jemalloc_dir}/bin/jemalloc.sh ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc.sh /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc.sh /usr/local/bin fi if [ -f ${jemalloc_dir}/bin/jeprof ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jeprof /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jeprof /usr/local/bin fi if [ -f ${jemalloc_dir}/include/jemalloc/jemalloc.h ]; then - ${csudo} /usr/bin/install -c -d /usr/local/include/jemalloc - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/include/jemalloc/jemalloc.h /usr/local/include/jemalloc + ${csudo}/usr/bin/install -c -d /usr/local/include/jemalloc + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/include/jemalloc/jemalloc.h /usr/local/include/jemalloc fi if [ -f ${jemalloc_dir}/lib/libjemalloc.so.2 ]; then - ${csudo} /usr/bin/install -c -d /usr/local/lib - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.so.2 /usr/local/lib - ${csudo} ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so - ${csudo} /usr/bin/install -c -d /usr/local/lib + ${csudo}/usr/bin/install -c -d /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.so.2 /usr/local/lib + ${csudo}ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so + ${csudo}/usr/bin/install -c -d /usr/local/lib if [ -f ${jemalloc_dir}/lib/libjemalloc.a ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.a /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.a /usr/local/lib fi if [ -f ${jemalloc_dir}/lib/libjemalloc_pic.a ]; then - ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc_pic.a /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc_pic.a /usr/local/lib fi if [ -f ${jemalloc_dir}/lib/libjemalloc_pic.a ]; then - ${csudo} /usr/bin/install -c -d /usr/local/lib/pkgconfig - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/lib/pkgconfig/jemalloc.pc /usr/local/lib/pkgconfig + ${csudo}/usr/bin/install -c -d /usr/local/lib/pkgconfig + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/lib/pkgconfig/jemalloc.pc /usr/local/lib/pkgconfig fi fi if [ -f ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html ]; then - ${csudo} /usr/bin/install -c -d /usr/local/share/doc/jemalloc - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html /usr/local/share/doc/jemalloc + ${csudo}/usr/bin/install -c -d /usr/local/share/doc/jemalloc + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html /usr/local/share/doc/jemalloc fi if [ -f ${jemalloc_dir}/share/man/man3/jemalloc.3 ]; then - ${csudo} /usr/bin/install -c -d /usr/local/share/man/man3 - ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/share/man/man3/jemalloc.3 /usr/local/share/man/man3 + ${csudo}/usr/bin/install -c -d /usr/local/share/man/man3 + ${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/share/man/man3/jemalloc.3 /usr/local/share/man/man3 fi if [ -d /etc/ld.so.conf.d ]; then - echo "/usr/local/lib" | ${csudo} tee /etc/ld.so.conf.d/jemalloc.conf > /dev/null || echo -e "failed to write ld.so.conf.d/jemalloc.conf" - ${csudo} ldconfig + echo "/usr/local/lib" | ${csudo}tee /etc/ld.so.conf.d/jemalloc.conf > /dev/null || echo -e "failed to write ld.so.conf.d/jemalloc.conf" + ${csudo}ldconfig else echo "/etc/ld.so.conf.d not found!" fi @@ -289,7 +289,7 @@ function add_newHostname_to_hosts() { return fi done - ${csudo} echo "127.0.0.1 $1" >> /etc/hosts ||: + ${csudo}echo "127.0.0.1 $1" >> /etc/hosts ||: } function set_hostname() { @@ -303,7 +303,7 @@ function set_hostname() { fi done - ${csudo} hostname $newHostname ||: + ${csudo}hostname $newHostname ||: retval=`echo $?` if [[ $retval != 0 ]]; then echo @@ -316,15 +316,15 @@ function set_hostname() { #ubuntu/centos /etc/hostname if [[ -e /etc/hostname ]]; then - ${csudo} echo $newHostname > /etc/hostname ||: + ${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 ||: + ${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}/tq.cfg + ${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$newHostname/" ${cfg_install_dir}/tq.cfg serverFqdn=$newHostname if [[ -e /etc/hosts ]]; then @@ -359,7 +359,7 @@ 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}/tq.cfg + ${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${cfg_install_dir}/tq.cfg serverFqdn=$localFqdn echo return @@ -381,7 +381,7 @@ function set_ipAsFqdn() { 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}/tq.cfg + ${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${cfg_install_dir}/tq.cfg serverFqdn=$localFqdn break fi @@ -429,13 +429,13 @@ function local_fqdn_check() { function install_config() { if [ ! -f ${cfg_install_dir}/tq.cfg ]; then - ${csudo} mkdir -p ${cfg_install_dir} - [ -f ${script_dir}/cfg/tq.cfg ] && ${csudo} cp ${script_dir}/cfg/tq.cfg ${cfg_install_dir} - ${csudo} chmod 644 ${cfg_install_dir}/* + ${csudo}mkdir -p ${cfg_install_dir} + [ -f ${script_dir}/cfg/tq.cfg ] && ${csudo}cp ${script_dir}/cfg/tq.cfg ${cfg_install_dir} + ${csudo}chmod 644 ${cfg_install_dir}/* fi - ${csudo} cp -f ${script_dir}/cfg/tq.cfg ${install_main_dir}/cfg/tq.cfg.org - ${csudo} ln -s ${cfg_install_dir}/tq.cfg ${install_main_dir}/cfg + ${csudo}cp -f ${script_dir}/cfg/tq.cfg ${install_main_dir}/cfg/tq.cfg.org + ${csudo}ln -s ${cfg_install_dir}/tq.cfg ${install_main_dir}/cfg [ ! -z $1 ] && return 0 || : # only install client @@ -465,7 +465,7 @@ function install_config() { # check the format of the firstEp #if [[ $firstEp == $FQDN_PATTERN ]]; then # Write the first FQDN to configuration file - ${csudo} sed -i -r "s/#*\s*(firstEp\s*).*/\1$firstEp/" ${cfg_install_dir}/tq.cfg + ${csudo}sed -i -r "s/#*\s*(firstEp\s*).*/\1$firstEp/" ${cfg_install_dir}/tq.cfg break #else # read -p "Please enter the correct FQDN:port: " firstEp @@ -478,69 +478,69 @@ function install_config() { function install_log() { - ${csudo} rm -rf ${log_dir} || : - ${csudo} mkdir -p ${log_dir} && ${csudo} chmod 777 ${log_dir} + ${csudo}rm -rf ${log_dir} || : + ${csudo}mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir} - ${csudo} ln -s ${log_dir} ${install_main_dir}/log + ${csudo}ln -s ${log_dir} ${install_main_dir}/log } function install_data() { - ${csudo} mkdir -p ${data_dir} + ${csudo}mkdir -p ${data_dir} - ${csudo} ln -s ${data_dir} ${install_main_dir}/data + ${csudo}ln -s ${data_dir} ${install_main_dir}/data } function install_connector() { - ${csudo} cp -rf ${script_dir}/connector/* ${install_main_dir}/connector + ${csudo}cp -rf ${script_dir}/connector/* ${install_main_dir}/connector } function install_examples() { if [ -d ${script_dir}/examples ]; then - ${csudo} cp -rf ${script_dir}/examples/* ${install_main_dir}/examples + ${csudo}cp -rf ${script_dir}/examples/* ${install_main_dir}/examples fi } function clean_service_on_sysvinit() { #restart_config_str="tq:2345:respawn:${service_config_dir}/tqd start" - #${csudo} sed -i "\|${restart_config_str}|d" /etc/inittab || : + #${csudo}sed -i "\|${restart_config_str}|d" /etc/inittab || : if pidof tqd &> /dev/null; then - ${csudo} service tqd stop || : + ${csudo}service tqd stop || : fi if pidof tarbitrator &> /dev/null; then - ${csudo} service tarbitratord stop || : + ${csudo}service tarbitratord stop || : fi if ((${initd_mod}==1)); then if [ -e ${service_config_dir}/tqd ]; then - ${csudo} chkconfig --del tqd || : + ${csudo}chkconfig --del tqd || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} chkconfig --del tarbitratord || : + ${csudo}chkconfig --del tarbitratord || : fi elif ((${initd_mod}==2)); then if [ -e ${service_config_dir}/tqd ]; then - ${csudo} insserv -r tqd || : + ${csudo}insserv -r tqd || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} insserv -r tarbitratord || : + ${csudo}insserv -r tarbitratord || : fi elif ((${initd_mod}==3)); then if [ -e ${service_config_dir}/tqd ]; then - ${csudo} update-rc.d -f tqd remove || : + ${csudo}update-rc.d -f tqd remove || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} update-rc.d -f tarbitratord remove || : + ${csudo}update-rc.d -f tarbitratord remove || : fi fi - ${csudo} rm -f ${service_config_dir}/tqd || : - ${csudo} rm -f ${service_config_dir}/tarbitratord || : + ${csudo}rm -f ${service_config_dir}/tqd || : + ${csudo}rm -f ${service_config_dir}/tarbitratord || : if $(which init &> /dev/null); then - ${csudo} init q || : + ${csudo}init q || : fi } @@ -551,33 +551,33 @@ function install_service_on_sysvinit() { # Install tqd service if ((${os_type}==1)); then - ${csudo} cp -f ${script_dir}/init.d/tqd.deb ${install_main_dir}/init.d/tqd - ${csudo} cp ${script_dir}/init.d/tqd.deb ${service_config_dir}/tqd && ${csudo} chmod a+x ${service_config_dir}/tqd - ${csudo} cp -f ${script_dir}/init.d/tarbitratord.deb ${install_main_dir}/init.d/tarbitratord - ${csudo} cp ${script_dir}/init.d/tarbitratord.deb ${service_config_dir}/tarbitratord && ${csudo} chmod a+x ${service_config_dir}/tarbitratord + ${csudo}cp -f ${script_dir}/init.d/tqd.deb ${install_main_dir}/init.d/tqd + ${csudo}cp ${script_dir}/init.d/tqd.deb ${service_config_dir}/tqd && ${csudo}chmod a+x ${service_config_dir}/tqd + ${csudo}cp -f ${script_dir}/init.d/tarbitratord.deb ${install_main_dir}/init.d/tarbitratord + ${csudo}cp ${script_dir}/init.d/tarbitratord.deb ${service_config_dir}/tarbitratord && ${csudo}chmod a+x ${service_config_dir}/tarbitratord elif ((${os_type}==2)); then - ${csudo} cp -f ${script_dir}/init.d/tqd.rpm ${install_main_dir}/init.d/tqd - ${csudo} cp ${script_dir}/init.d/tqd.rpm ${service_config_dir}/tqd && ${csudo} chmod a+x ${service_config_dir}/tqd - ${csudo} cp -f ${script_dir}/init.d/tarbitratord.rpm ${install_main_dir}/init.d/tarbitratord - ${csudo} cp ${script_dir}/init.d/tarbitratord.rpm ${service_config_dir}/tarbitratord && ${csudo} chmod a+x ${service_config_dir}/tarbitratord + ${csudo}cp -f ${script_dir}/init.d/tqd.rpm ${install_main_dir}/init.d/tqd + ${csudo}cp ${script_dir}/init.d/tqd.rpm ${service_config_dir}/tqd && ${csudo}chmod a+x ${service_config_dir}/tqd + ${csudo}cp -f ${script_dir}/init.d/tarbitratord.rpm ${install_main_dir}/init.d/tarbitratord + ${csudo}cp ${script_dir}/init.d/tarbitratord.rpm ${service_config_dir}/tarbitratord && ${csudo}chmod a+x ${service_config_dir}/tarbitratord fi #restart_config_str="tq:2345:respawn:${service_config_dir}/tqd start" - #${csudo} grep -q -F "$restart_config_str" /etc/inittab || ${csudo} bash -c "echo '${restart_config_str}' >> /etc/inittab" + #${csudo}grep -q -F "$restart_config_str" /etc/inittab || ${csudo}bash -c "echo '${restart_config_str}' >> /etc/inittab" if ((${initd_mod}==1)); then - ${csudo} chkconfig --add tqd || : - ${csudo} chkconfig --level 2345 tqd on || : - ${csudo} chkconfig --add tarbitratord || : - ${csudo} chkconfig --level 2345 tarbitratord on || : + ${csudo}chkconfig --add tqd || : + ${csudo}chkconfig --level 2345 tqd on || : + ${csudo}chkconfig --add tarbitratord || : + ${csudo}chkconfig --level 2345 tarbitratord on || : elif ((${initd_mod}==2)); then - ${csudo} insserv tqd || : - ${csudo} insserv -d tqd || : - ${csudo} insserv tarbitratord || : - ${csudo} insserv -d tarbitratord || : + ${csudo}insserv tqd || : + ${csudo}insserv -d tqd || : + ${csudo}insserv tarbitratord || : + ${csudo}insserv -d tarbitratord || : elif ((${initd_mod}==3)); then - ${csudo} update-rc.d tqd defaults || : - ${csudo} update-rc.d tarbitratord defaults || : + ${csudo}update-rc.d tqd defaults || : + ${csudo}update-rc.d tarbitratord defaults || : fi } @@ -585,27 +585,27 @@ function clean_service_on_systemd() { tqd_service_config="${service_config_dir}/tqd.service" if systemctl is-active --quiet tqd; then echo "TQ is running, stopping it..." - ${csudo} systemctl stop tqd &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop tqd &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable tqd &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${tqd_service_config} + ${csudo}systemctl disable tqd &> /dev/null || echo &> /dev/null + ${csudo}rm -f ${tqd_service_config} tarbitratord_service_config="${service_config_dir}/tarbitratord.service" if systemctl is-active --quiet tarbitratord; then echo "tarbitrator is running, stopping it..." - ${csudo} systemctl stop tarbitratord &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop tarbitratord &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable tarbitratord &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${tarbitratord_service_config} + ${csudo}systemctl disable tarbitratord &> /dev/null || echo &> /dev/null + ${csudo}rm -f ${tarbitratord_service_config} if [ "$verMode" == "cluster" ]; then nginx_service_config="${service_config_dir}/nginxd.service" if systemctl is-active --quiet nginxd; then echo "Nginx for TQ is running, stopping it..." - ${csudo} systemctl stop nginxd &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop nginxd &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable nginxd &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${nginx_service_config} + ${csudo}systemctl disable nginxd &> /dev/null || echo &> /dev/null + ${csudo}rm -f ${nginx_service_config} fi } @@ -615,81 +615,81 @@ function install_service_on_systemd() { clean_service_on_systemd tqd_service_config="${service_config_dir}/tqd.service" - ${csudo} bash -c "echo '[Unit]' >> ${tqd_service_config}" - ${csudo} bash -c "echo 'Description=TQ server service' >> ${tqd_service_config}" - ${csudo} bash -c "echo 'After=network-online.target' >> ${tqd_service_config}" - ${csudo} bash -c "echo 'Wants=network-online.target' >> ${tqd_service_config}" - ${csudo} bash -c "echo >> ${tqd_service_config}" - ${csudo} bash -c "echo '[Service]' >> ${tqd_service_config}" - ${csudo} bash -c "echo 'Type=simple' >> ${tqd_service_config}" - ${csudo} bash -c "echo 'ExecStart=/usr/bin/tqd' >> ${tqd_service_config}" - ${csudo} bash -c "echo 'ExecStartPre=/usr/local/tq/bin/startPre.sh' >> ${tqd_service_config}" - ${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${tqd_service_config}" - ${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${tqd_service_config}" - ${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${tqd_service_config}" - ${csudo} bash -c "echo 'LimitCORE=infinity' >> ${tqd_service_config}" - ${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${tqd_service_config}" - ${csudo} bash -c "echo 'StandardOutput=null' >> ${tqd_service_config}" - ${csudo} bash -c "echo 'Restart=always' >> ${tqd_service_config}" - ${csudo} bash -c "echo 'StartLimitBurst=3' >> ${tqd_service_config}" - ${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${tqd_service_config}" - ${csudo} bash -c "echo >> ${tqd_service_config}" - ${csudo} bash -c "echo '[Install]' >> ${tqd_service_config}" - ${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${tqd_service_config}" - ${csudo} systemctl enable tqd + ${csudo}bash -c "echo '[Unit]' >> ${tqd_service_config}" + ${csudo}bash -c "echo 'Description=TQ server service' >> ${tqd_service_config}" + ${csudo}bash -c "echo 'After=network-online.target' >> ${tqd_service_config}" + ${csudo}bash -c "echo 'Wants=network-online.target' >> ${tqd_service_config}" + ${csudo}bash -c "echo >> ${tqd_service_config}" + ${csudo}bash -c "echo '[Service]' >> ${tqd_service_config}" + ${csudo}bash -c "echo 'Type=simple' >> ${tqd_service_config}" + ${csudo}bash -c "echo 'ExecStart=/usr/bin/tqd' >> ${tqd_service_config}" + ${csudo}bash -c "echo 'ExecStartPre=/usr/local/tq/bin/startPre.sh' >> ${tqd_service_config}" + ${csudo}bash -c "echo 'TimeoutStopSec=1000000s' >> ${tqd_service_config}" + ${csudo}bash -c "echo 'LimitNOFILE=infinity' >> ${tqd_service_config}" + ${csudo}bash -c "echo 'LimitNPROC=infinity' >> ${tqd_service_config}" + ${csudo}bash -c "echo 'LimitCORE=infinity' >> ${tqd_service_config}" + ${csudo}bash -c "echo 'TimeoutStartSec=0' >> ${tqd_service_config}" + ${csudo}bash -c "echo 'StandardOutput=null' >> ${tqd_service_config}" + ${csudo}bash -c "echo 'Restart=always' >> ${tqd_service_config}" + ${csudo}bash -c "echo 'StartLimitBurst=3' >> ${tqd_service_config}" + ${csudo}bash -c "echo 'StartLimitInterval=60s' >> ${tqd_service_config}" + ${csudo}bash -c "echo >> ${tqd_service_config}" + ${csudo}bash -c "echo '[Install]' >> ${tqd_service_config}" + ${csudo}bash -c "echo 'WantedBy=multi-user.target' >> ${tqd_service_config}" + ${csudo}systemctl enable tqd tarbitratord_service_config="${service_config_dir}/tarbitratord.service" - ${csudo} bash -c "echo '[Unit]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Description=TQ arbitrator service' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'After=network-online.target' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Wants=network-online.target' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo '[Service]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Type=simple' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'ExecStart=/usr/bin/tarbitrator' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'LimitCORE=infinity' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StandardOutput=null' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'Restart=always' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StartLimitBurst=3' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo '[Install]' >> ${tarbitratord_service_config}" - ${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${tarbitratord_service_config}" - #${csudo} systemctl enable tarbitratord + ${csudo}bash -c "echo '[Unit]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Description=TQ arbitrator service' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'After=network-online.target' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Wants=network-online.target' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo '[Service]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Type=simple' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'ExecStart=/usr/bin/tarbitrator' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'TimeoutStopSec=1000000s' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitNOFILE=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitNPROC=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'LimitCORE=infinity' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'TimeoutStartSec=0' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StandardOutput=null' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'Restart=always' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StartLimitBurst=3' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'StartLimitInterval=60s' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo '[Install]' >> ${tarbitratord_service_config}" + ${csudo}bash -c "echo 'WantedBy=multi-user.target' >> ${tarbitratord_service_config}" + #${csudo}systemctl enable tarbitratord if [ "$verMode" == "cluster" ]; then nginx_service_config="${service_config_dir}/nginxd.service" - ${csudo} bash -c "echo '[Unit]' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'Description=Nginx For PowrDB Service' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'After=network-online.target' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'Wants=network-online.target' >> ${nginx_service_config}" - ${csudo} bash -c "echo >> ${nginx_service_config}" - ${csudo} bash -c "echo '[Service]' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'Type=forking' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'PIDFile=/usr/local/nginxd/logs/nginx.pid' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'ExecStart=/usr/local/nginxd/sbin/nginx' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'ExecStop=/usr/local/nginxd/sbin/nginx -s stop' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'LimitCORE=infinity' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'StandardOutput=null' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'Restart=always' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'StartLimitBurst=3' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${nginx_service_config}" - ${csudo} bash -c "echo >> ${nginx_service_config}" - ${csudo} bash -c "echo '[Install]' >> ${nginx_service_config}" - ${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${nginx_service_config}" - if ! ${csudo} systemctl enable nginxd &> /dev/null; then - ${csudo} systemctl daemon-reexec - ${csudo} systemctl enable nginxd + ${csudo}bash -c "echo '[Unit]' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'Description=Nginx For PowrDB Service' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'After=network-online.target' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'Wants=network-online.target' >> ${nginx_service_config}" + ${csudo}bash -c "echo >> ${nginx_service_config}" + ${csudo}bash -c "echo '[Service]' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'Type=forking' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'PIDFile=/usr/local/nginxd/logs/nginx.pid' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'ExecStart=/usr/local/nginxd/sbin/nginx' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'ExecStop=/usr/local/nginxd/sbin/nginx -s stop' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'TimeoutStopSec=1000000s' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'LimitNOFILE=infinity' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'LimitNPROC=infinity' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'LimitCORE=infinity' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'TimeoutStartSec=0' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'StandardOutput=null' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'Restart=always' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'StartLimitBurst=3' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'StartLimitInterval=60s' >> ${nginx_service_config}" + ${csudo}bash -c "echo >> ${nginx_service_config}" + ${csudo}bash -c "echo '[Install]' >> ${nginx_service_config}" + ${csudo}bash -c "echo 'WantedBy=multi-user.target' >> ${nginx_service_config}" + if ! ${csudo}systemctl enable nginxd &> /dev/null; then + ${csudo}systemctl daemon-reexec + ${csudo}systemctl enable nginxd fi - ${csudo} systemctl start nginxd + ${csudo}systemctl start nginxd fi } @@ -770,9 +770,9 @@ function update_tq() { # Stop the service if running if pidof tqd &> /dev/null; then if ((${service_mod}==0)); then - ${csudo} systemctl stop tqd || : + ${csudo}systemctl stop tqd || : elif ((${service_mod}==1)); then - ${csudo} service tqd stop || : + ${csudo}service tqd stop || : else kill_process tqd fi @@ -781,9 +781,9 @@ function update_tq() { if [ "$verMode" == "cluster" ]; then if pidof nginx &> /dev/null; then if ((${service_mod}==0)); then - ${csudo} systemctl stop nginxd || : + ${csudo}systemctl stop nginxd || : elif ((${service_mod}==1)); then - ${csudo} service nginxd stop || : + ${csudo}service nginxd stop || : else kill_process nginx fi @@ -824,9 +824,9 @@ function update_tq() { echo echo -e "${GREEN_DARK}To configure TQ ${NC}: edit /etc/tq/tq.cfg" if ((${service_mod}==0)); then - echo -e "${GREEN_DARK}To start TQ ${NC}: ${csudo} systemctl start tqd${NC}" + echo -e "${GREEN_DARK}To start TQ ${NC}: ${csudo}systemctl start tqd${NC}" elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start TQ ${NC}: ${csudo} service tqd start${NC}" + echo -e "${GREEN_DARK}To start TQ ${NC}: ${csudo}service tqd start${NC}" else echo -e "${GREEN_DARK}To start TQ ${NC}: ./tqd${NC}" fi @@ -901,9 +901,9 @@ function install_tq() { echo echo -e "${GREEN_DARK}To configure TQ ${NC}: edit /etc/tq/tq.cfg" if ((${service_mod}==0)); then - echo -e "${GREEN_DARK}To start TQ ${NC}: ${csudo} systemctl start tqd${NC}" + echo -e "${GREEN_DARK}To start TQ ${NC}: ${csudo}systemctl start tqd${NC}" elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start TQ ${NC}: ${csudo} service tqd start${NC}" + echo -e "${GREEN_DARK}To start TQ ${NC}: ${csudo}service tqd start${NC}" else echo -e "${GREEN_DARK}To start TQ ${NC}: tqd${NC}" fi diff --git a/packaging/tools/make_install.sh b/packaging/tools/make_install.sh index 38b45871a6a96887fee19cd460f056410f52fbc5..ba81aacb19e8054ce7d4423cd3b106c1a8d1ad67 100755 --- a/packaging/tools/make_install.sh +++ b/packaging/tools/make_install.sh @@ -67,7 +67,7 @@ os_type=0 if [ "$osType" != "Darwin" ]; then if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi initd_mod=0 if pidof systemd &> /dev/null; then @@ -118,7 +118,7 @@ fi function kill_taosadapter() { pid=$(ps -ef | grep "taosadapter" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } @@ -126,79 +126,79 @@ function kill_taosd() { ps -ef | grep "taosd" pid=$(ps -ef | grep -w "taosd" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function install_main_path() { #create install main dir and all sub dir if [ "$osType" != "Darwin" ]; then - ${csudo} rm -rf ${install_main_dir} || : - ${csudo} mkdir -p ${install_main_dir} - ${csudo} mkdir -p ${install_main_dir}/cfg - ${csudo} mkdir -p ${install_main_dir}/bin - ${csudo} mkdir -p ${install_main_dir}/connector - ${csudo} mkdir -p ${install_main_dir}/driver - ${csudo} mkdir -p ${install_main_dir}/examples - ${csudo} mkdir -p ${install_main_dir}/include - ${csudo} mkdir -p ${install_main_dir}/init.d + ${csudo}rm -rf ${install_main_dir} || : + ${csudo}mkdir -p ${install_main_dir} + ${csudo}mkdir -p ${install_main_dir}/cfg + ${csudo}mkdir -p ${install_main_dir}/bin + ${csudo}mkdir -p ${install_main_dir}/connector + ${csudo}mkdir -p ${install_main_dir}/driver + ${csudo}mkdir -p ${install_main_dir}/examples + ${csudo}mkdir -p ${install_main_dir}/include + ${csudo}mkdir -p ${install_main_dir}/init.d else - ${csudo} rm -rf ${install_main_dir} || ${csudo} rm -rf ${install_main_2_dir} || : - ${csudo} mkdir -p ${install_main_dir} || ${csudo} mkdir -p ${install_main_2_dir} - ${csudo} mkdir -p ${install_main_dir}/cfg || ${csudo} mkdir -p ${install_main_2_dir}/cfg - ${csudo} mkdir -p ${install_main_dir}/bin || ${csudo} mkdir -p ${install_main_2_dir}/bin - ${csudo} mkdir -p ${install_main_dir}/connector || ${csudo} mkdir -p ${install_main_2_dir}/connector - ${csudo} mkdir -p ${install_main_dir}/driver || ${csudo} mkdir -p ${install_main_2_dir}/driver - ${csudo} mkdir -p ${install_main_dir}/examples || ${csudo} mkdir -p ${install_main_2_dir}/examples - ${csudo} mkdir -p ${install_main_dir}/include || ${csudo} mkdir -p ${install_main_2_dir}/include + ${csudo}rm -rf ${install_main_dir} || ${csudo}rm -rf ${install_main_2_dir} || : + ${csudo}mkdir -p ${install_main_dir} || ${csudo}mkdir -p ${install_main_2_dir} + ${csudo}mkdir -p ${install_main_dir}/cfg || ${csudo}mkdir -p ${install_main_2_dir}/cfg + ${csudo}mkdir -p ${install_main_dir}/bin || ${csudo}mkdir -p ${install_main_2_dir}/bin + ${csudo}mkdir -p ${install_main_dir}/connector || ${csudo}mkdir -p ${install_main_2_dir}/connector + ${csudo}mkdir -p ${install_main_dir}/driver || ${csudo}mkdir -p ${install_main_2_dir}/driver + ${csudo}mkdir -p ${install_main_dir}/examples || ${csudo}mkdir -p ${install_main_2_dir}/examples + ${csudo}mkdir -p ${install_main_dir}/include || ${csudo}mkdir -p ${install_main_2_dir}/include fi } function install_bin() { # Remove links - ${csudo} rm -f ${bin_link_dir}/taos || : - ${csudo} rm -f ${bin_link_dir}/taosd || : - ${csudo} rm -f ${bin_link_dir}/taosadapter || : - ${csudo} rm -f ${bin_link_dir}/taosdemo || : - ${csudo} rm -f ${bin_link_dir}/taosdump || : + ${csudo}rm -f ${bin_link_dir}/taos || : + ${csudo}rm -f ${bin_link_dir}/taosd || : + ${csudo}rm -f ${bin_link_dir}/taosadapter || : + ${csudo}rm -f ${bin_link_dir}/taosdemo || : + ${csudo}rm -f ${bin_link_dir}/taosdump || : if [ "$osType" != "Darwin" ]; then - ${csudo} rm -f ${bin_link_dir}/perfMonitor || : - ${csudo} rm -f ${bin_link_dir}/set_core || : - ${csudo} rm -f ${bin_link_dir}/run_taosd.sh || : - ${csudo} rm -f ${bin_link_dir}/rmtaos || : + ${csudo}rm -f ${bin_link_dir}/perfMonitor || : + ${csudo}rm -f ${bin_link_dir}/set_core || : + ${csudo}rm -f ${bin_link_dir}/run_taosd.sh || : + ${csudo}rm -f ${bin_link_dir}/rmtaos || : - ${csudo} cp -r ${binary_dir}/build/bin/* ${install_main_dir}/bin - ${csudo} cp -r ${script_dir}/taosd-dump-cfg.gdb ${install_main_dir}/bin + ${csudo}cp -r ${binary_dir}/build/bin/* ${install_main_dir}/bin + ${csudo}cp -r ${script_dir}/taosd-dump-cfg.gdb ${install_main_dir}/bin - ${csudo} cp -r ${script_dir}/remove.sh ${install_main_dir}/bin - ${csudo} cp -r ${script_dir}/set_core.sh ${install_main_dir}/bin - ${csudo} cp -r ${script_dir}/run_taosd.sh ${install_main_dir}/bin - ${csudo} cp -r ${script_dir}/startPre.sh ${install_main_dir}/bin + ${csudo}cp -r ${script_dir}/remove.sh ${install_main_dir}/bin + ${csudo}cp -r ${script_dir}/set_core.sh ${install_main_dir}/bin + ${csudo}cp -r ${script_dir}/run_taosd.sh ${install_main_dir}/bin + ${csudo}cp -r ${script_dir}/startPre.sh ${install_main_dir}/bin - ${csudo} chmod 0555 ${install_main_dir}/bin/* + ${csudo}chmod 0555 ${install_main_dir}/bin/* #Make link - [ -x ${install_main_dir}/bin/taos ] && ${csudo} ln -s ${install_main_dir}/bin/taos ${bin_link_dir}/taos || : - [ -x ${install_main_dir}/bin/taosd ] && ${csudo} ln -s ${install_main_dir}/bin/taosd ${bin_link_dir}/taosd || : - [ -x ${install_main_dir}/bin/taosadapter ] && ${csudo} ln -s ${install_main_dir}/bin/taosadapter ${bin_link_dir}/taosadapter || : - [ -x ${install_main_dir}/bin/taosdump ] && ${csudo} ln -s ${install_main_dir}/bin/taosdump ${bin_link_dir}/taosdump || : - [ -x ${install_main_dir}/bin/taosdemo ] && ${csudo} ln -s ${install_main_dir}/bin/taosdemo ${bin_link_dir}/taosdemo || : - [ -x ${install_main_dir}/bin/perfMonitor ] && ${csudo} ln -s ${install_main_dir}/bin/perfMonitor ${bin_link_dir}/perfMonitor || : - [ -x ${install_main_dir}/set_core.sh ] && ${csudo} ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : - [ -x ${install_main_dir}/run_taosd.sh ] && ${csudo} ln -s ${install_main_dir}/bin/run_taosd.sh ${bin_link_dir}/run_taosd.sh || : - [ -x ${install_main_dir}/bin/remove.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove.sh ${bin_link_dir}/rmtaos || : + [ -x ${install_main_dir}/bin/taos ] && ${csudo}ln -s ${install_main_dir}/bin/taos ${bin_link_dir}/taos || : + [ -x ${install_main_dir}/bin/taosd ] && ${csudo}ln -s ${install_main_dir}/bin/taosd ${bin_link_dir}/taosd || : + [ -x ${install_main_dir}/bin/taosadapter ] && ${csudo}ln -s ${install_main_dir}/bin/taosadapter ${bin_link_dir}/taosadapter || : + [ -x ${install_main_dir}/bin/taosdump ] && ${csudo}ln -s ${install_main_dir}/bin/taosdump ${bin_link_dir}/taosdump || : + [ -x ${install_main_dir}/bin/taosdemo ] && ${csudo}ln -s ${install_main_dir}/bin/taosdemo ${bin_link_dir}/taosdemo || : + [ -x ${install_main_dir}/bin/perfMonitor ] && ${csudo}ln -s ${install_main_dir}/bin/perfMonitor ${bin_link_dir}/perfMonitor || : + [ -x ${install_main_dir}/set_core.sh ] && ${csudo}ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : + [ -x ${install_main_dir}/run_taosd.sh ] && ${csudo}ln -s ${install_main_dir}/bin/run_taosd.sh ${bin_link_dir}/run_taosd.sh || : + [ -x ${install_main_dir}/bin/remove.sh ] && ${csudo}ln -s ${install_main_dir}/bin/remove.sh ${bin_link_dir}/rmtaos || : else - ${csudo} cp -r ${binary_dir}/build/bin/* ${install_main_dir}/bin || ${csudo} cp -r ${binary_dir}/build/bin/* ${install_main_2_dir}/bin || : - ${csudo} cp -r ${script_dir}/taosd-dump-cfg.gdb ${install_main_dir}/bin || ${csudo}cp -r ${script_dir}/taosd-dump-cfg.gdb ${install_main_2_dir} || : - ${csudo} cp -r ${script_dir}/remove_client.sh ${install_main_dir}/bin || ${csudo} cp -r ${script_dir}/remove_client.sh ${install_main_2_dir}/bin - ${csudo} chmod 0555 ${install_main_dir}/bin/* || ${csudo} chmod 0555 ${install_main_2_dir}/bin/* + ${csudo}cp -r ${binary_dir}/build/bin/* ${install_main_dir}/bin || ${csudo}cp -r ${binary_dir}/build/bin/* ${install_main_2_dir}/bin || : + ${csudo}cp -r ${script_dir}/taosd-dump-cfg.gdb ${install_main_dir}/bin || ${csudo}cp -r ${script_dir}/taosd-dump-cfg.gdb ${install_main_2_dir} || : + ${csudo}cp -r ${script_dir}/remove_client.sh ${install_main_dir}/bin || ${csudo}cp -r ${script_dir}/remove_client.sh ${install_main_2_dir}/bin + ${csudo}chmod 0555 ${install_main_dir}/bin/* || ${csudo}chmod 0555 ${install_main_2_dir}/bin/* #Make link - [ -x ${install_main_dir}/bin/taos ] || [ -x ${install_main_2_dir}/bin/taos ] && ${csudo} ln -s ${install_main_dir}/bin/taos ${bin_link_dir}/taos || ${csudo} ln -s ${install_main_2_dir}/bin/taos || : - [ -x ${install_main_dir}/bin/taosd ] || [ -x ${install_main_2_dir}/bin/taosd ] && ${csudo} ln -s ${install_main_dir}/bin/taosd ${bin_link_dir}/taosd || ${csudo} ln -s ${install_main_2_dir}/bin/taosd || : - [ -x ${install_main_dir}/bin/taosadapter ] || [ -x ${install_main_2_dir}/bin/taosadapter ] && ${csudo} ln -s ${install_main_dir}/bin/taosadapter ${bin_link_dir}/taosadapter || ${csudo} ln -s ${install_main_2_dir}/bin/taosadapter || : - [ -x ${install_main_dir}/bin/taosdump ] || [ -x ${install_main_2_dir}/bin/taosdump ] && ${csudo} ln -s ${install_main_dir}/bin/taosdump ${bin_link_dir}/taosdump || ln -s ${install_main_2_dir}/bin/taosdump ${bin_link_dir}/taosdump || : - [ -x ${install_main_dir}/bin/taosdemo ] || [ -x ${install_main_2_dir}/bin/taosdemo ] && ${csudo} ln -s ${install_main_dir}/bin/taosdemo ${bin_link_dir}/taosdemo || ln -s ${install_main_2_dir}/bin/taosdemo ${bin_link_dir}/taosdemo || : + [ -x ${install_main_dir}/bin/taos ] || [ -x ${install_main_2_dir}/bin/taos ] && ${csudo}ln -s ${install_main_dir}/bin/taos ${bin_link_dir}/taos || ${csudo}ln -s ${install_main_2_dir}/bin/taos || : + [ -x ${install_main_dir}/bin/taosd ] || [ -x ${install_main_2_dir}/bin/taosd ] && ${csudo}ln -s ${install_main_dir}/bin/taosd ${bin_link_dir}/taosd || ${csudo}ln -s ${install_main_2_dir}/bin/taosd || : + [ -x ${install_main_dir}/bin/taosadapter ] || [ -x ${install_main_2_dir}/bin/taosadapter ] && ${csudo}ln -s ${install_main_dir}/bin/taosadapter ${bin_link_dir}/taosadapter || ${csudo}ln -s ${install_main_2_dir}/bin/taosadapter || : + [ -x ${install_main_dir}/bin/taosdump ] || [ -x ${install_main_2_dir}/bin/taosdump ] && ${csudo}ln -s ${install_main_dir}/bin/taosdump ${bin_link_dir}/taosdump || ln -s ${install_main_2_dir}/bin/taosdump ${bin_link_dir}/taosdump || : + [ -x ${install_main_dir}/bin/taosdemo ] || [ -x ${install_main_2_dir}/bin/taosdemo ] && ${csudo}ln -s ${install_main_dir}/bin/taosdemo ${bin_link_dir}/taosdemo || ln -s ${install_main_2_dir}/bin/taosdemo ${bin_link_dir}/taosdemo || : fi } @@ -207,48 +207,48 @@ function install_jemalloc() { /usr/bin/install -c -d /usr/local/bin if [ -f "${binary_dir}/build/bin/jemalloc-config" ]; then - ${csudo} /usr/bin/install -c -m 755 ${binary_dir}/build/bin/jemalloc-config /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${binary_dir}/build/bin/jemalloc-config /usr/local/bin fi if [ -f "${binary_dir}/build/bin/jemalloc.sh" ]; then - ${csudo} /usr/bin/install -c -m 755 ${binary_dir}/build/bin/jemalloc.sh /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${binary_dir}/build/bin/jemalloc.sh /usr/local/bin fi if [ -f "${binary_dir}/build/bin/jeprof" ]; then - ${csudo} /usr/bin/install -c -m 755 ${binary_dir}/build/bin/jeprof /usr/local/bin + ${csudo}/usr/bin/install -c -m 755 ${binary_dir}/build/bin/jeprof /usr/local/bin fi if [ -f "${binary_dir}/build/include/jemalloc/jemalloc.h" ]; then - ${csudo} /usr/bin/install -c -d /usr/local/include/jemalloc - ${csudo} /usr/bin/install -c -m 644 ${binary_dir}/build/include/jemalloc/jemalloc.h\ + ${csudo}/usr/bin/install -c -d /usr/local/include/jemalloc + ${csudo}/usr/bin/install -c -m 644 ${binary_dir}/build/include/jemalloc/jemalloc.h\ /usr/local/include/jemalloc fi if [ -f "${binary_dir}/build/lib/libjemalloc.so.2" ]; then - ${csudo} /usr/bin/install -c -d /usr/local/lib - ${csudo} /usr/bin/install -c -m 755 ${binary_dir}/build/lib/libjemalloc.so.2 /usr/local/lib - ${csudo} ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so - ${csudo} /usr/bin/install -c -d /usr/local/lib + ${csudo}/usr/bin/install -c -d /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${binary_dir}/build/lib/libjemalloc.so.2 /usr/local/lib + ${csudo}ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so + ${csudo}/usr/bin/install -c -d /usr/local/lib [ -f ${binary_dir}/build/lib/libjemalloc.a ] && - ${csudo} /usr/bin/install -c -m 755 ${binary_dir}/build/lib/libjemalloc.a /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${binary_dir}/build/lib/libjemalloc.a /usr/local/lib [ -f ${binary_dir}/build/lib/libjemalloc_pic.a ] && - ${csudo} /usr/bin/install -c -m 755 ${binary_dir}/build/lib/libjemalloc_pic.a /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${binary_dir}/build/lib/libjemalloc_pic.a /usr/local/lib if [ -f "${binary_dir}/build/lib/pkgconfig/jemalloc.pc" ]; then - ${csudo} /usr/bin/install -c -d /usr/local/lib/pkgconfig - ${csudo} /usr/bin/install -c -m 644 ${binary_dir}/build/lib/pkgconfig/jemalloc.pc\ + ${csudo}/usr/bin/install -c -d /usr/local/lib/pkgconfig + ${csudo}/usr/bin/install -c -m 644 ${binary_dir}/build/lib/pkgconfig/jemalloc.pc\ /usr/local/lib/pkgconfig fi if [ -d /etc/ld.so.conf.d ]; then - echo "/usr/local/lib" | ${csudo} tee /etc/ld.so.conf.d/jemalloc.conf > /dev/null || echo -e "failed to write /etc/ld.so.conf.d/jemalloc.conf" - ${csudo} ldconfig + echo "/usr/local/lib" | ${csudo}tee /etc/ld.so.conf.d/jemalloc.conf > /dev/null || echo -e "failed to write /etc/ld.so.conf.d/jemalloc.conf" + ${csudo}ldconfig else echo "/etc/ld.so.conf.d not found!" fi fi if [ -f "${binary_dir}/build/share/doc/jemalloc/jemalloc.html" ]; then - ${csudo} /usr/bin/install -c -d /usr/local/share/doc/jemalloc - ${csudo} /usr/bin/install -c -m 644 ${binary_dir}/build/share/doc/jemalloc/jemalloc.html\ + ${csudo}/usr/bin/install -c -d /usr/local/share/doc/jemalloc + ${csudo}/usr/bin/install -c -m 644 ${binary_dir}/build/share/doc/jemalloc/jemalloc.html\ /usr/local/share/doc/jemalloc fi if [ -f "${binary_dir}/build/share/man/man3/jemalloc.3" ]; then - ${csudo} /usr/bin/install -c -d /usr/local/share/man/man3 - ${csudo} /usr/bin/install -c -m 644 ${binary_dir}/build/share/man/man3/jemalloc.3\ + ${csudo}/usr/bin/install -c -d /usr/local/share/man/man3 + ${csudo}/usr/bin/install -c -m 644 ${binary_dir}/build/share/man/man3/jemalloc.3\ /usr/local/share/man/man3 fi fi @@ -257,17 +257,17 @@ function install_jemalloc() { function install_avro() { if [ "$osType" != "Darwin" ]; then if [ -f "${binary_dir}/build/$1/libavro.so.23.0.0" ] && [ -d /usr/local/$1 ]; then - ${csudo} /usr/bin/install -c -d /usr/local/$1 - ${csudo} /usr/bin/install -c -m 755 ${binary_dir}/build/$1/libavro.so.23.0.0 /usr/local/$1 - ${csudo} ln -sf libavro.so.23.0.0 /usr/local/$1/libavro.so.23 - ${csudo} ln -sf libavro.so.23 /usr/local/$1/libavro.so - ${csudo} /usr/bin/install -c -d /usr/local/$1 + ${csudo}/usr/bin/install -c -d /usr/local/$1 + ${csudo}/usr/bin/install -c -m 755 ${binary_dir}/build/$1/libavro.so.23.0.0 /usr/local/$1 + ${csudo}ln -sf libavro.so.23.0.0 /usr/local/$1/libavro.so.23 + ${csudo}ln -sf libavro.so.23 /usr/local/$1/libavro.so + ${csudo}/usr/bin/install -c -d /usr/local/$1 [ -f ${binary_dir}/build/$1/libavro.a ] && - ${csudo} /usr/bin/install -c -m 755 ${binary_dir}/build/$1/libavro.a /usr/local/$1 + ${csudo}/usr/bin/install -c -m 755 ${binary_dir}/build/$1/libavro.a /usr/local/$1 if [ -d /etc/ld.so.conf.d ]; then - echo "/usr/local/$1" | ${csudo} tee /etc/ld.so.conf.d/libavro.conf > /dev/null || echo -e "failed to write /etc/ld.so.conf.d/libavro.conf" - ${csudo} ldconfig + echo "/usr/local/$1" | ${csudo}tee /etc/ld.so.conf.d/libavro.conf > /dev/null || echo -e "failed to write /etc/ld.so.conf.d/libavro.conf" + ${csudo}ldconfig else echo "/etc/ld.so.conf.d not found!" fi @@ -277,47 +277,47 @@ function install_avro() { function install_lib() { # Remove links - ${csudo} rm -f ${lib_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib_link_dir}/libtaos.* || : if [ "$osType" != "Darwin" ]; then - ${csudo} rm -f ${lib64_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : fi if [ "$osType" != "Darwin" ]; then - ${csudo} cp ${binary_dir}/build/lib/libtaos.so.${verNumber} \ + ${csudo}cp ${binary_dir}/build/lib/libtaos.so.${verNumber} \ ${install_main_dir}/driver \ - && ${csudo} chmod 777 ${install_main_dir}/driver/* + && ${csudo}chmod 777 ${install_main_dir}/driver/* - ${csudo} ln -sf ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 - ${csudo} ln -sf ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so + ${csudo}ln -sf ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 + ${csudo}ln -sf ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so if [ -d "${lib64_link_dir}" ]; then - ${csudo} ln -sf ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 - ${csudo} ln -sf ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so + ${csudo}ln -sf ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 + ${csudo}ln -sf ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so fi else - ${csudo} cp -Rf ${binary_dir}/build/lib/libtaos.${verNumber}.dylib \ + ${csudo}cp -Rf ${binary_dir}/build/lib/libtaos.${verNumber}.dylib \ ${install_main_dir}/driver \ - || ${csudo} cp -Rf ${binary_dir}/build/lib/libtaos.${verNumber}.dylib \ + || ${csudo}cp -Rf ${binary_dir}/build/lib/libtaos.${verNumber}.dylib \ ${install_main_2_dir}/driver \ - && ${csudo} chmod 777 ${install_main_dir}/driver/* \ - || ${csudo} chmod 777 ${install_main_2_dir}/driver/* + && ${csudo}chmod 777 ${install_main_dir}/driver/* \ + || ${csudo}chmod 777 ${install_main_2_dir}/driver/* - ${csudo} ln -sf ${install_main_dir}/driver/libtaos.* \ + ${csudo}ln -sf ${install_main_dir}/driver/libtaos.* \ ${install_main_dir}/driver/libtaos.1.dylib \ - || ${csudo} ln -sf ${install_main_2_dir}/driver/libtaos.* \ + || ${csudo}ln -sf ${install_main_2_dir}/driver/libtaos.* \ ${install_main_2_dir}/driver/libtaos.1.dylib || : - ${csudo} ln -sf ${install_main_dir}/driver/libtaos.1.dylib \ + ${csudo}ln -sf ${install_main_dir}/driver/libtaos.1.dylib \ ${install_main_dir}/driver/libtaos.dylib \ - || ${csudo} ln -sf ${install_main_2_dir}/driver/libtaos.1.dylib \ + || ${csudo}ln -sf ${install_main_2_dir}/driver/libtaos.1.dylib \ ${install_main_2_dir}/driver/libtaos.dylib || : - ${csudo} ln -sf ${install_main_dir}/driver/libtaos.${verNumber}.dylib \ + ${csudo}ln -sf ${install_main_dir}/driver/libtaos.${verNumber}.dylib \ ${lib_link_dir}/libtaos.1.dylib \ - || ${csudo} ln -sf ${install_main_2_dir}/driver/libtaos.${verNumber}.dylib \ + || ${csudo}ln -sf ${install_main_2_dir}/driver/libtaos.${verNumber}.dylib \ ${lib_link_dir}/libtaos.1.dylib || : - ${csudo} ln -sf ${lib_link_dir}/libtaos.1.dylib ${lib_link_dir}/libtaos.dylib || : + ${csudo}ln -sf ${lib_link_dir}/libtaos.1.dylib ${lib_link_dir}/libtaos.dylib || : fi install_jemalloc @@ -325,129 +325,129 @@ function install_lib() { install_avro lib64 if [ "$osType" != "Darwin" ]; then - ${csudo} ldconfig + ${csudo}ldconfig fi } function install_header() { if [ "$osType" != "Darwin" ]; then - ${csudo} rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h || : - ${csudo} cp -f ${source_dir}/src/inc/taos.h ${source_dir}/src/inc/taosdef.h ${source_dir}/src/inc/taoserror.h \ - ${install_main_dir}/include && ${csudo} chmod 644 ${install_main_dir}/include/* - ${csudo} ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h - ${csudo} ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h - ${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h + ${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h || : + ${csudo}cp -f ${source_dir}/src/inc/taos.h ${source_dir}/src/inc/taosdef.h ${source_dir}/src/inc/taoserror.h \ + ${install_main_dir}/include && ${csudo}chmod 644 ${install_main_dir}/include/* + ${csudo}ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h + ${csudo}ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h + ${csudo}ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h else - ${csudo} cp -f ${source_dir}/src/inc/taos.h ${source_dir}/src/inc/taosdef.h ${source_dir}/src/inc/taoserror.h \ + ${csudo}cp -f ${source_dir}/src/inc/taos.h ${source_dir}/src/inc/taosdef.h ${source_dir}/src/inc/taoserror.h \ ${install_main_dir}/include \ - || ${csudo} cp -f ${source_dir}/src/inc/taos.h ${source_dir}/src/inc/taosdef.h ${source_dir}/src/inc/taoserror.h \ + || ${csudo}cp -f ${source_dir}/src/inc/taos.h ${source_dir}/src/inc/taosdef.h ${source_dir}/src/inc/taoserror.h \ ${install_main_2_dir}/include \ - && ${csudo} chmod 644 ${install_main_dir}/include/* \ - || ${csudo} chmod 644 ${install_main_2_dir}/include/* + && ${csudo}chmod 644 ${install_main_dir}/include/* \ + || ${csudo}chmod 644 ${install_main_2_dir}/include/* fi } function install_config() { if [ ! -f ${cfg_install_dir}/taos.cfg ]; then - ${csudo} mkdir -p ${cfg_install_dir} + ${csudo}mkdir -p ${cfg_install_dir} [ -f ${script_dir}/../cfg/taos.cfg ] && - ${csudo} cp ${script_dir}/../cfg/taos.cfg ${cfg_install_dir} - ${csudo} chmod 644 ${cfg_install_dir}/taos.cfg - ${csudo} cp -f ${script_dir}/../cfg/taos.cfg \ + ${csudo}cp ${script_dir}/../cfg/taos.cfg ${cfg_install_dir} + ${csudo}chmod 644 ${cfg_install_dir}/taos.cfg + ${csudo}cp -f ${script_dir}/../cfg/taos.cfg \ ${cfg_install_dir}/taos.cfg.${verNumber} - ${csudo} ln -s ${cfg_install_dir}/taos.cfg \ + ${csudo}ln -s ${cfg_install_dir}/taos.cfg \ ${install_main_dir}/cfg/taos.cfg else - ${csudo} cp -f ${script_dir}/../cfg/taos.cfg \ + ${csudo}cp -f ${script_dir}/../cfg/taos.cfg \ ${cfg_install_dir}/taos.cfg.${verNumber} fi } function install_taosadapter_config() { if [ ! -f "${cfg_install_dir}/taosadapter.toml" ]; then - ${csudo} mkdir -p ${cfg_install_dir} + ${csudo}mkdir -p ${cfg_install_dir} [ -f ${binary_dir}/test/cfg/taosadapter.toml ] && - ${csudo} cp ${binary_dir}/test/cfg/taosadapter.toml ${cfg_install_dir} + ${csudo}cp ${binary_dir}/test/cfg/taosadapter.toml ${cfg_install_dir} [ -f ${cfg_install_dir}/taosadapter.toml ] && - ${csudo} chmod 644 ${cfg_install_dir}/taosadapter.toml + ${csudo}chmod 644 ${cfg_install_dir}/taosadapter.toml [ -f ${binary_dir}/test/cfg/taosadapter.toml ] && - ${csudo} cp -f ${binary_dir}/test/cfg/taosadapter.toml \ + ${csudo}cp -f ${binary_dir}/test/cfg/taosadapter.toml \ ${cfg_install_dir}/taosadapter.toml.${verNumber} [ -f ${cfg_install_dir}/taosadapter.toml ] && \ - ${csudo} ln -s ${cfg_install_dir}/taosadapter.toml \ + ${csudo}ln -s ${cfg_install_dir}/taosadapter.toml \ ${install_main_dir}/cfg/taosadapter.toml else if [ -f "${binary_dir}/test/cfg/taosadapter.toml" ]; then - ${csudo} cp -f ${binary_dir}/test/cfg/taosadapter.toml \ + ${csudo}cp -f ${binary_dir}/test/cfg/taosadapter.toml \ ${cfg_install_dir}/taosadapter.toml.${verNumber} fi fi } function install_log() { - ${csudo} rm -rf ${log_dir} || : - ${csudo} mkdir -p ${log_dir} && ${csudo} chmod 777 ${log_dir} + ${csudo}rm -rf ${log_dir} || : + ${csudo}mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir} if [ "$osType" != "Darwin" ]; then - ${csudo} ln -s ${log_dir} ${install_main_dir}/log + ${csudo}ln -s ${log_dir} ${install_main_dir}/log else - ${csudo} ln -s ${log_dir} ${install_main_dir}/log || ${csudo} ln -s ${log_dir} ${install_main_2_dir}/log + ${csudo}ln -s ${log_dir} ${install_main_dir}/log || ${csudo}ln -s ${log_dir} ${install_main_2_dir}/log fi } function install_data() { - ${csudo} mkdir -p ${data_dir} + ${csudo}mkdir -p ${data_dir} if [ "$osType" != "Darwin" ]; then - ${csudo} ln -s ${data_dir} ${install_main_dir}/data + ${csudo}ln -s ${data_dir} ${install_main_dir}/data else - ${csudo} ln -s ${data_dir} ${install_main_dir}/data || ${csudo} ln -s ${data_dir} ${install_main_2_dir}/data + ${csudo}ln -s ${data_dir} ${install_main_dir}/data || ${csudo}ln -s ${data_dir} ${install_main_2_dir}/data fi } function install_connector() { if find ${source_dir}/src/connector/go -mindepth 1 -maxdepth 1 | read; then - ${csudo} cp -r ${source_dir}/src/connector/go ${install_main_dir}/connector + ${csudo}cp -r ${source_dir}/src/connector/go ${install_main_dir}/connector else echo "WARNING: go connector not found, please check if want to use it!" fi if [ "$osType" != "Darwin" ]; then - ${csudo} cp -rf ${source_dir}/src/connector/python ${install_main_dir}/connector - ${csudo} cp ${binary_dir}/build/lib/*.jar ${install_main_dir}/connector &> /dev/null && ${csudo} chmod 777 ${install_main_dir}/connector/*.jar || echo &> /dev/null + ${csudo}cp -rf ${source_dir}/src/connector/python ${install_main_dir}/connector + ${csudo}cp ${binary_dir}/build/lib/*.jar ${install_main_dir}/connector &> /dev/null && ${csudo}chmod 777 ${install_main_dir}/connector/*.jar || echo &> /dev/null else - ${csudo} cp -rf ${source_dir}/src/connector/python ${install_main_dir}/connector || ${csudo} cp -rf ${source_dir}/src/connector/python ${install_main_2_dir}/connector - ${csudo} cp ${binary_dir}/build/lib/*.jar ${install_main_dir}/connector &> /dev/null && ${csudo} chmod 777 ${install_main_dir}/connector/*.jar || echo &> /dev/null - ${csudo} cp ${binary_dir}/build/lib/*.jar ${install_main_2_dir}/connector &> /dev/null && ${csudo} chmod 777 ${install_main_2_dir}/connector/*.jar || echo &> /dev/null + ${csudo}cp -rf ${source_dir}/src/connector/python ${install_main_dir}/connector || ${csudo}cp -rf ${source_dir}/src/connector/python ${install_main_2_dir}/connector + ${csudo}cp ${binary_dir}/build/lib/*.jar ${install_main_dir}/connector &> /dev/null && ${csudo}chmod 777 ${install_main_dir}/connector/*.jar || echo &> /dev/null + ${csudo}cp ${binary_dir}/build/lib/*.jar ${install_main_2_dir}/connector &> /dev/null && ${csudo}chmod 777 ${install_main_2_dir}/connector/*.jar || echo &> /dev/null fi } function install_examples() { if [ "$osType" != "Darwin" ]; then - ${csudo} cp -rf ${source_dir}/tests/examples/* ${install_main_dir}/examples + ${csudo}cp -rf ${source_dir}/tests/examples/* ${install_main_dir}/examples else - ${csudo} cp -rf ${source_dir}/tests/examples/* ${install_main_dir}/examples || ${csudo} cp -rf ${source_dir}/tests/examples/* ${install_main_2_dir}/examples + ${csudo}cp -rf ${source_dir}/tests/examples/* ${install_main_dir}/examples || ${csudo}cp -rf ${source_dir}/tests/examples/* ${install_main_2_dir}/examples fi } function clean_service_on_sysvinit() { #restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" - #${csudo} sed -i "\|${restart_config_str}|d" /etc/inittab || : + #${csudo}sed -i "\|${restart_config_str}|d" /etc/inittab || : if pidof taosd &> /dev/null; then - ${csudo} service taosd stop || : + ${csudo}service taosd stop || : fi if ((${initd_mod}==1)); then - ${csudo} chkconfig --del taosd || : + ${csudo}chkconfig --del taosd || : elif ((${initd_mod}==2)); then - ${csudo} insserv -r taosd || : + ${csudo}insserv -r taosd || : elif ((${initd_mod}==3)); then - ${csudo} update-rc.d -f taosd remove || : + ${csudo}update-rc.d -f taosd remove || : fi - ${csudo} rm -f ${service_config_dir}/taosd || : + ${csudo}rm -f ${service_config_dir}/taosd || : if $(which init &> /dev/null); then - ${csudo} init q || : + ${csudo}init q || : fi } @@ -458,24 +458,24 @@ function install_service_on_sysvinit() { # Install taosd service if ((${os_type}==1)); then - ${csudo} cp -f ${script_dir}/../deb/taosd ${install_main_dir}/init.d - ${csudo} cp ${script_dir}/../deb/taosd ${service_config_dir} && ${csudo} chmod a+x ${service_config_dir}/taosd + ${csudo}cp -f ${script_dir}/../deb/taosd ${install_main_dir}/init.d + ${csudo}cp ${script_dir}/../deb/taosd ${service_config_dir} && ${csudo}chmod a+x ${service_config_dir}/taosd elif ((${os_type}==2)); then - ${csudo} cp -f ${script_dir}/../rpm/taosd ${install_main_dir}/init.d - ${csudo} cp ${script_dir}/../rpm/taosd ${service_config_dir} && ${csudo} chmod a+x ${service_config_dir}/taosd + ${csudo}cp -f ${script_dir}/../rpm/taosd ${install_main_dir}/init.d + ${csudo}cp ${script_dir}/../rpm/taosd ${service_config_dir} && ${csudo}chmod a+x ${service_config_dir}/taosd fi #restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" - #${csudo} grep -q -F "$restart_config_str" /etc/inittab || ${csudo} bash -c "echo '${restart_config_str}' >> /etc/inittab" + #${csudo}grep -q -F "$restart_config_str" /etc/inittab || ${csudo}bash -c "echo '${restart_config_str}' >> /etc/inittab" if ((${initd_mod}==1)); then - ${csudo} chkconfig --add taosd || : - ${csudo} chkconfig --level 2345 taosd on || : + ${csudo}chkconfig --add taosd || : + ${csudo}chkconfig --level 2345 taosd on || : elif ((${initd_mod}==2)); then - ${csudo} insserv taosd || : - ${csudo} insserv -d taosd || : + ${csudo}insserv taosd || : + ${csudo}insserv -d taosd || : elif ((${initd_mod}==3)); then - ${csudo} update-rc.d taosd defaults || : + ${csudo}update-rc.d taosd defaults || : fi } @@ -484,11 +484,11 @@ function clean_service_on_systemd() { if systemctl is-active --quiet taosd; then echo "TDengine is running, stopping it..." - ${csudo} systemctl stop taosd &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop taosd &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable taosd &> /dev/null || echo &> /dev/null + ${csudo}systemctl disable taosd &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${taosd_service_config} + ${csudo}rm -f ${taosd_service_config} } # taos:2345:respawn:/etc/init.d/taosd start @@ -498,36 +498,36 @@ function install_service_on_systemd() { taosd_service_config="${service_config_dir}/taosd.service" - ${csudo} bash -c "echo '[Unit]' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'Description=TDengine server service' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'After=network-online.target taosadapter.service' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'Wants=network-online.target taosadapter.service' >> ${taosd_service_config}" - ${csudo} bash -c "echo >> ${taosd_service_config}" - ${csudo} bash -c "echo '[Service]' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'Type=simple' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'ExecStart=/usr/bin/taosd' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'ExecStartPre=/usr/local/taos/bin/startPre.sh' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'LimitCORE=infinity' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'StandardOutput=null' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'Restart=always' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'StartLimitBurst=3' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${taosd_service_config}" - ${csudo} bash -c "echo >> ${taosd_service_config}" - ${csudo} bash -c "echo '[Install]' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${taosd_service_config}" - ${csudo} systemctl enable taosd + ${csudo}bash -c "echo '[Unit]' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'Description=TDengine server service' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'After=network-online.target taosadapter.service' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'Wants=network-online.target taosadapter.service' >> ${taosd_service_config}" + ${csudo}bash -c "echo >> ${taosd_service_config}" + ${csudo}bash -c "echo '[Service]' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'Type=simple' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'ExecStart=/usr/bin/taosd' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'ExecStartPre=/usr/local/taos/bin/startPre.sh' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'TimeoutStopSec=1000000s' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'LimitNOFILE=infinity' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'LimitNPROC=infinity' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'LimitCORE=infinity' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'TimeoutStartSec=0' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'StandardOutput=null' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'Restart=always' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'StartLimitBurst=3' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'StartLimitInterval=60s' >> ${taosd_service_config}" + ${csudo}bash -c "echo >> ${taosd_service_config}" + ${csudo}bash -c "echo '[Install]' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'WantedBy=multi-user.target' >> ${taosd_service_config}" + ${csudo}systemctl enable taosd } function install_taosadapter_service() { if ((${service_mod}==0)); then [ -f ${binary_dir}/test/cfg/taosadapter.service ] &&\ - ${csudo} cp ${binary_dir}/test/cfg/taosadapter.service\ + ${csudo}cp ${binary_dir}/test/cfg/taosadapter.service\ ${service_config_dir}/ || : - ${csudo} systemctl daemon-reload + ${csudo}systemctl daemon-reload fi } @@ -548,9 +548,9 @@ function update_TDengine() { if pidof taosd &> /dev/null; then if ((${service_mod}==0)); then - ${csudo} systemctl stop taosd || : + ${csudo}systemctl stop taosd || : elif ((${service_mod}==1)); then - ${csudo} service taosd stop || : + ${csudo}service taosd stop || : else kill_taosadapter kill_taosd @@ -580,9 +580,9 @@ function update_TDengine() { echo -e "${GREEN_DARK}To configure TDengine ${NC}: edit /etc/taos/taos.cfg" echo -e "${GREEN_DARK}To configure Taos Adapter (if has) ${NC}: edit /etc/taos/taosadapter.toml" if ((${service_mod}==0)); then - echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} systemctl start taosd${NC}" + echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo}systemctl start taosd${NC}" elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} service taosd start${NC}" + echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo}service taosd start${NC}" else echo -e "${GREEN_DARK}To start Taos Adapter (if has)${NC}: taosadapter &${NC}" echo -e "${GREEN_DARK}To start TDengine ${NC}: taosd${NC}" @@ -620,10 +620,11 @@ function install_TDengine() { echo -e "${GREEN_DARK}To configure TDengine ${NC}: edit /etc/taos/taos.cfg" echo -e "${GREEN_DARK}To configure taosadapter (if has) ${NC}: edit /etc/taos/taosadapter.toml" if ((${service_mod}==0)); then - echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} systemctl start taosd${NC}" + echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo}systemctl start taosd${NC}" elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} service taosd start${NC}" + echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo}service taosd start${NC}" else + echo -e "${GREEN_DARK}To start Taos Adapter (if has)${NC}: taosadapter &${NC}" echo -e "${GREEN_DARK}To start TDengine ${NC}: ./taosd${NC}" fi diff --git a/packaging/tools/post.sh b/packaging/tools/post.sh index 7a90435d8f1ce8dc190e0f1513aee080838e4645..7fc2f984570f65a0b0381e5e54510e0fef667c6a 100755 --- a/packaging/tools/post.sh +++ b/packaging/tools/post.sh @@ -41,7 +41,7 @@ NC='\033[0m' csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi initd_mod=0 @@ -65,62 +65,62 @@ else fi function kill_taosadapter() { -# ${csudo} pkill -f taosadapter || : +# ${csudo}pkill -f taosadapter || : pid=$(ps -ef | grep "taosadapter" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function kill_taosd() { -# ${csudo} pkill -f taosd || : +# ${csudo}pkill -f taosd || : pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function install_include() { - ${csudo} rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h|| : - ${csudo} ln -s ${inc_dir}/taos.h ${inc_link_dir}/taos.h - ${csudo} ln -s ${inc_dir}/taosdef.h ${inc_link_dir}/taosdef.h - ${csudo} ln -s ${inc_dir}/taoserror.h ${inc_link_dir}/taoserror.h + ${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h|| : + ${csudo}ln -s ${inc_dir}/taos.h ${inc_link_dir}/taos.h + ${csudo}ln -s ${inc_dir}/taosdef.h ${inc_link_dir}/taosdef.h + ${csudo}ln -s ${inc_dir}/taoserror.h ${inc_link_dir}/taoserror.h } function install_lib() { - ${csudo} rm -f ${lib_link_dir}/libtaos* || : - ${csudo} rm -f ${lib64_link_dir}/libtaos* || : + ${csudo}rm -f ${lib_link_dir}/libtaos* || : + ${csudo}rm -f ${lib64_link_dir}/libtaos* || : - ${csudo} ln -s ${lib_dir}/libtaos.* ${lib_link_dir}/libtaos.so.1 - ${csudo} ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so + ${csudo}ln -s ${lib_dir}/libtaos.* ${lib_link_dir}/libtaos.so.1 + ${csudo}ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so if [[ -d ${lib64_link_dir} && ! -e ${lib64_link_dir}/libtaos.so ]]; then - ${csudo} ln -s ${lib_dir}/libtaos.* ${lib64_link_dir}/libtaos.so.1 || : - ${csudo} ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || : + ${csudo}ln -s ${lib_dir}/libtaos.* ${lib64_link_dir}/libtaos.so.1 || : + ${csudo}ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || : fi - ${csudo} ldconfig + ${csudo}ldconfig } function install_bin() { # Remove links - ${csudo} rm -f ${bin_link_dir}/taos || : - ${csudo} rm -f ${bin_link_dir}/taosd || : - ${csudo} rm -f ${bin_link_dir}/taosadapter || : - ${csudo} rm -f ${bin_link_dir}/taosdemo || : - ${csudo} rm -f ${bin_link_dir}/taosdump || : - ${csudo} rm -f ${bin_link_dir}/rmtaos || : - ${csudo} rm -f ${bin_link_dir}/set_core || : + ${csudo}rm -f ${bin_link_dir}/taos || : + ${csudo}rm -f ${bin_link_dir}/taosd || : + ${csudo}rm -f ${bin_link_dir}/taosadapter || : + ${csudo}rm -f ${bin_link_dir}/taosdemo || : + ${csudo}rm -f ${bin_link_dir}/taosdump || : + ${csudo}rm -f ${bin_link_dir}/rmtaos || : + ${csudo}rm -f ${bin_link_dir}/set_core || : - ${csudo} chmod 0555 ${bin_dir}/* + ${csudo}chmod 0555 ${bin_dir}/* #Make link - [ -x ${bin_dir}/taos ] && ${csudo} ln -s ${bin_dir}/taos ${bin_link_dir}/taos || : - [ -x ${bin_dir}/taosd ] && ${csudo} ln -s ${bin_dir}/taosd ${bin_link_dir}/taosd || : - [ -x ${bin_dir}/taosadapter ] && ${csudo} ln -s ${bin_dir}/taosadapter ${bin_link_dir}/taosadapter || : - [ -x ${bin_dir}/taosdemo ] && ${csudo} ln -s ${bin_dir}/taosdemo ${bin_link_dir}/taosdemo || : - [ -x ${bin_dir}/taosdump ] && ${csudo} ln -s ${bin_dir}/taosdump ${bin_link_dir}/taosdump || : - [ -x ${bin_dir}/set_core.sh ] && ${csudo} ln -s ${bin_dir}/set_core.sh ${bin_link_dir}/set_core || : + [ -x ${bin_dir}/taos ] && ${csudo}ln -s ${bin_dir}/taos ${bin_link_dir}/taos || : + [ -x ${bin_dir}/taosd ] && ${csudo}ln -s ${bin_dir}/taosd ${bin_link_dir}/taosd || : + [ -x ${bin_dir}/taosadapter ] && ${csudo}ln -s ${bin_dir}/taosadapter ${bin_link_dir}/taosadapter || : + [ -x ${bin_dir}/taosdemo ] && ${csudo}ln -s ${bin_dir}/taosdemo ${bin_link_dir}/taosdemo || : + [ -x ${bin_dir}/taosdump ] && ${csudo}ln -s ${bin_dir}/taosdump ${bin_link_dir}/taosdump || : + [ -x ${bin_dir}/set_core.sh ] && ${csudo}ln -s ${bin_dir}/set_core.sh ${bin_link_dir}/set_core || : } function add_newHostname_to_hosts() { @@ -136,7 +136,7 @@ function add_newHostname_to_hosts() { return fi done - ${csudo} echo "127.0.0.1 $1" >> /etc/hosts ||: + ${csudo}echo "127.0.0.1 $1" >> /etc/hosts ||: } function set_hostname() { @@ -150,7 +150,7 @@ function set_hostname() { fi done - ${csudo} hostname $newHostname ||: + ${csudo}hostname $newHostname ||: retval=`echo $?` if [[ $retval != 0 ]]; then echo @@ -163,15 +163,15 @@ function set_hostname() { #ubuntu/centos /etc/hostname if [[ -e /etc/hostname ]]; then - ${csudo} echo $newHostname > /etc/hostname ||: + ${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 ||: + ${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}/taos.cfg + ${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$newHostname/" ${cfg_install_dir}/taos.cfg serverFqdn=$newHostname if [[ -e /etc/hosts ]]; then @@ -206,7 +206,7 @@ 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}/taos.cfg + ${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${cfg_install_dir}/taos.cfg serverFqdn=$localFqdn echo return @@ -228,7 +228,7 @@ function set_ipAsFqdn() { 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}/taos.cfg + ${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${cfg_install_dir}/taos.cfg serverFqdn=$localFqdn break fi @@ -277,24 +277,24 @@ function local_fqdn_check() { function install_taosadapter_config() { if [ ! -f "${cfg_install_dir}/taosadapter.toml" ]; then [ ! -d %{cfg_install_dir} ] && - ${csudo} ${csudo} mkdir -p ${cfg_install_dir} - [ -f ${cfg_dir}/taosadapter.toml ] && ${csudo} cp ${cfg_dir}/taosadapter.toml ${cfg_install_dir} + ${csudo}${csudo}mkdir -p ${cfg_install_dir} + [ -f ${cfg_dir}/taosadapter.toml ] && ${csudo}cp ${cfg_dir}/taosadapter.toml ${cfg_install_dir} [ -f ${cfg_install_dir}/taosadapter.toml ] && - ${csudo} chmod 644 ${cfg_install_dir}/taosadapter.toml + ${csudo}chmod 644 ${cfg_install_dir}/taosadapter.toml fi [ -f ${cfg_dir}/taosadapter.toml ] && - ${csudo} mv ${cfg_dir}/taosadapter.toml ${cfg_dir}/taosadapter.toml.new + ${csudo}mv ${cfg_dir}/taosadapter.toml ${cfg_dir}/taosadapter.toml.new [ -f ${cfg_install_dir}/taosadapter.toml ] && - ${csudo} ln -s ${cfg_install_dir}/taosadapter.toml ${cfg_dir} + ${csudo}ln -s ${cfg_install_dir}/taosadapter.toml ${cfg_dir} } function install_config() { if [ ! -f "${cfg_install_dir}/taos.cfg" ]; then - ${csudo} ${csudo} mkdir -p ${cfg_install_dir} - [ -f ${cfg_dir}/taos.cfg ] && ${csudo} cp ${cfg_dir}/taos.cfg ${cfg_install_dir} - ${csudo} chmod 644 ${cfg_install_dir}/* + ${csudo}${csudo}mkdir -p ${cfg_install_dir} + [ -f ${cfg_dir}/taos.cfg ] && ${csudo}cp ${cfg_dir}/taos.cfg ${cfg_install_dir} + ${csudo}chmod 644 ${cfg_install_dir}/* fi # Save standard input to 6 and open / dev / TTY on standard input @@ -305,8 +305,8 @@ function install_config() { # restore the backup standard input, and turn off 6 exec 0<&6 6<&- - ${csudo} mv ${cfg_dir}/taos.cfg ${cfg_dir}/taos.cfg.new - ${csudo} ln -s ${cfg_install_dir}/taos.cfg ${cfg_dir} + ${csudo}mv ${cfg_dir}/taos.cfg ${cfg_dir}/taos.cfg.new + ${csudo}ln -s ${cfg_install_dir}/taos.cfg ${cfg_dir} #FQDN_FORMAT="(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" #FQDN_FORMAT="(:[1-6][0-9][0-9][0-9][0-9]$)" #PORT_FORMAT="(/[1-6][0-9][0-9][0-9][0-9]?/)" @@ -326,7 +326,7 @@ function install_config() { # check the format of the firstEp #if [[ $firstEp == $FQDN_PATTERN ]]; then # Write the first FQDN to configuration file - ${csudo} sed -i -r "s/#*\s*(firstEp\s*).*/\1$firstEp/" ${cfg_install_dir}/taos.cfg + ${csudo}sed -i -r "s/#*\s*(firstEp\s*).*/\1$firstEp/" ${cfg_install_dir}/taos.cfg break #else # read -p "Please enter the correct FQDN:port: " firstEp @@ -349,7 +349,7 @@ function install_config() { #if [[ "$emailAddr" =~ $EMAIL_PATTERN ]]; then # Write the email address to temp file email_file="${install_main_dir}/email" - ${csudo} bash -c "echo $emailAddr > ${email_file}" + ${csudo}bash -c "echo $emailAddr > ${email_file}" break #else # read -p "Please enter the correct email address: " emailAddr @@ -362,24 +362,24 @@ function install_config() { function clean_service_on_sysvinit() { #restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" - #${csudo} sed -i "\|${restart_config_str}|d" /etc/inittab || : + #${csudo}sed -i "\|${restart_config_str}|d" /etc/inittab || : if pidof taosd &> /dev/null; then - ${csudo} service taosd stop || : + ${csudo}service taosd stop || : fi if ((${initd_mod}==1)); then - ${csudo} chkconfig --del taosd || : + ${csudo}chkconfig --del taosd || : elif ((${initd_mod}==2)); then - ${csudo} insserv -r taosd || : + ${csudo}insserv -r taosd || : elif ((${initd_mod}==3)); then - ${csudo} update-rc.d -f taosd remove || : + ${csudo}update-rc.d -f taosd remove || : fi - ${csudo} rm -f ${service_config_dir}/taosd || : + ${csudo}rm -f ${service_config_dir}/taosd || : if $(which init &> /dev/null); then - ${csudo} init q || : + ${csudo}init q || : fi } @@ -389,19 +389,19 @@ function install_service_on_sysvinit() { sleep 1 # Install taosd service - ${csudo} cp %{init_d_dir}/taosd ${service_config_dir} && ${csudo} chmod a+x ${service_config_dir}/taosd + ${csudo}cp %{init_d_dir}/taosd ${service_config_dir} && ${csudo}chmod a+x ${service_config_dir}/taosd #restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" - #${csudo} grep -q -F "$restart_config_str" /etc/inittab || ${csudo} bash -c "echo '${restart_config_str}' >> /etc/inittab" + #${csudo}grep -q -F "$restart_config_str" /etc/inittab || ${csudo}bash -c "echo '${restart_config_str}' >> /etc/inittab" if ((${initd_mod}==1)); then - ${csudo} chkconfig --add taosd || : - ${csudo} chkconfig --level 2345 taosd on || : + ${csudo}chkconfig --add taosd || : + ${csudo}chkconfig --level 2345 taosd on || : elif ((${initd_mod}==2)); then - ${csudo} insserv taosd || : - ${csudo} insserv -d taosd || : + ${csudo}insserv taosd || : + ${csudo}insserv -d taosd || : elif ((${initd_mod}==3)); then - ${csudo} update-rc.d taosd defaults || : + ${csudo}update-rc.d taosd defaults || : fi } @@ -411,11 +411,11 @@ function clean_service_on_systemd() { # taosd service already is stoped before install in preinst script #if systemctl is-active --quiet taosd; then # echo "TDengine is running, stopping it..." - # ${csudo} systemctl stop taosd &> /dev/null || echo &> /dev/null + # ${csudo}systemctl stop taosd &> /dev/null || echo &> /dev/null #fi - ${csudo} systemctl disable taosd &> /dev/null || echo &> /dev/null + ${csudo}systemctl disable taosd &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${taosd_service_config} + ${csudo}rm -f ${taosd_service_config} } # taos:2345:respawn:/etc/init.d/taosd start @@ -425,36 +425,36 @@ function install_service_on_systemd() { taosd_service_config="${service_config_dir}/taosd.service" - ${csudo} bash -c "echo '[Unit]' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'Description=TDengine server service' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'After=network-online.target taosadapter.service' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'Wants=network-online.target taosadapter.service' >> ${taosd_service_config}" - ${csudo} bash -c "echo >> ${taosd_service_config}" - ${csudo} bash -c "echo '[Service]' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'Type=simple' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'ExecStart=/usr/bin/taosd' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'ExecStartPre=/usr/local/taos/bin/startPre.sh' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'LimitCORE=infinity' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'StandardOutput=null' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'Restart=always' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'StartLimitBurst=3' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${taosd_service_config}" - ${csudo} bash -c "echo >> ${taosd_service_config}" - ${csudo} bash -c "echo '[Install]' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${taosd_service_config}" - ${csudo} systemctl enable taosd + ${csudo}bash -c "echo '[Unit]' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'Description=TDengine server service' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'After=network-online.target taosadapter.service' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'Wants=network-online.target taosadapter.service' >> ${taosd_service_config}" + ${csudo}bash -c "echo >> ${taosd_service_config}" + ${csudo}bash -c "echo '[Service]' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'Type=simple' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'ExecStart=/usr/bin/taosd' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'ExecStartPre=/usr/local/taos/bin/startPre.sh' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'TimeoutStopSec=1000000s' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'LimitNOFILE=infinity' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'LimitNPROC=infinity' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'LimitCORE=infinity' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'TimeoutStartSec=0' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'StandardOutput=null' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'Restart=always' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'StartLimitBurst=3' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'StartLimitInterval=60s' >> ${taosd_service_config}" + ${csudo}bash -c "echo >> ${taosd_service_config}" + ${csudo}bash -c "echo '[Install]' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'WantedBy=multi-user.target' >> ${taosd_service_config}" + ${csudo}systemctl enable taosd } function install_taosadapter_service() { if ((${service_mod}==0)); then [ -f ${script_dir}/../cfg/taosadapter.service ] &&\ - ${csudo} cp ${script_dir}/../cfg/taosadapter.service \ + ${csudo}cp ${script_dir}/../cfg/taosadapter.service \ ${service_config_dir}/ || : - ${csudo} systemctl daemon-reload + ${csudo}systemctl daemon-reload fi } @@ -474,14 +474,14 @@ function install_TDengine() { echo -e "${GREEN}Start to install TDengine...${NC}" #install log and data dir , then ln to /usr/local/taos - ${csudo} mkdir -p ${log_dir} && ${csudo} chmod 777 ${log_dir} - ${csudo} mkdir -p ${data_dir} + ${csudo}mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir} + ${csudo}mkdir -p ${data_dir} - ${csudo} rm -rf ${log_link_dir} || : - ${csudo} rm -rf ${data_link_dir} || : + ${csudo}rm -rf ${log_link_dir} || : + ${csudo}rm -rf ${data_link_dir} || : - ${csudo} ln -s ${log_dir} ${log_link_dir} || : - ${csudo} ln -s ${data_dir} ${data_link_dir} || : + ${csudo}ln -s ${log_dir} ${log_link_dir} || : + ${csudo}ln -s ${data_dir} ${data_link_dir} || : # Install include, lib, binary and service install_include @@ -498,10 +498,10 @@ function install_TDengine() { echo echo -e "${GREEN_DARK}To configure TDengine ${NC}: edit /etc/taos/taos.cfg" if ((${service_mod}==0)); then - echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} systemctl start taosd${NC}" + echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo}systemctl start taosd${NC}" elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} update-rc.d taosd default ${RED} for the first time${NC}" - echo -e " : ${csudo} service taosd start ${RED} after${NC}" + echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo}update-rc.d taosd default ${RED} for the first time${NC}" + echo -e " : ${csudo}service taosd start ${RED} after${NC}" else echo -e "${GREEN_DARK}To start TDengine ${NC}: ./taosd${NC}" fi diff --git a/packaging/tools/preun.sh b/packaging/tools/preun.sh index 43fead76ba675dfa8ee45422d9f9dc8166b2488d..27dc830a1f189d196a5b937f71dbafc776d035d4 100755 --- a/packaging/tools/preun.sh +++ b/packaging/tools/preun.sh @@ -20,7 +20,7 @@ taos_service_name="taosd" csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi initd_mod=0 @@ -46,14 +46,14 @@ fi function kill_taosadapter() { pid=$(ps -ef | grep "taosadapter" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function kill_taosd() { pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } @@ -61,44 +61,44 @@ function clean_service_on_systemd() { taosadapter_service_config="${service_config_dir}/taosadapter.service" if systemctl is-active --quiet taosadapter; then echo "taosadapter is running, stopping it..." - ${csudo} systemctl stop taosadapter &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop taosadapter &> /dev/null || echo &> /dev/null fi 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..." - ${csudo} systemctl stop ${taos_service_name} &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop ${taos_service_name} &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable ${taos_service_name} &> /dev/null || echo &> /dev/null + ${csudo}systemctl disable ${taos_service_name} &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${taosd_service_config} + ${csudo}rm -f ${taosd_service_config} - [ -f ${taosadapter_service_config} ] && ${csudo} rm -f ${taosadapter_service_config} + [ -f ${taosadapter_service_config} ] && ${csudo}rm -f ${taosadapter_service_config} } function clean_service_on_sysvinit() { #restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" - #${csudo} sed -i "\|${restart_config_str}|d" /etc/inittab || : + #${csudo}sed -i "\|${restart_config_str}|d" /etc/inittab || : if pidof taosd &> /dev/null; then echo "TDengine taosd is running, stopping it..." - ${csudo} service taosd stop || : + ${csudo}service taosd stop || : fi if ((${initd_mod}==1)); then - ${csudo} chkconfig --del taosd || : + ${csudo}chkconfig --del taosd || : elif ((${initd_mod}==2)); then - ${csudo} insserv -r taosd || : + ${csudo}insserv -r taosd || : elif ((${initd_mod}==3)); then - ${csudo} update-rc.d -f taosd remove || : + ${csudo}update-rc.d -f taosd remove || : fi - ${csudo} rm -f ${service_config_dir}/taosd || : + ${csudo}rm -f ${service_config_dir}/taosd || : if $(which init &> /dev/null); then - ${csudo} init q || : + ${csudo}init q || : fi } @@ -118,20 +118,20 @@ function clean_service() { clean_service # Remove all links -${csudo} rm -f ${bin_link_dir}/taos || : -${csudo} rm -f ${bin_link_dir}/taosd || : -${csudo} rm -f ${bin_link_dir}/taosadapter || : -${csudo} rm -f ${bin_link_dir}/taosdemo || : -${csudo} rm -f ${bin_link_dir}/set_core || : -${csudo} rm -f ${cfg_link_dir}/*.new || : -${csudo} rm -f ${inc_link_dir}/taos.h || : -${csudo} rm -f ${inc_link_dir}/taosdef.h || : -${csudo} rm -f ${inc_link_dir}/taoserror.h || : -${csudo} rm -f ${lib_link_dir}/libtaos.* || : -${csudo} rm -f ${lib64_link_dir}/libtaos.* || : - -${csudo} rm -f ${log_link_dir} || : -${csudo} rm -f ${data_link_dir} || : +${csudo}rm -f ${bin_link_dir}/taos || : +${csudo}rm -f ${bin_link_dir}/taosd || : +${csudo}rm -f ${bin_link_dir}/taosadapter || : +${csudo}rm -f ${bin_link_dir}/taosdemo || : +${csudo}rm -f ${bin_link_dir}/set_core || : +${csudo}rm -f ${cfg_link_dir}/*.new || : +${csudo}rm -f ${inc_link_dir}/taos.h || : +${csudo}rm -f ${inc_link_dir}/taosdef.h || : +${csudo}rm -f ${inc_link_dir}/taoserror.h || : +${csudo}rm -f ${lib_link_dir}/libtaos.* || : +${csudo}rm -f ${lib64_link_dir}/libtaos.* || : + +${csudo}rm -f ${log_link_dir} || : +${csudo}rm -f ${data_link_dir} || : if ((${service_mod}==2)); then kill_taosadapter diff --git a/packaging/tools/remove.sh b/packaging/tools/remove.sh index 4f814692ebaacf8017ede030a977af36528a27c1..b9bd1c163809c1d2dabfff6f85ffaa765378cede 100755 --- a/packaging/tools/remove.sh +++ b/packaging/tools/remove.sh @@ -32,7 +32,7 @@ tarbitrator_service_name="tarbitratord" nginx_service_name="nginxd" csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi initd_mod=0 @@ -58,140 +58,140 @@ fi function kill_taosadapter() { pid=$(ps -ef | grep "taosadapter" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function kill_taosd() { pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function kill_tarbitrator() { pid=$(ps -ef | grep "tarbitrator" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function clean_bin() { # Remove link - ${csudo} rm -f ${bin_link_dir}/taos || : - ${csudo} rm -f ${bin_link_dir}/taosd || : - ${csudo} rm -f ${bin_link_dir}/taosadapter || : - ${csudo} rm -f ${bin_link_dir}/taosdemo || : - ${csudo} rm -f ${bin_link_dir}/taosdump || : - ${csudo} rm -f ${bin_link_dir}/rmtaos || : - ${csudo} rm -f ${bin_link_dir}/tarbitrator || : - ${csudo} rm -f ${bin_link_dir}/set_core || : - ${csudo} rm -f ${bin_link_dir}/run_taosd.sh || : + ${csudo}rm -f ${bin_link_dir}/taos || : + ${csudo}rm -f ${bin_link_dir}/taosd || : + ${csudo}rm -f ${bin_link_dir}/taosadapter || : + ${csudo}rm -f ${bin_link_dir}/taosdemo || : + ${csudo}rm -f ${bin_link_dir}/taosdump || : + ${csudo}rm -f ${bin_link_dir}/rmtaos || : + ${csudo}rm -f ${bin_link_dir}/tarbitrator || : + ${csudo}rm -f ${bin_link_dir}/set_core || : + ${csudo}rm -f ${bin_link_dir}/run_taosd.sh || : } function clean_lib() { # Remove link - ${csudo} rm -f ${lib_link_dir}/libtaos.* || : - ${csudo} rm -f ${lib64_link_dir}/libtaos.* || : - #${csudo} rm -rf ${v15_java_app_dir} || : + ${csudo}rm -f ${lib_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : + #${csudo}rm -rf ${v15_java_app_dir} || : } function clean_header() { # 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 || : + ${csudo}rm -f ${inc_link_dir}/taos.h || : + ${csudo}rm -f ${inc_link_dir}/taosdef.h || : + ${csudo}rm -f ${inc_link_dir}/taoserror.h || : } function clean_config() { # Remove link - ${csudo} rm -f ${cfg_link_dir}/* || : + ${csudo}rm -f ${cfg_link_dir}/* || : } function clean_log() { # Remove link - ${csudo} rm -rf ${log_link_dir} || : + ${csudo}rm -rf ${log_link_dir} || : } 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..." - ${csudo} systemctl stop ${taos_service_name} &> /dev/null || echo &> /dev/null + ${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} + ${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 "TDengine taosAdapter is running, stopping it..." - ${csudo} systemctl stop ${taosadapter_service_name} &> /dev/null || echo &> /dev/null + ${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} + ${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 "TDengine tarbitrator is running, stopping it..." - ${csudo} systemctl stop ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null + ${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} + ${csudo}systemctl disable ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null + ${csudo}rm -f ${tarbitratord_service_config} if [ "$verMode" == "cluster" ]; then nginx_service_config="${service_config_dir}/${nginx_service_name}.service" if [ -d ${install_nginxd_dir} ]; then if systemctl is-active --quiet ${nginx_service_name}; then echo "Nginx for TDengine is running, stopping it..." - ${csudo} systemctl stop ${nginx_service_name} &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop ${nginx_service_name} &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable ${nginx_service_name} &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${nginx_service_config} + ${csudo}systemctl disable ${nginx_service_name} &> /dev/null || echo &> /dev/null + ${csudo}rm -f ${nginx_service_config} fi fi } function clean_service_on_sysvinit() { #restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" - #${csudo} sed -i "\|${restart_config_str}|d" /etc/inittab || : + #${csudo}sed -i "\|${restart_config_str}|d" /etc/inittab || : if pidof taosd &> /dev/null; then echo "TDengine taosd is running, stopping it..." - ${csudo} service taosd stop || : + ${csudo}service taosd stop || : fi if pidof tarbitrator &> /dev/null; then echo "TDengine tarbitrator is running, stopping it..." - ${csudo} service tarbitratord stop || : + ${csudo}service tarbitratord stop || : fi if ((${initd_mod}==1)); then if [ -e ${service_config_dir}/taosd ]; then - ${csudo} chkconfig --del taosd || : + ${csudo}chkconfig --del taosd || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} chkconfig --del tarbitratord || : + ${csudo}chkconfig --del tarbitratord || : fi elif ((${initd_mod}==2)); then if [ -e ${service_config_dir}/taosd ]; then - ${csudo} insserv -r taosd || : + ${csudo}insserv -r taosd || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} insserv -r tarbitratord || : + ${csudo}insserv -r tarbitratord || : fi elif ((${initd_mod}==3)); then if [ -e ${service_config_dir}/taosd ]; then - ${csudo} update-rc.d -f taosd remove || : + ${csudo}update-rc.d -f taosd remove || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} update-rc.d -f tarbitratord remove || : + ${csudo}update-rc.d -f tarbitratord remove || : fi fi - ${csudo} rm -f ${service_config_dir}/taosd || : - ${csudo} rm -f ${service_config_dir}/tarbitratord || : + ${csudo}rm -f ${service_config_dir}/taosd || : + ${csudo}rm -f ${service_config_dir}/tarbitratord || : if $(which init &> /dev/null); then - ${csudo} init q || : + ${csudo}init q || : fi } @@ -221,10 +221,10 @@ clean_log # Remove link configuration file clean_config # Remove data link directory -${csudo} rm -rf ${data_link_dir} || : +${csudo}rm -rf ${data_link_dir} || : -${csudo} rm -rf ${install_main_dir} -${csudo} rm -rf ${install_nginxd_dir} +${csudo}rm -rf ${install_main_dir} +${csudo}rm -rf ${install_nginxd_dir} if [[ -e /etc/os-release ]]; then osinfo=$(awk -F= '/^NAME/{print $2}' /etc/os-release) else @@ -233,13 +233,13 @@ fi if echo $osinfo | grep -qwi "ubuntu" ; then # echo "this is ubuntu system" - ${csudo} dpkg --force-all -P tdengine > /dev/null 2>&1 || : + ${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 || : + ${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 || : + ${csudo}rpm -e --noscripts tdengine > /dev/null 2>&1 || : fi echo -e "${GREEN}TDengine is removed successfully!${NC}" diff --git a/packaging/tools/remove_arbi.sh b/packaging/tools/remove_arbi.sh index 4495f25f3617c3c28c6dbd22ddeeda93cdf5423a..0a1162cd7a6793d8542ad5079b8c8cce1659724a 100755 --- a/packaging/tools/remove_arbi.sh +++ b/packaging/tools/remove_arbi.sh @@ -20,7 +20,7 @@ service_config_dir="/etc/systemd/system" tarbitrator_service_name="tarbitratord" csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi initd_mod=0 @@ -46,24 +46,24 @@ fi function kill_tarbitrator() { pid=$(ps -ef | grep "tarbitrator" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function clean_bin() { # Remove link - ${csudo} rm -f ${bin_link_dir}/tarbitrator || : + ${csudo}rm -f ${bin_link_dir}/tarbitrator || : } function clean_header() { # 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 || : + ${csudo}rm -f ${inc_link_dir}/taos.h || : + ${csudo}rm -f ${inc_link_dir}/taosdef.h || : + ${csudo}rm -f ${inc_link_dir}/taoserror.h || : } function clean_log() { # Remove link - ${csudo} rm -rf /arbitrator.log || : + ${csudo}rm -rf /arbitrator.log || : } function clean_service_on_systemd() { @@ -71,37 +71,37 @@ function clean_service_on_systemd() { if systemctl is-active --quiet ${tarbitrator_service_name}; then echo "TDengine tarbitrator is running, stopping it..." - ${csudo} systemctl stop ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null + ${csudo}systemctl disable ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${tarbitratord_service_config} + ${csudo}rm -f ${tarbitratord_service_config} } function clean_service_on_sysvinit() { if pidof tarbitrator &> /dev/null; then echo "TDengine's tarbitrator is running, stopping it..." - ${csudo} service tarbitratord stop || : + ${csudo}service tarbitratord stop || : fi if ((${initd_mod}==1)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} chkconfig --del tarbitratord || : + ${csudo}chkconfig --del tarbitratord || : fi elif ((${initd_mod}==2)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} insserv -r tarbitratord || : + ${csudo}insserv -r tarbitratord || : fi elif ((${initd_mod}==3)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} update-rc.d -f tarbitratord remove || : + ${csudo}update-rc.d -f tarbitratord remove || : fi fi - ${csudo} rm -f ${service_config_dir}/tarbitratord || : + ${csudo}rm -f ${service_config_dir}/tarbitratord || : if $(which init &> /dev/null); then - ${csudo} init q || : + ${csudo}init q || : fi } @@ -125,6 +125,6 @@ clean_bin # Remove log file clean_log -${csudo} rm -rf ${install_main_dir} +${csudo}rm -rf ${install_main_dir} echo -e "${GREEN}TDengine's arbitrator is removed successfully!${NC}" diff --git a/packaging/tools/remove_arbi_jh.sh b/packaging/tools/remove_arbi_jh.sh index 8b690771c761ac51772dac83cafec46360a16be3..018bf793d9df80ed5076fa15e3714975e2c3ea80 100755 --- a/packaging/tools/remove_arbi_jh.sh +++ b/packaging/tools/remove_arbi_jh.sh @@ -19,7 +19,7 @@ service_config_dir="/etc/systemd/system" tarbitrator_service_name="tarbitratord" csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi initd_mod=0 @@ -45,24 +45,24 @@ fi function kill_tarbitrator() { pid=$(ps -ef | grep "tarbitrator" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function clean_bin() { # Remove link - ${csudo} rm -f ${bin_link_dir}/tarbitrator || : + ${csudo}rm -f ${bin_link_dir}/tarbitrator || : } function clean_header() { # Remove link - ${csudo} rm -f ${inc_link_dir}/taos.h || : - ${csudo} rm -f ${inc_link_dir}/taoserror.h || : + ${csudo}rm -f ${inc_link_dir}/taos.h || : + ${csudo}rm -f ${inc_link_dir}/taoserror.h || : } function clean_log() { # Remove link - ${csudo} rm -rf /arbitrator.log || : + ${csudo}rm -rf /arbitrator.log || : } function clean_service_on_systemd() { @@ -70,37 +70,37 @@ function clean_service_on_systemd() { if systemctl is-active --quiet ${tarbitrator_service_name}; then echo "jh_iot's tarbitrator is running, stopping it..." - ${csudo} systemctl stop ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null + ${csudo}systemctl disable ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${tarbitratord_service_config} + ${csudo}rm -f ${tarbitratord_service_config} } function clean_service_on_sysvinit() { if pidof tarbitrator &> /dev/null; then echo "jh_iot's tarbitrator is running, stopping it..." - ${csudo} service tarbitratord stop || : + ${csudo}service tarbitratord stop || : fi if ((${initd_mod}==1)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} chkconfig --del tarbitratord || : + ${csudo}chkconfig --del tarbitratord || : fi elif ((${initd_mod}==2)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} insserv -r tarbitratord || : + ${csudo}insserv -r tarbitratord || : fi elif ((${initd_mod}==3)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} update-rc.d -f tarbitratord remove || : + ${csudo}update-rc.d -f tarbitratord remove || : fi fi - ${csudo} rm -f ${service_config_dir}/tarbitratord || : + ${csudo}rm -f ${service_config_dir}/tarbitratord || : if $(which init &> /dev/null); then - ${csudo} init q || : + ${csudo}init q || : fi } @@ -124,7 +124,7 @@ clean_bin # Remove log file clean_log -${csudo} rm -rf ${install_main_dir} +${csudo}rm -rf ${install_main_dir} echo -e "${GREEN}jh_iot's arbitrator is removed successfully!${NC}" echo diff --git a/packaging/tools/remove_arbi_kh.sh b/packaging/tools/remove_arbi_kh.sh index ec3254b01649add57f9485c59878059e086b2669..2d270ea0bef735e1c307970e4d5b45d6eca56622 100755 --- a/packaging/tools/remove_arbi_kh.sh +++ b/packaging/tools/remove_arbi_kh.sh @@ -19,7 +19,7 @@ service_config_dir="/etc/systemd/system" tarbitrator_service_name="tarbitratord" csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi initd_mod=0 @@ -45,24 +45,24 @@ fi function kill_tarbitrator() { pid=$(ps -ef | grep "tarbitrator" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function clean_bin() { # Remove link - ${csudo} rm -f ${bin_link_dir}/tarbitrator || : + ${csudo}rm -f ${bin_link_dir}/tarbitrator || : } function clean_header() { # Remove link - ${csudo} rm -f ${inc_link_dir}/taos.h || : - ${csudo} rm -f ${inc_link_dir}/taoserror.h || : + ${csudo}rm -f ${inc_link_dir}/taos.h || : + ${csudo}rm -f ${inc_link_dir}/taoserror.h || : } function clean_log() { # Remove link - ${csudo} rm -rf /arbitrator.log || : + ${csudo}rm -rf /arbitrator.log || : } function clean_service_on_systemd() { @@ -70,37 +70,37 @@ function clean_service_on_systemd() { if systemctl is-active --quiet ${tarbitrator_service_name}; then echo "KingHistorian's tarbitrator is running, stopping it..." - ${csudo} systemctl stop ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null + ${csudo}systemctl disable ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${tarbitratord_service_config} + ${csudo}rm -f ${tarbitratord_service_config} } function clean_service_on_sysvinit() { if pidof tarbitrator &> /dev/null; then echo "KingHistorian's tarbitrator is running, stopping it..." - ${csudo} service tarbitratord stop || : + ${csudo}service tarbitratord stop || : fi if ((${initd_mod}==1)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} chkconfig --del tarbitratord || : + ${csudo}chkconfig --del tarbitratord || : fi elif ((${initd_mod}==2)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} insserv -r tarbitratord || : + ${csudo}insserv -r tarbitratord || : fi elif ((${initd_mod}==3)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} update-rc.d -f tarbitratord remove || : + ${csudo}update-rc.d -f tarbitratord remove || : fi fi - ${csudo} rm -f ${service_config_dir}/tarbitratord || : + ${csudo}rm -f ${service_config_dir}/tarbitratord || : if $(which init &> /dev/null); then - ${csudo} init q || : + ${csudo}init q || : fi } @@ -124,7 +124,7 @@ clean_bin # Remove log file clean_log -${csudo} rm -rf ${install_main_dir} +${csudo}rm -rf ${install_main_dir} echo -e "${GREEN}KingHistorian's arbitrator is removed successfully!${NC}" echo diff --git a/packaging/tools/remove_arbi_power.sh b/packaging/tools/remove_arbi_power.sh index 27b08a47e87c28395faa004515702d9e1b51492a..459ca481e32954e8472f5f1c108a597fd59ff129 100755 --- a/packaging/tools/remove_arbi_power.sh +++ b/packaging/tools/remove_arbi_power.sh @@ -20,7 +20,7 @@ service_config_dir="/etc/systemd/system" tarbitrator_service_name="tarbitratord" csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi initd_mod=0 @@ -46,24 +46,24 @@ fi function kill_tarbitrator() { pid=$(ps -ef | grep "tarbitrator" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function clean_bin() { # Remove link - ${csudo} rm -f ${bin_link_dir}/tarbitrator || : + ${csudo}rm -f ${bin_link_dir}/tarbitrator || : } function clean_header() { # 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 || : + ${csudo}rm -f ${inc_link_dir}/taos.h || : + ${csudo}rm -f ${inc_link_dir}/taosdef.h || : + ${csudo}rm -f ${inc_link_dir}/taoserror.h || : } function clean_log() { # Remove link - ${csudo} rm -rf /arbitrator.log || : + ${csudo}rm -rf /arbitrator.log || : } function clean_service_on_systemd() { @@ -71,37 +71,37 @@ function clean_service_on_systemd() { if systemctl is-active --quiet ${tarbitrator_service_name}; then echo "PowerDB tarbitrator is running, stopping it..." - ${csudo} systemctl stop ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null + ${csudo}systemctl disable ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${tarbitratord_service_config} + ${csudo}rm -f ${tarbitratord_service_config} } function clean_service_on_sysvinit() { if pidof tarbitrator &> /dev/null; then echo "PowerDB's tarbitrator is running, stopping it..." - ${csudo} service tarbitratord stop || : + ${csudo}service tarbitratord stop || : fi if ((${initd_mod}==1)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} chkconfig --del tarbitratord || : + ${csudo}chkconfig --del tarbitratord || : fi elif ((${initd_mod}==2)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} insserv -r tarbitratord || : + ${csudo}insserv -r tarbitratord || : fi elif ((${initd_mod}==3)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} update-rc.d -f tarbitratord remove || : + ${csudo}update-rc.d -f tarbitratord remove || : fi fi - ${csudo} rm -f ${service_config_dir}/tarbitratord || : + ${csudo}rm -f ${service_config_dir}/tarbitratord || : if $(which init &> /dev/null); then - ${csudo} init q || : + ${csudo}init q || : fi } @@ -125,7 +125,7 @@ clean_bin # Remove log file clean_log -${csudo} rm -rf ${install_main_dir} +${csudo}rm -rf ${install_main_dir} echo -e "${GREEN}PowerDB's arbitrator is removed successfully!${NC}" echo diff --git a/packaging/tools/remove_arbi_pro.sh b/packaging/tools/remove_arbi_pro.sh index 4bb435cc97e7b31341007ac56c6eb1bbe75a9fda..4a5edff1c6f9b006085977a2c3bf9c9e4fa24326 100755 --- a/packaging/tools/remove_arbi_pro.sh +++ b/packaging/tools/remove_arbi_pro.sh @@ -19,7 +19,7 @@ service_config_dir="/etc/systemd/system" tarbitrator_service_name="tarbitratord" csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi initd_mod=0 @@ -45,25 +45,25 @@ fi function kill_tarbitrator() { pid=$(ps -ef | grep "tarbitrator" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function clean_bin() { # Remove link - ${csudo} rm -f ${bin_link_dir}/tarbitrator || : + ${csudo}rm -f ${bin_link_dir}/tarbitrator || : } function clean_header() { # 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 || : + ${csudo}rm -f ${inc_link_dir}/taos.h || : + ${csudo}rm -f ${inc_link_dir}/taosdef.h || : + ${csudo}rm -f ${inc_link_dir}/taoserror.h || : } function clean_log() { # Remove link - ${csudo} rm -rf /arbitrator.log || : + ${csudo}rm -rf /arbitrator.log || : } function clean_service_on_systemd() { @@ -71,37 +71,37 @@ function clean_service_on_systemd() { if systemctl is-active --quiet ${tarbitrator_service_name}; then echo "ProDB tarbitrator is running, stopping it..." - ${csudo} systemctl stop ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null + ${csudo}systemctl disable ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${tarbitratord_service_config} + ${csudo}rm -f ${tarbitratord_service_config} } function clean_service_on_sysvinit() { if pidof tarbitrator &> /dev/null; then echo "ProDB's tarbitrator is running, stopping it..." - ${csudo} service tarbitratord stop || : + ${csudo}service tarbitratord stop || : fi if ((${initd_mod}==1)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} chkconfig --del tarbitratord || : + ${csudo}chkconfig --del tarbitratord || : fi elif ((${initd_mod}==2)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} insserv -r tarbitratord || : + ${csudo}insserv -r tarbitratord || : fi elif ((${initd_mod}==3)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} update-rc.d -f tarbitratord remove || : + ${csudo}update-rc.d -f tarbitratord remove || : fi fi - ${csudo} rm -f ${service_config_dir}/tarbitratord || : + ${csudo}rm -f ${service_config_dir}/tarbitratord || : if $(which init &> /dev/null); then - ${csudo} init q || : + ${csudo}init q || : fi } @@ -125,7 +125,7 @@ clean_bin # Remove log file clean_log -${csudo} rm -rf ${install_main_dir} +${csudo}rm -rf ${install_main_dir} echo -e "${GREEN}ProDB's arbitrator is removed successfully!${NC}" echo diff --git a/packaging/tools/remove_arbi_tq.sh b/packaging/tools/remove_arbi_tq.sh index e0b401255f1071a21f0a5e09cd9b6e0e307ec5ba..f1b5bed44080f0631689098c6990a5cecdd186f1 100755 --- a/packaging/tools/remove_arbi_tq.sh +++ b/packaging/tools/remove_arbi_tq.sh @@ -20,7 +20,7 @@ service_config_dir="/etc/systemd/system" tarbitrator_service_name="tarbitratord" csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi initd_mod=0 @@ -46,24 +46,24 @@ fi function kill_tarbitrator() { pid=$(ps -ef | grep "tarbitrator" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function clean_bin() { # Remove link - ${csudo} rm -f ${bin_link_dir}/tarbitrator || : + ${csudo}rm -f ${bin_link_dir}/tarbitrator || : } function clean_header() { # 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 || : + ${csudo}rm -f ${inc_link_dir}/taos.h || : + ${csudo}rm -f ${inc_link_dir}/taosdef.h || : + ${csudo}rm -f ${inc_link_dir}/taoserror.h || : } function clean_log() { # Remove link - ${csudo} rm -rf /arbitrator.log || : + ${csudo}rm -rf /arbitrator.log || : } function clean_service_on_systemd() { @@ -71,37 +71,37 @@ function clean_service_on_systemd() { if systemctl is-active --quiet ${tarbitrator_service_name}; then echo "TQ tarbitrator is running, stopping it..." - ${csudo} systemctl stop ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null + ${csudo}systemctl disable ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${tarbitratord_service_config} + ${csudo}rm -f ${tarbitratord_service_config} } function clean_service_on_sysvinit() { if pidof tarbitrator &> /dev/null; then echo "TQ's tarbitrator is running, stopping it..." - ${csudo} service tarbitratord stop || : + ${csudo}service tarbitratord stop || : fi if ((${initd_mod}==1)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} chkconfig --del tarbitratord || : + ${csudo}chkconfig --del tarbitratord || : fi elif ((${initd_mod}==2)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} insserv -r tarbitratord || : + ${csudo}insserv -r tarbitratord || : fi elif ((${initd_mod}==3)); then if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} update-rc.d -f tarbitratord remove || : + ${csudo}update-rc.d -f tarbitratord remove || : fi fi - ${csudo} rm -f ${service_config_dir}/tarbitratord || : + ${csudo}rm -f ${service_config_dir}/tarbitratord || : if $(which init &> /dev/null); then - ${csudo} init q || : + ${csudo}init q || : fi } @@ -125,7 +125,7 @@ clean_bin # Remove log file clean_log -${csudo} rm -rf ${install_main_dir} +${csudo}rm -rf ${install_main_dir} echo -e "${GREEN}TQ's arbitrator is removed successfully!${NC}" echo diff --git a/packaging/tools/remove_client.sh b/packaging/tools/remove_client.sh index aad8d67d948d566b72820625391ba7592859c079..b7e5a327bfd3b7d81520737b252111889660084d 100755 --- a/packaging/tools/remove_client.sh +++ b/packaging/tools/remove_client.sh @@ -24,47 +24,47 @@ inc_link_dir="/usr/include" csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi function kill_client() { #pid=$(ps -ef | grep "taos" | grep -v "grep" | awk '{print $2}') if [ -n "$(pidof taos)" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function clean_bin() { # Remove link - ${csudo} rm -f ${bin_link_dir}/taos || : - ${csudo} rm -f ${bin_link_dir}/taosdemo || : - ${csudo} rm -f ${bin_link_dir}/taosdump || : - ${csudo} rm -f ${bin_link_dir}/rmtaos || : - ${csudo} rm -f ${bin_link_dir}/set_core || : + ${csudo}rm -f ${bin_link_dir}/taos || : + ${csudo}rm -f ${bin_link_dir}/taosdemo || : + ${csudo}rm -f ${bin_link_dir}/taosdump || : + ${csudo}rm -f ${bin_link_dir}/rmtaos || : + ${csudo}rm -f ${bin_link_dir}/set_core || : } function clean_lib() { # Remove link - ${csudo} rm -f ${lib_link_dir}/libtaos.* || : - ${csudo} rm -f ${lib64_link_dir}/libtaos.* || : - #${csudo} rm -rf ${v15_java_app_dir} || : + ${csudo}rm -f ${lib_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : + #${csudo}rm -rf ${v15_java_app_dir} || : } function clean_header() { # 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 || : + ${csudo}rm -f ${inc_link_dir}/taos.h || : + ${csudo}rm -f ${inc_link_dir}/taosdef.h || : + ${csudo}rm -f ${inc_link_dir}/taoserror.h || : } function clean_config() { # Remove link - ${csudo} rm -f ${cfg_link_dir}/* || : + ${csudo}rm -f ${cfg_link_dir}/* || : } function clean_log() { # Remove link - ${csudo} rm -rf ${log_link_dir} || : + ${csudo}rm -rf ${log_link_dir} || : } # Stop client. @@ -80,7 +80,7 @@ clean_log # Remove link configuration file clean_config -${csudo} rm -rf ${install_main_dir} +${csudo}rm -rf ${install_main_dir} echo -e "${GREEN}TDengine client is removed successfully!${NC}" echo diff --git a/packaging/tools/remove_client_jh.sh b/packaging/tools/remove_client_jh.sh index a3f5dfd10debb0a28211b3682becd083d49ca9c6..491339fb450f9017004f312032ff5f2dbcaa4164 100755 --- a/packaging/tools/remove_client_jh.sh +++ b/packaging/tools/remove_client_jh.sh @@ -20,44 +20,44 @@ inc_link_dir="/usr/include" csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi function kill_client() { if [ -n "$(pidof jh_taos)" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function clean_bin() { # Remove link - ${csudo} rm -f ${bin_link_dir}/jh_taos || : - ${csudo} rm -f ${bin_link_dir}/jhdemo || : - ${csudo} rm -f ${bin_link_dir}/jh_taosdump || : - ${csudo} rm -f ${bin_link_dir}/rmjh || : - ${csudo} rm -f ${bin_link_dir}/set_core || : + ${csudo}rm -f ${bin_link_dir}/jh_taos || : + ${csudo}rm -f ${bin_link_dir}/jhdemo || : + ${csudo}rm -f ${bin_link_dir}/jh_taosdump || : + ${csudo}rm -f ${bin_link_dir}/rmjh || : + ${csudo}rm -f ${bin_link_dir}/set_core || : } function clean_lib() { # Remove link - ${csudo} rm -f ${lib_link_dir}/libtaos.* || : - ${csudo} rm -f ${lib64_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : } function clean_header() { # Remove link - ${csudo} rm -f ${inc_link_dir}/taos.h || : - ${csudo} rm -f ${inc_link_dir}/taoserror.h || : + ${csudo}rm -f ${inc_link_dir}/taos.h || : + ${csudo}rm -f ${inc_link_dir}/taoserror.h || : } function clean_config() { # Remove link - ${csudo} rm -f ${cfg_link_dir}/* || : + ${csudo}rm -f ${cfg_link_dir}/* || : } function clean_log() { # Remove link - ${csudo} rm -rf ${log_link_dir} || : + ${csudo}rm -rf ${log_link_dir} || : } # Stop client. @@ -73,7 +73,7 @@ clean_log # Remove link configuration file clean_config -${csudo} rm -rf ${install_main_dir} +${csudo}rm -rf ${install_main_dir} echo -e "${GREEN}jh_iot client is removed successfully!${NC}" echo diff --git a/packaging/tools/remove_client_kh.sh b/packaging/tools/remove_client_kh.sh index 6a44e875e3426b14400508b1bdbd7510c2ae49cb..56cf49ca820fcc3077c2253d89955048c5ffa273 100755 --- a/packaging/tools/remove_client_kh.sh +++ b/packaging/tools/remove_client_kh.sh @@ -20,44 +20,44 @@ inc_link_dir="/usr/include" csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi function kill_client() { if [ -n "$(pidof khclient)" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function clean_bin() { # Remove link - ${csudo} rm -f ${bin_link_dir}/khclient || : - ${csudo} rm -f ${bin_link_dir}/khdemo || : - ${csudo} rm -f ${bin_link_dir}/khdump || : - ${csudo} rm -f ${bin_link_dir}/rmkh || : - ${csudo} rm -f ${bin_link_dir}/set_core || : + ${csudo}rm -f ${bin_link_dir}/khclient || : + ${csudo}rm -f ${bin_link_dir}/khdemo || : + ${csudo}rm -f ${bin_link_dir}/khdump || : + ${csudo}rm -f ${bin_link_dir}/rmkh || : + ${csudo}rm -f ${bin_link_dir}/set_core || : } function clean_lib() { # Remove link - ${csudo} rm -f ${lib_link_dir}/libtaos.* || : - ${csudo} rm -f ${lib64_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : } function clean_header() { # Remove link - ${csudo} rm -f ${inc_link_dir}/taos.h || : - ${csudo} rm -f ${inc_link_dir}/taoserror.h || : + ${csudo}rm -f ${inc_link_dir}/taos.h || : + ${csudo}rm -f ${inc_link_dir}/taoserror.h || : } function clean_config() { # Remove link - ${csudo} rm -f ${cfg_link_dir}/* || : + ${csudo}rm -f ${cfg_link_dir}/* || : } function clean_log() { # Remove link - ${csudo} rm -rf ${log_link_dir} || : + ${csudo}rm -rf ${log_link_dir} || : } # Stop client. @@ -73,7 +73,7 @@ clean_log # Remove link configuration file clean_config -${csudo} rm -rf ${install_main_dir} +${csudo}rm -rf ${install_main_dir} echo -e "${GREEN}KingHistorian client is removed successfully!${NC}" echo diff --git a/packaging/tools/remove_client_power.sh b/packaging/tools/remove_client_power.sh index 75e9717e54b6e02ad5a5d8b28244caf89ab570fb..f16e7813ef894b23b01b89b365ad2038b5b1bb40 100755 --- a/packaging/tools/remove_client_power.sh +++ b/packaging/tools/remove_client_power.sh @@ -24,47 +24,47 @@ inc_link_dir="/usr/include" csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi function kill_client() { #pid=$(ps -ef | grep "power" | grep -v "grep" | awk '{print $2}') if [ -n "$(pidof power)" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function clean_bin() { # Remove link - ${csudo} rm -f ${bin_link_dir}/power || : - ${csudo} rm -f ${bin_link_dir}/powerdemo || : - ${csudo} rm -f ${bin_link_dir}/powerdump || : - ${csudo} rm -f ${bin_link_dir}/rmpower || : - ${csudo} rm -f ${bin_link_dir}/set_core || : + ${csudo}rm -f ${bin_link_dir}/power || : + ${csudo}rm -f ${bin_link_dir}/powerdemo || : + ${csudo}rm -f ${bin_link_dir}/powerdump || : + ${csudo}rm -f ${bin_link_dir}/rmpower || : + ${csudo}rm -f ${bin_link_dir}/set_core || : } function clean_lib() { # Remove link - ${csudo} rm -f ${lib_link_dir}/libtaos.* || : - ${csudo} rm -f ${lib64_link_dir}/libtaos.* || : - #${csudo} rm -rf ${v15_java_app_dir} || : + ${csudo}rm -f ${lib_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : + #${csudo}rm -rf ${v15_java_app_dir} || : } function clean_header() { # 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 || : + ${csudo}rm -f ${inc_link_dir}/taos.h || : + ${csudo}rm -f ${inc_link_dir}/taosdef.h || : + ${csudo}rm -f ${inc_link_dir}/taoserror.h || : } function clean_config() { # Remove link - ${csudo} rm -f ${cfg_link_dir}/* || : + ${csudo}rm -f ${cfg_link_dir}/* || : } function clean_log() { # Remove link - ${csudo} rm -rf ${log_link_dir} || : + ${csudo}rm -rf ${log_link_dir} || : } # Stop client. @@ -80,7 +80,7 @@ clean_log # Remove link configuration file clean_config -${csudo} rm -rf ${install_main_dir} +${csudo}rm -rf ${install_main_dir} echo -e "${GREEN}PowerDB client is removed successfully!${NC}" echo diff --git a/packaging/tools/remove_client_pro.sh b/packaging/tools/remove_client_pro.sh index b7ddb27bf48c3e416523c021d42c6ae468fb04e2..3ed0cef1e98896f8160ae3d5a0c5e89bfc01500f 100755 --- a/packaging/tools/remove_client_pro.sh +++ b/packaging/tools/remove_client_pro.sh @@ -20,45 +20,45 @@ inc_link_dir="/usr/include" csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi function kill_client() { if [ -n "$(pidof prodbc)" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function clean_bin() { # Remove link - ${csudo} rm -f ${bin_link_dir}/prodbc || : - ${csudo} rm -f ${bin_link_dir}/prodemo || : - ${csudo} rm -f ${bin_link_dir}/prodump || : - ${csudo} rm -f ${bin_link_dir}/rmprodb || : - ${csudo} rm -f ${bin_link_dir}/set_core || : + ${csudo}rm -f ${bin_link_dir}/prodbc || : + ${csudo}rm -f ${bin_link_dir}/prodemo || : + ${csudo}rm -f ${bin_link_dir}/prodump || : + ${csudo}rm -f ${bin_link_dir}/rmprodb || : + ${csudo}rm -f ${bin_link_dir}/set_core || : } function clean_lib() { # Remove link - ${csudo} rm -f ${lib_link_dir}/libtaos.* || : - ${csudo} rm -f ${lib64_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : } function clean_header() { # 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 || : + ${csudo}rm -f ${inc_link_dir}/taos.h || : + ${csudo}rm -f ${inc_link_dir}/taosdef.h || : + ${csudo}rm -f ${inc_link_dir}/taoserror.h || : } function clean_config() { # Remove link - ${csudo} rm -f ${cfg_link_dir}/* || : + ${csudo}rm -f ${cfg_link_dir}/* || : } function clean_log() { # Remove link - ${csudo} rm -rf ${log_link_dir} || : + ${csudo}rm -rf ${log_link_dir} || : } # Stop client. @@ -74,7 +74,7 @@ clean_log # Remove link configuration file clean_config -${csudo} rm -rf ${install_main_dir} +${csudo}rm -rf ${install_main_dir} echo -e "${GREEN}ProDB client is removed successfully!${NC}" echo diff --git a/packaging/tools/remove_client_tq.sh b/packaging/tools/remove_client_tq.sh index d701217c77e671a4ad24234bdfb4a196f5545970..a35eb9d46e4e33783b47fa33703764c10ee87b9b 100755 --- a/packaging/tools/remove_client_tq.sh +++ b/packaging/tools/remove_client_tq.sh @@ -24,47 +24,47 @@ inc_link_dir="/usr/include" csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi function kill_client() { #pid=$(ps -ef | grep "tq" | grep -v "grep" | awk '{print $2}') if [ -n "$(pidof tq)" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function clean_bin() { # Remove link - ${csudo} rm -f ${bin_link_dir}/tq || : - ${csudo} rm -f ${bin_link_dir}/tqdemo || : - ${csudo} rm -f ${bin_link_dir}/tqdump || : - ${csudo} rm -f ${bin_link_dir}/rmtq || : - ${csudo} rm -f ${bin_link_dir}/set_core || : + ${csudo}rm -f ${bin_link_dir}/tq || : + ${csudo}rm -f ${bin_link_dir}/tqdemo || : + ${csudo}rm -f ${bin_link_dir}/tqdump || : + ${csudo}rm -f ${bin_link_dir}/rmtq || : + ${csudo}rm -f ${bin_link_dir}/set_core || : } function clean_lib() { # Remove link - ${csudo} rm -f ${lib_link_dir}/libtaos.* || : - ${csudo} rm -f ${lib64_link_dir}/libtaos.* || : - #${csudo} rm -rf ${v15_java_app_dir} || : + ${csudo}rm -f ${lib_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : + #${csudo}rm -rf ${v15_java_app_dir} || : } function clean_header() { # 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 || : + ${csudo}rm -f ${inc_link_dir}/taos.h || : + ${csudo}rm -f ${inc_link_dir}/taosdef.h || : + ${csudo}rm -f ${inc_link_dir}/taoserror.h || : } function clean_config() { # Remove link - ${csudo} rm -f ${cfg_link_dir}/* || : + ${csudo}rm -f ${cfg_link_dir}/* || : } function clean_log() { # Remove link - ${csudo} rm -rf ${log_link_dir} || : + ${csudo}rm -rf ${log_link_dir} || : } # Stop client. @@ -80,7 +80,7 @@ clean_log # Remove link configuration file clean_config -${csudo} rm -rf ${install_main_dir} +${csudo}rm -rf ${install_main_dir} echo -e "${GREEN}TQ client is removed successfully!${NC}" echo diff --git a/packaging/tools/remove_jh.sh b/packaging/tools/remove_jh.sh index 6965ba388f99e8a2ac1c33def2f696f8d7c3898e..7b3abff42ad662160cf984adf73abeb51116a422 100755 --- a/packaging/tools/remove_jh.sh +++ b/packaging/tools/remove_jh.sh @@ -28,7 +28,7 @@ tarbitrator_service_name="tarbitratord" nginx_service_name="nginxd" csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi initd_mod=0 @@ -54,78 +54,78 @@ fi function kill_process() { pid=$(ps -ef | grep "jh_taosd" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function kill_tarbitrator() { pid=$(ps -ef | grep "tarbitrator" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function clean_bin() { # Remove link - ${csudo} rm -f ${bin_link_dir}/jh_taos || : - ${csudo} rm -f ${bin_link_dir}/jh_taosd || : - ${csudo} rm -f ${bin_link_dir}/jhdemo || : - ${csudo} rm -f ${bin_link_dir}/jh_taosdump || : - ${csudo} rm -f ${bin_link_dir}/rmjh || : - ${csudo} rm -f ${bin_link_dir}/tarbitrator || : - ${csudo} rm -f ${bin_link_dir}/set_core || : - ${csudo} rm -f ${bin_link_dir}/run_taosd.sh || : + ${csudo}rm -f ${bin_link_dir}/jh_taos || : + ${csudo}rm -f ${bin_link_dir}/jh_taosd || : + ${csudo}rm -f ${bin_link_dir}/jhdemo || : + ${csudo}rm -f ${bin_link_dir}/jh_taosdump || : + ${csudo}rm -f ${bin_link_dir}/rmjh || : + ${csudo}rm -f ${bin_link_dir}/tarbitrator || : + ${csudo}rm -f ${bin_link_dir}/set_core || : + ${csudo}rm -f ${bin_link_dir}/run_taosd.sh || : } function clean_lib() { # Remove link - ${csudo} rm -f ${lib_link_dir}/libtaos.* || : - ${csudo} rm -f ${lib64_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : } function clean_header() { # Remove link - ${csudo} rm -f ${inc_link_dir}/taos.h || : - ${csudo} rm -f ${inc_link_dir}/taoserror.h || : + ${csudo}rm -f ${inc_link_dir}/taos.h || : + ${csudo}rm -f ${inc_link_dir}/taoserror.h || : } function clean_config() { # Remove link - ${csudo} rm -f ${cfg_link_dir}/* || : + ${csudo}rm -f ${cfg_link_dir}/* || : } function clean_log() { # Remove link - ${csudo} rm -rf ${log_link_dir} || : + ${csudo}rm -rf ${log_link_dir} || : } function clean_service_on_systemd() { service_config="${service_config_dir}/${service_name}.service" if systemctl is-active --quiet ${service_name}; then echo "jh_iot's jh_taosd is running, stopping it..." - ${csudo} systemctl stop ${service_name} &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop ${service_name} &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable ${service_name} &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${service_config} + ${csudo}systemctl disable ${service_name} &> /dev/null || echo &> /dev/null + ${csudo}rm -f ${service_config} tarbitratord_service_config="${service_config_dir}/${tarbitrator_service_name}.service" if systemctl is-active --quiet ${tarbitrator_service_name}; then echo "jh_iot's tarbitrator is running, stopping it..." - ${csudo} systemctl stop ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null + ${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} + ${csudo}systemctl disable ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null + ${csudo}rm -f ${tarbitratord_service_config} if [ "$verMode" == "cluster" ]; then nginx_service_config="${service_config_dir}/${nginx_service_name}.service" if [ -d ${bin_dir}/web ]; then if systemctl is-active --quiet ${nginx_service_name}; then echo "Nginx for jh_iot is running, stopping it..." - ${csudo} systemctl stop ${nginx_service_name} &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop ${nginx_service_name} &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable ${nginx_service_name} &> /dev/null || echo &> /dev/null + ${csudo}systemctl disable ${nginx_service_name} &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${nginx_service_config} + ${csudo}rm -f ${nginx_service_config} fi fi } @@ -133,42 +133,42 @@ function clean_service_on_systemd() { function clean_service_on_sysvinit() { if pidof jh_taosd &> /dev/null; then echo "jh_iot's jh_taosd is running, stopping it..." - ${csudo} service jh_taosd stop || : + ${csudo}service jh_taosd stop || : fi if pidof tarbitrator &> /dev/null; then echo "jh_iot's tarbitrator is running, stopping it..." - ${csudo} service tarbitratord stop || : + ${csudo}service tarbitratord stop || : fi if ((${initd_mod}==1)); then if [ -e ${service_config_dir}/jh_taosd ]; then - ${csudo} chkconfig --del jh_taosd || : + ${csudo}chkconfig --del jh_taosd || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} chkconfig --del tarbitratord || : + ${csudo}chkconfig --del tarbitratord || : fi elif ((${initd_mod}==2)); then if [ -e ${service_config_dir}/jh_taosd ]; then - ${csudo} insserv -r jh_taosd || : + ${csudo}insserv -r jh_taosd || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} insserv -r tarbitratord || : + ${csudo}insserv -r tarbitratord || : fi elif ((${initd_mod}==3)); then if [ -e ${service_config_dir}/jh_taosd ]; then - ${csudo} update-rc.d -f jh_taosd remove || : + ${csudo}update-rc.d -f jh_taosd remove || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} update-rc.d -f tarbitratord remove || : + ${csudo}update-rc.d -f tarbitratord remove || : fi fi - ${csudo} rm -f ${service_config_dir}/jh_taosd || : - ${csudo} rm -f ${service_config_dir}/tarbitratord || : + ${csudo}rm -f ${service_config_dir}/jh_taosd || : + ${csudo}rm -f ${service_config_dir}/tarbitratord || : if $(which init &> /dev/null); then - ${csudo} init q || : + ${csudo}init q || : fi } @@ -196,10 +196,10 @@ clean_log # Remove link configuration file clean_config # Remove data link directory -${csudo} rm -rf ${data_link_dir} || : +${csudo}rm -rf ${data_link_dir} || : -${csudo} rm -rf ${install_main_dir} -${csudo} rm -rf ${install_nginxd_dir} +${csudo}rm -rf ${install_main_dir} +${csudo}rm -rf ${install_nginxd_dir} if [[ -e /etc/os-release ]]; then osinfo=$(awk -F= '/^NAME/{print $2}' /etc/os-release) else diff --git a/packaging/tools/remove_kh.sh b/packaging/tools/remove_kh.sh index cf6a93fdf2bf8884bda02b4f44058eb7f8d77210..0c830455c7ef4950384f456ed55a7dd9ca706bfb 100755 --- a/packaging/tools/remove_kh.sh +++ b/packaging/tools/remove_kh.sh @@ -28,7 +28,7 @@ tarbitrator_service_name="tarbitratord" nginx_service_name="nginxd" csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi initd_mod=0 @@ -54,78 +54,78 @@ fi function kill_process() { pid=$(ps -ef | grep "khserver" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function kill_tarbitrator() { pid=$(ps -ef | grep "tarbitrator" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function clean_bin() { # Remove link - ${csudo} rm -f ${bin_link_dir}/khclient || : - ${csudo} rm -f ${bin_link_dir}/khserver || : - ${csudo} rm -f ${bin_link_dir}/khdemo || : - ${csudo} rm -f ${bin_link_dir}/khdump || : - ${csudo} rm -f ${bin_link_dir}/rmkh || : - ${csudo} rm -f ${bin_link_dir}/tarbitrator || : - ${csudo} rm -f ${bin_link_dir}/set_core || : - ${csudo} rm -f ${bin_link_dir}/run_taosd.sh || : + ${csudo}rm -f ${bin_link_dir}/khclient || : + ${csudo}rm -f ${bin_link_dir}/khserver || : + ${csudo}rm -f ${bin_link_dir}/khdemo || : + ${csudo}rm -f ${bin_link_dir}/khdump || : + ${csudo}rm -f ${bin_link_dir}/rmkh || : + ${csudo}rm -f ${bin_link_dir}/tarbitrator || : + ${csudo}rm -f ${bin_link_dir}/set_core || : + ${csudo}rm -f ${bin_link_dir}/run_taosd.sh || : } function clean_lib() { # Remove link - ${csudo} rm -f ${lib_link_dir}/libtaos.* || : - ${csudo} rm -f ${lib64_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : } function clean_header() { # Remove link - ${csudo} rm -f ${inc_link_dir}/taos.h || : - ${csudo} rm -f ${inc_link_dir}/taoserror.h || : + ${csudo}rm -f ${inc_link_dir}/taos.h || : + ${csudo}rm -f ${inc_link_dir}/taoserror.h || : } function clean_config() { # Remove link - ${csudo} rm -f ${cfg_link_dir}/* || : + ${csudo}rm -f ${cfg_link_dir}/* || : } function clean_log() { # Remove link - ${csudo} rm -rf ${log_link_dir} || : + ${csudo}rm -rf ${log_link_dir} || : } function clean_service_on_systemd() { service_config="${service_config_dir}/${service_name}.service" if systemctl is-active --quiet ${service_name}; then echo "KingHistorian's khserver is running, stopping it..." - ${csudo} systemctl stop ${service_name} &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop ${service_name} &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable ${service_name} &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${service_config} + ${csudo}systemctl disable ${service_name} &> /dev/null || echo &> /dev/null + ${csudo}rm -f ${service_config} tarbitratord_service_config="${service_config_dir}/${tarbitrator_service_name}.service" if systemctl is-active --quiet ${tarbitrator_service_name}; then echo "KingHistorian's tarbitrator is running, stopping it..." - ${csudo} systemctl stop ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null + ${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} + ${csudo}systemctl disable ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null + ${csudo}rm -f ${tarbitratord_service_config} if [ "$verMode" == "cluster" ]; then nginx_service_config="${service_config_dir}/${nginx_service_name}.service" if [ -d ${bin_dir}/web ]; then if systemctl is-active --quiet ${nginx_service_name}; then echo "Nginx for KingHistorian is running, stopping it..." - ${csudo} systemctl stop ${nginx_service_name} &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop ${nginx_service_name} &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable ${nginx_service_name} &> /dev/null || echo &> /dev/null + ${csudo}systemctl disable ${nginx_service_name} &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${nginx_service_config} + ${csudo}rm -f ${nginx_service_config} fi fi } @@ -133,42 +133,42 @@ function clean_service_on_systemd() { function clean_service_on_sysvinit() { if pidof khserver &> /dev/null; then echo "KingHistorian's khserver is running, stopping it..." - ${csudo} service khserver stop || : + ${csudo}service khserver stop || : fi if pidof tarbitrator &> /dev/null; then echo "KingHistorian's tarbitrator is running, stopping it..." - ${csudo} service tarbitratord stop || : + ${csudo}service tarbitratord stop || : fi if ((${initd_mod}==1)); then if [ -e ${service_config_dir}/khserver ]; then - ${csudo} chkconfig --del khserver || : + ${csudo}chkconfig --del khserver || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} chkconfig --del tarbitratord || : + ${csudo}chkconfig --del tarbitratord || : fi elif ((${initd_mod}==2)); then if [ -e ${service_config_dir}/khserver ]; then - ${csudo} insserv -r khserver || : + ${csudo}insserv -r khserver || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} insserv -r tarbitratord || : + ${csudo}insserv -r tarbitratord || : fi elif ((${initd_mod}==3)); then if [ -e ${service_config_dir}/khserver ]; then - ${csudo} update-rc.d -f khserver remove || : + ${csudo}update-rc.d -f khserver remove || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} update-rc.d -f tarbitratord remove || : + ${csudo}update-rc.d -f tarbitratord remove || : fi fi - ${csudo} rm -f ${service_config_dir}/khserver || : - ${csudo} rm -f ${service_config_dir}/tarbitratord || : + ${csudo}rm -f ${service_config_dir}/khserver || : + ${csudo}rm -f ${service_config_dir}/tarbitratord || : if $(which init &> /dev/null); then - ${csudo} init q || : + ${csudo}init q || : fi } @@ -196,10 +196,10 @@ clean_log # Remove link configuration file clean_config # Remove data link directory -${csudo} rm -rf ${data_link_dir} || : +${csudo}rm -rf ${data_link_dir} || : -${csudo} rm -rf ${install_main_dir} -${csudo} rm -rf ${install_nginxd_dir} +${csudo}rm -rf ${install_main_dir} +${csudo}rm -rf ${install_nginxd_dir} if [[ -e /etc/os-release ]]; then osinfo=$(awk -F= '/^NAME/{print $2}' /etc/os-release) else diff --git a/packaging/tools/remove_power.sh b/packaging/tools/remove_power.sh index 70d0095f978f8c7a2578c63110cdd118fef43e30..4216147bdf63b3e102d94a668abafd1de18c5ac1 100755 --- a/packaging/tools/remove_power.sh +++ b/packaging/tools/remove_power.sh @@ -31,7 +31,7 @@ tarbitrator_service_name="tarbitratord" nginx_service_name="nginxd" csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi initd_mod=0 @@ -57,79 +57,79 @@ fi function kill_powerd() { pid=$(ps -ef | grep "powerd" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function kill_tarbitrator() { pid=$(ps -ef | grep "tarbitrator" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function clean_bin() { # Remove link - ${csudo} rm -f ${bin_link_dir}/power || : - ${csudo} rm -f ${bin_link_dir}/powerd || : - ${csudo} rm -f ${bin_link_dir}/powerdemo || : - ${csudo} rm -f ${bin_link_dir}/powerdump || : - ${csudo} rm -f ${bin_link_dir}/rmpower || : - ${csudo} rm -f ${bin_link_dir}/tarbitrator || : - ${csudo} rm -f ${bin_link_dir}/set_core || : - ${csudo} rm -f ${bin_link_dir}/run_taosd.sh || : + ${csudo}rm -f ${bin_link_dir}/power || : + ${csudo}rm -f ${bin_link_dir}/powerd || : + ${csudo}rm -f ${bin_link_dir}/powerdemo || : + ${csudo}rm -f ${bin_link_dir}/powerdump || : + ${csudo}rm -f ${bin_link_dir}/rmpower || : + ${csudo}rm -f ${bin_link_dir}/tarbitrator || : + ${csudo}rm -f ${bin_link_dir}/set_core || : + ${csudo}rm -f ${bin_link_dir}/run_taosd.sh || : } function clean_lib() { # Remove link - ${csudo} rm -f ${lib_link_dir}/libtaos.* || : - ${csudo} rm -f ${lib64_link_dir}/libtaos.* || : - #${csudo} rm -rf ${v15_java_app_dir} || : + ${csudo}rm -f ${lib_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : + #${csudo}rm -rf ${v15_java_app_dir} || : } function clean_header() { # 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 || : + ${csudo}rm -f ${inc_link_dir}/taos.h || : + ${csudo}rm -f ${inc_link_dir}/taosdef.h || : + ${csudo}rm -f ${inc_link_dir}/taoserror.h || : } function clean_config() { # Remove link - ${csudo} rm -f ${cfg_link_dir}/* || : + ${csudo}rm -f ${cfg_link_dir}/* || : } function clean_log() { # Remove link - ${csudo} rm -rf ${log_link_dir} || : + ${csudo}rm -rf ${log_link_dir} || : } function clean_service_on_systemd() { power_service_config="${service_config_dir}/${power_service_name}.service" if systemctl is-active --quiet ${power_service_name}; then echo "PowerDB powerd is running, stopping it..." - ${csudo} systemctl stop ${power_service_name} &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop ${power_service_name} &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable ${power_service_name} &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${power_service_config} + ${csudo}systemctl disable ${power_service_name} &> /dev/null || echo &> /dev/null + ${csudo}rm -f ${power_service_config} tarbitratord_service_config="${service_config_dir}/${tarbitrator_service_name}.service" if systemctl is-active --quiet ${tarbitrator_service_name}; then echo "PowerDB tarbitrator is running, stopping it..." - ${csudo} systemctl stop ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null + ${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} + ${csudo}systemctl disable ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null + ${csudo}rm -f ${tarbitratord_service_config} if [ "$verMode" == "cluster" ]; then nginx_service_config="${service_config_dir}/${nginx_service_name}.service" if [ -d ${bin_dir}/web ]; then if systemctl is-active --quiet ${nginx_service_name}; then echo "Nginx for PowerDB is running, stopping it..." - ${csudo} systemctl stop ${nginx_service_name} &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop ${nginx_service_name} &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable ${nginx_service_name} &> /dev/null || echo &> /dev/null + ${csudo}systemctl disable ${nginx_service_name} &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${nginx_service_config} + ${csudo}rm -f ${nginx_service_config} fi fi } @@ -137,42 +137,42 @@ function clean_service_on_systemd() { function clean_service_on_sysvinit() { if pidof powerd &> /dev/null; then echo "PowerDB powerd is running, stopping it..." - ${csudo} service powerd stop || : + ${csudo}service powerd stop || : fi if pidof tarbitrator &> /dev/null; then echo "PowerDB tarbitrator is running, stopping it..." - ${csudo} service tarbitratord stop || : + ${csudo}service tarbitratord stop || : fi if ((${initd_mod}==1)); then if [ -e ${service_config_dir}/powerd ]; then - ${csudo} chkconfig --del powerd || : + ${csudo}chkconfig --del powerd || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} chkconfig --del tarbitratord || : + ${csudo}chkconfig --del tarbitratord || : fi elif ((${initd_mod}==2)); then if [ -e ${service_config_dir}/powerd ]; then - ${csudo} insserv -r powerd || : + ${csudo}insserv -r powerd || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} insserv -r tarbitratord || : + ${csudo}insserv -r tarbitratord || : fi elif ((${initd_mod}==3)); then if [ -e ${service_config_dir}/powerd ]; then - ${csudo} update-rc.d -f powerd remove || : + ${csudo}update-rc.d -f powerd remove || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} update-rc.d -f tarbitratord remove || : + ${csudo}update-rc.d -f tarbitratord remove || : fi fi - ${csudo} rm -f ${service_config_dir}/powerd || : - ${csudo} rm -f ${service_config_dir}/tarbitratord || : + ${csudo}rm -f ${service_config_dir}/powerd || : + ${csudo}rm -f ${service_config_dir}/tarbitratord || : if $(which init &> /dev/null); then - ${csudo} init q || : + ${csudo}init q || : fi } @@ -200,10 +200,10 @@ clean_log # Remove link configuration file clean_config # Remove data link directory -${csudo} rm -rf ${data_link_dir} || : +${csudo}rm -rf ${data_link_dir} || : -${csudo} rm -rf ${install_main_dir} -${csudo} rm -rf ${install_nginxd_dir} +${csudo}rm -rf ${install_main_dir} +${csudo}rm -rf ${install_nginxd_dir} if [[ -e /etc/os-release ]]; then osinfo=$(awk -F= '/^NAME/{print $2}' /etc/os-release) else @@ -212,13 +212,13 @@ fi #if echo $osinfo | grep -qwi "ubuntu" ; then ## echo "this is ubuntu system" -# ${csudo} rm -f /var/lib/dpkg/info/tdengine* || : +# ${csudo}rm -f /var/lib/dpkg/info/tdengine* || : #elif echo $osinfo | grep -qwi "debian" ; then ## echo "this is debian system" -# ${csudo} rm -f /var/lib/dpkg/info/tdengine* || : +# ${csudo}rm -f /var/lib/dpkg/info/tdengine* || : #elif echo $osinfo | grep -qwi "centos" ; then ## echo "this is centos system" -# ${csudo} rpm -e --noscripts tdengine || : +# ${csudo}rpm -e --noscripts tdengine || : #fi echo -e "${GREEN}PowerDB is removed successfully!${NC}" diff --git a/packaging/tools/remove_pro.sh b/packaging/tools/remove_pro.sh index 1572a7f08c6083f7da3d81176f107e4cb977d4f9..f9e8069bb5bb14b44520d0bea3edf2225e6d6b06 100755 --- a/packaging/tools/remove_pro.sh +++ b/packaging/tools/remove_pro.sh @@ -28,7 +28,7 @@ tarbitrator_service_name="tarbitratord" nginx_service_name="nginxd" csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi initd_mod=0 @@ -54,79 +54,79 @@ fi function kill_prodbs() { pid=$(ps -ef | grep "prodbs" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function kill_tarbitrator() { pid=$(ps -ef | grep "tarbitrator" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function clean_bin() { # Remove link - ${csudo} rm -f ${bin_link_dir}/prodbc || : - ${csudo} rm -f ${bin_link_dir}/prodbs || : - ${csudo} rm -f ${bin_link_dir}/prodemo || : - ${csudo} rm -f ${bin_link_dir}/prodump || : - ${csudo} rm -f ${bin_link_dir}/rmprodb || : - ${csudo} rm -f ${bin_link_dir}/tarbitrator || : - ${csudo} rm -f ${bin_link_dir}/set_core || : - ${csudo} rm -f ${bin_link_dir}/run_taosd.sh || : + ${csudo}rm -f ${bin_link_dir}/prodbc || : + ${csudo}rm -f ${bin_link_dir}/prodbs || : + ${csudo}rm -f ${bin_link_dir}/prodemo || : + ${csudo}rm -f ${bin_link_dir}/prodump || : + ${csudo}rm -f ${bin_link_dir}/rmprodb || : + ${csudo}rm -f ${bin_link_dir}/tarbitrator || : + ${csudo}rm -f ${bin_link_dir}/set_core || : + ${csudo}rm -f ${bin_link_dir}/run_taosd.sh || : } function clean_lib() { # Remove link - ${csudo} rm -f ${lib_link_dir}/libtaos.* || : - ${csudo} rm -f ${lib64_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : } function clean_header() { # 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 || : + ${csudo}rm -f ${inc_link_dir}/taos.h || : + ${csudo}rm -f ${inc_link_dir}/taosdef.h || : + ${csudo}rm -f ${inc_link_dir}/taoserror.h || : } function clean_config() { # Remove link - ${csudo} rm -f ${cfg_link_dir}/* || : + ${csudo}rm -f ${cfg_link_dir}/* || : } function clean_log() { # Remove link - ${csudo} rm -rf ${log_link_dir} || : + ${csudo}rm -rf ${log_link_dir} || : } function clean_service_on_systemd() { prodb_service_config="${service_config_dir}/${prodb_service_name}.service" if systemctl is-active --quiet ${prodb_service_name}; then echo "ProDB prodbs is running, stopping it..." - ${csudo} systemctl stop ${prodb_service_name} &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop ${prodb_service_name} &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable ${prodb_service_name} &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${prodb_service_config} + ${csudo}systemctl disable ${prodb_service_name} &> /dev/null || echo &> /dev/null + ${csudo}rm -f ${prodb_service_config} tarbitratord_service_config="${service_config_dir}/${tarbitrator_service_name}.service" if systemctl is-active --quiet ${tarbitrator_service_name}; then echo "ProDB tarbitrator is running, stopping it..." - ${csudo} systemctl stop ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null + ${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} + ${csudo}systemctl disable ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null + ${csudo}rm -f ${tarbitratord_service_config} if [ "$verMode" == "cluster" ]; then nginx_service_config="${service_config_dir}/${nginx_service_name}.service" if [ -d ${bin_dir}/web ]; then if systemctl is-active --quiet ${nginx_service_name}; then echo "Nginx for ProDB is running, stopping it..." - ${csudo} systemctl stop ${nginx_service_name} &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop ${nginx_service_name} &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable ${nginx_service_name} &> /dev/null || echo &> /dev/null + ${csudo}systemctl disable ${nginx_service_name} &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${nginx_service_config} + ${csudo}rm -f ${nginx_service_config} fi fi } @@ -134,42 +134,42 @@ function clean_service_on_systemd() { function clean_service_on_sysvinit() { if pidof prodbs &> /dev/null; then echo "ProDB prodbs is running, stopping it..." - ${csudo} service prodbs stop || : + ${csudo}service prodbs stop || : fi if pidof tarbitrator &> /dev/null; then echo "ProDB tarbitrator is running, stopping it..." - ${csudo} service tarbitratord stop || : + ${csudo}service tarbitratord stop || : fi if ((${initd_mod}==1)); then if [ -e ${service_config_dir}/prodbs ]; then - ${csudo} chkconfig --del prodbs || : + ${csudo}chkconfig --del prodbs || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} chkconfig --del tarbitratord || : + ${csudo}chkconfig --del tarbitratord || : fi elif ((${initd_mod}==2)); then if [ -e ${service_config_dir}/prodbs ]; then - ${csudo} insserv -r prodbs || : + ${csudo}insserv -r prodbs || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} insserv -r tarbitratord || : + ${csudo}insserv -r tarbitratord || : fi elif ((${initd_mod}==3)); then if [ -e ${service_config_dir}/prodbs ]; then - ${csudo} update-rc.d -f prodbs remove || : + ${csudo}update-rc.d -f prodbs remove || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} update-rc.d -f tarbitratord remove || : + ${csudo}update-rc.d -f tarbitratord remove || : fi fi - ${csudo} rm -f ${service_config_dir}/prodbs || : - ${csudo} rm -f ${service_config_dir}/tarbitratord || : + ${csudo}rm -f ${service_config_dir}/prodbs || : + ${csudo}rm -f ${service_config_dir}/tarbitratord || : if $(which init &> /dev/null); then - ${csudo} init q || : + ${csudo}init q || : fi } @@ -197,10 +197,10 @@ clean_log # Remove link configuration file clean_config # Remove data link directory -${csudo} rm -rf ${data_link_dir} || : +${csudo}rm -rf ${data_link_dir} || : -${csudo} rm -rf ${install_main_dir} -${csudo} rm -rf ${install_nginxd_dir} +${csudo}rm -rf ${install_main_dir} +${csudo}rm -rf ${install_nginxd_dir} if [[ -e /etc/os-release ]]; then osinfo=$(awk -F= '/^NAME/{print $2}' /etc/os-release) else diff --git a/packaging/tools/remove_tq.sh b/packaging/tools/remove_tq.sh index eb83b92d1a5ef7e9e4ac498d98cc538a34da2a4f..e9a071f7d6b6bd5ae89c12cf8db5de014dbc2d52 100755 --- a/packaging/tools/remove_tq.sh +++ b/packaging/tools/remove_tq.sh @@ -31,7 +31,7 @@ tarbitrator_service_name="tarbitratord" nginx_service_name="nginxd" csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi initd_mod=0 @@ -57,125 +57,125 @@ fi function kill_tqd() { pid=$(ps -ef | grep "tqd" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function kill_tarbitrator() { pid=$(ps -ef | grep "tarbitrator" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : + ${csudo}kill -9 $pid || : fi } function clean_bin() { # Remove link - ${csudo} rm -f ${bin_link_dir}/tq || : - ${csudo} rm -f ${bin_link_dir}/tqd || : - ${csudo} rm -f ${bin_link_dir}/tqdemo || : - ${csudo} rm -f ${bin_link_dir}/tqdump || : - ${csudo} rm -f ${bin_link_dir}/rmtq || : - ${csudo} rm -f ${bin_link_dir}/tarbitrator || : - ${csudo} rm -f ${bin_link_dir}/set_core || : - ${csudo} rm -f ${bin_link_dir}/run_taosd.sh || : + ${csudo}rm -f ${bin_link_dir}/tq || : + ${csudo}rm -f ${bin_link_dir}/tqd || : + ${csudo}rm -f ${bin_link_dir}/tqdemo || : + ${csudo}rm -f ${bin_link_dir}/tqdump || : + ${csudo}rm -f ${bin_link_dir}/rmtq || : + ${csudo}rm -f ${bin_link_dir}/tarbitrator || : + ${csudo}rm -f ${bin_link_dir}/set_core || : + ${csudo}rm -f ${bin_link_dir}/run_taosd.sh || : } function clean_lib() { # Remove link - ${csudo} rm -f ${lib_link_dir}/libtaos.* || : - ${csudo} rm -f ${lib64_link_dir}/libtaos.* || : - #${csudo} rm -rf ${v15_java_app_dir} || : + ${csudo}rm -f ${lib_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : + #${csudo}rm -rf ${v15_java_app_dir} || : } function clean_header() { # 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 || : + ${csudo}rm -f ${inc_link_dir}/taos.h || : + ${csudo}rm -f ${inc_link_dir}/taosdef.h || : + ${csudo}rm -f ${inc_link_dir}/taoserror.h || : } function clean_config() { # Remove link - ${csudo} rm -f ${cfg_link_dir}/* || : + ${csudo}rm -f ${cfg_link_dir}/* || : } function clean_log() { # Remove link - ${csudo} rm -rf ${log_link_dir} || : + ${csudo}rm -rf ${log_link_dir} || : } function clean_service_on_systemd() { tq_service_config="${service_config_dir}/${tq_service_name}.service" if systemctl is-active --quiet ${tq_service_name}; then echo "TQ tqd is running, stopping it..." - ${csudo} systemctl stop ${tq_service_name} &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop ${tq_service_name} &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable ${tq_service_name} &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${tq_service_config} + ${csudo}systemctl disable ${tq_service_name} &> /dev/null || echo &> /dev/null + ${csudo}rm -f ${tq_service_config} tarbitratord_service_config="${service_config_dir}/${tarbitrator_service_name}.service" if systemctl is-active --quiet ${tarbitrator_service_name}; then echo "TQ tarbitrator is running, stopping it..." - ${csudo} systemctl stop ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null + ${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} + ${csudo}systemctl disable ${tarbitrator_service_name} &> /dev/null || echo &> /dev/null + ${csudo}rm -f ${tarbitratord_service_config} if [ "$verMode" == "cluster" ]; then nginx_service_config="${service_config_dir}/${nginx_service_name}.service" if [ -d ${bin_dir}/web ]; then if systemctl is-active --quiet ${nginx_service_name}; then echo "Nginx for TQ is running, stopping it..." - ${csudo} systemctl stop ${nginx_service_name} &> /dev/null || echo &> /dev/null + ${csudo}systemctl stop ${nginx_service_name} &> /dev/null || echo &> /dev/null fi - ${csudo} systemctl disable ${nginx_service_name} &> /dev/null || echo &> /dev/null + ${csudo}systemctl disable ${nginx_service_name} &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${nginx_service_config} + ${csudo}rm -f ${nginx_service_config} fi fi } function clean_service_on_sysvinit() { #restart_config_str="tq:2345:respawn:${service_config_dir}/tqd start" - #${csudo} sed -i "\|${restart_config_str}|d" /etc/inittab || : + #${csudo}sed -i "\|${restart_config_str}|d" /etc/inittab || : if pidof tqd &> /dev/null; then echo "TQ tqd is running, stopping it..." - ${csudo} service tqd stop || : + ${csudo}service tqd stop || : fi if pidof tarbitrator &> /dev/null; then echo "TQ tarbitrator is running, stopping it..." - ${csudo} service tarbitratord stop || : + ${csudo}service tarbitratord stop || : fi if ((${initd_mod}==1)); then if [ -e ${service_config_dir}/tqd ]; then - ${csudo} chkconfig --del tqd || : + ${csudo}chkconfig --del tqd || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} chkconfig --del tarbitratord || : + ${csudo}chkconfig --del tarbitratord || : fi elif ((${initd_mod}==2)); then if [ -e ${service_config_dir}/tqd ]; then - ${csudo} insserv -r tqd || : + ${csudo}insserv -r tqd || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} insserv -r tarbitratord || : + ${csudo}insserv -r tarbitratord || : fi elif ((${initd_mod}==3)); then if [ -e ${service_config_dir}/tqd ]; then - ${csudo} update-rc.d -f tqd remove || : + ${csudo}update-rc.d -f tqd remove || : fi if [ -e ${service_config_dir}/tarbitratord ]; then - ${csudo} update-rc.d -f tarbitratord remove || : + ${csudo}update-rc.d -f tarbitratord remove || : fi fi - ${csudo} rm -f ${service_config_dir}/tqd || : - ${csudo} rm -f ${service_config_dir}/tarbitratord || : + ${csudo}rm -f ${service_config_dir}/tqd || : + ${csudo}rm -f ${service_config_dir}/tarbitratord || : if $(which init &> /dev/null); then - ${csudo} init q || : + ${csudo}init q || : fi } @@ -203,10 +203,10 @@ clean_log # Remove link configuration file clean_config # Remove data link directory -${csudo} rm -rf ${data_link_dir} || : +${csudo}rm -rf ${data_link_dir} || : -${csudo} rm -rf ${install_main_dir} -${csudo} rm -rf ${install_nginxd_dir} +${csudo}rm -rf ${install_main_dir} +${csudo}rm -rf ${install_nginxd_dir} if [[ -e /etc/os-release ]]; then osinfo=$(awk -F= '/^NAME/{print $2}' /etc/os-release) else diff --git a/packaging/tools/set_core.sh b/packaging/tools/set_core.sh index f515fd3dc5ed4a26fc7f4120573d39303ea3d751..db95aeb34346b161d979b074e0cb50c017e0bc6d 100755 --- a/packaging/tools/set_core.sh +++ b/packaging/tools/set_core.sh @@ -15,7 +15,7 @@ corePath=$1 csudo="" if command -v sudo > /dev/null; then - csudo="sudo" + csudo="sudo " fi if [[ ! -n ${corePath} ]]; then @@ -31,10 +31,10 @@ if [[ ! -n ${corePath} ]]; then fi ulimit -c unlimited -${csudo} sed -i '/ulimit -c unlimited/d' /etc/profile ||: -${csudo} sed -i '$a\ulimit -c unlimited' /etc/profile ||: +${csudo}sed -i '/ulimit -c unlimited/d' /etc/profile ||: +${csudo}sed -i '$a\ulimit -c unlimited' /etc/profile ||: source /etc/profile -${csudo} mkdir -p ${corePath} ||: -${csudo} sysctl -w kernel.core_pattern=${corePath}/core-%e-%p ||: -${csudo} echo "${corePath}/core-%e-%p" | ${csudo} tee /proc/sys/kernel/core_pattern ||: +${csudo}mkdir -p ${corePath} ||: +${csudo}sysctl -w kernel.core_pattern=${corePath}/core-%e-%p ||: +${csudo}echo "${corePath}/core-%e-%p" | ${csudo}tee /proc/sys/kernel/core_pattern ||: diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index 10cfe8bcc5053fa9fe44982268d9e8843d071ce6..c5e3cb727f85dafd2b51efe741cd635394908cfd 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -440,7 +440,7 @@ int tsParseSql(SSqlObj *pSql, bool initial); void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet); int tscBuildAndSendRequest(SSqlObj *pSql, SQueryInfo* pQueryInfo); -int tscRenewTableMeta(SSqlObj *pSql, int32_t tableIndex); +int tscRenewTableMeta(SSqlObj *pSql); void tscAsyncResultOnError(SSqlObj *pSql); void tscQueueAsyncError(void(*fp), void *param, int32_t code); diff --git a/src/client/src/tscParseLineProtocol.c b/src/client/src/tscParseLineProtocol.c index 085b949cc102e3752abd41caacdf07985351e1db..0d43e101754e9ae3eb33440005790f238f6664a5 100644 --- a/src/client/src/tscParseLineProtocol.c +++ b/src/client/src/tscParseLineProtocol.c @@ -795,69 +795,69 @@ static int32_t arrangePointsByChildTableName(TAOS_SML_DATA_POINT* points, int nu static int32_t applyChildTableDataPointsWithInsertSQL(TAOS* taos, char* cTableName, char* sTableName, SSmlSTableSchema* sTableSchema, SArray* cTablePoints, size_t rowSize, SSmlLinesInfo* info) { int32_t code = TSDB_CODE_SUCCESS; - size_t numTags = taosArrayGetSize(sTableSchema->tags); - size_t numCols = taosArrayGetSize(sTableSchema->fields); - size_t rows = taosArrayGetSize(cTablePoints); + size_t numTags = taosArrayGetSize(sTableSchema->tags); + size_t numCols = taosArrayGetSize(sTableSchema->fields); + size_t rows = taosArrayGetSize(cTablePoints); SArray* tagsSchema = sTableSchema->tags; SArray* colsSchema = sTableSchema->fields; TAOS_SML_KV* tagKVs[TSDB_MAX_TAGS] = {0}; - for (int i= 0; i < rows; ++i) { - TAOS_SML_DATA_POINT * pDataPoint = taosArrayGetP(cTablePoints, i); + for (int i = 0; i < rows; ++i) { + TAOS_SML_DATA_POINT* pDataPoint = taosArrayGetP(cTablePoints, i); for (int j = 0; j < pDataPoint->tagNum; ++j) { TAOS_SML_KV* kv = pDataPoint->tags + j; tagKVs[kv->fieldSchemaIdx] = kv; } } - char* sql = malloc(tsMaxSQLStringLen+1); + char* sql = malloc(tsMaxSQLStringLen + 1); if (sql == NULL) { tscError("malloc sql memory error"); return TSDB_CODE_TSC_OUT_OF_MEMORY; } - int32_t freeBytes = tsMaxSQLStringLen + 1 ; + int32_t freeBytes = tsMaxSQLStringLen + 1; int32_t totalLen = 0; totalLen += sprintf(sql, "insert into %s using %s (", cTableName, sTableName); for (int i = 0; i < numTags; ++i) { SSchema* tagSchema = taosArrayGet(tagsSchema, i); - totalLen += snprintf(sql+totalLen, freeBytes-totalLen, "%s,", tagSchema->name); + totalLen += snprintf(sql + totalLen, freeBytes - totalLen, "%s,", tagSchema->name); } --totalLen; - totalLen += snprintf(sql + totalLen, freeBytes-totalLen, ")"); + totalLen += snprintf(sql + totalLen, freeBytes - totalLen, ")"); - totalLen += snprintf(sql + totalLen, freeBytes-totalLen, " tags ("); + totalLen += snprintf(sql + totalLen, freeBytes - totalLen, " tags ("); -// for (int i = 0; i < numTags; ++i) { -// snprintf(sql+strlen(sql), freeBytes-strlen(sql), "?,"); -// } + // for (int i = 0; i < numTags; ++i) { + // snprintf(sql+strlen(sql), freeBytes-strlen(sql), "?,"); + // } for (int i = 0; i < numTags; ++i) { if (tagKVs[i] == NULL) { - totalLen += snprintf(sql + totalLen, freeBytes-totalLen, "NULL,"); + totalLen += snprintf(sql + totalLen, freeBytes - totalLen, "NULL,"); } else { - TAOS_SML_KV* kv = tagKVs[i]; - size_t beforeLen = totalLen; - int32_t len = 0; - converToStr(sql+beforeLen, kv->type, kv->value, kv->length, &len); + TAOS_SML_KV* kv = tagKVs[i]; + size_t beforeLen = totalLen; + int32_t len = 0; + converToStr(sql + beforeLen, kv->type, kv->value, kv->length, &len); totalLen += len; - totalLen += snprintf(sql+totalLen, freeBytes-totalLen, ","); + totalLen += snprintf(sql + totalLen, freeBytes - totalLen, ","); } } --totalLen; - totalLen += snprintf(sql + totalLen, freeBytes-totalLen, ") ("); + totalLen += snprintf(sql + totalLen, freeBytes - totalLen, ") ("); for (int i = 0; i < numCols; ++i) { SSchema* colSchema = taosArrayGet(colsSchema, i); - totalLen += snprintf(sql+totalLen, freeBytes-totalLen, "%s,", colSchema->name); + totalLen += snprintf(sql + totalLen, freeBytes - totalLen, "%s,", colSchema->name); } --totalLen; - totalLen += snprintf(sql + totalLen, freeBytes-totalLen, ") values "); + totalLen += snprintf(sql + totalLen, freeBytes - totalLen, ") values "); - TAOS_SML_KV** colKVs = malloc(numCols*sizeof(TAOS_SML_KV*)); + TAOS_SML_KV** colKVs = malloc(numCols * sizeof(TAOS_SML_KV*)); for (int r = 0; r < rows; ++r) { - totalLen += snprintf(sql + totalLen, freeBytes-totalLen, "("); + totalLen += snprintf(sql + totalLen, freeBytes - totalLen, "("); - memset(colKVs, 0, numCols*sizeof(TAOS_SML_KV*)); + memset(colKVs, 0, numCols * sizeof(TAOS_SML_KV*)); TAOS_SML_DATA_POINT* point = taosArrayGetP(cTablePoints, r); for (int i = 0; i < point->fieldNum; ++i) { @@ -867,28 +867,68 @@ static int32_t applyChildTableDataPointsWithInsertSQL(TAOS* taos, char* cTableNa for (int i = 0; i < numCols; ++i) { if (colKVs[i] == NULL) { - totalLen += snprintf(sql + totalLen, freeBytes-totalLen, "NULL,"); + totalLen += snprintf(sql + totalLen, freeBytes - totalLen, "NULL,"); } else { - TAOS_SML_KV* kv = colKVs[i]; - size_t beforeLen = totalLen; - int32_t len = 0; - converToStr(sql+beforeLen, kv->type, kv->value, kv->length, &len); + TAOS_SML_KV* kv = colKVs[i]; + size_t beforeLen = totalLen; + int32_t len = 0; + converToStr(sql + beforeLen, kv->type, kv->value, kv->length, &len); totalLen += len; - totalLen += snprintf(sql+totalLen, freeBytes-totalLen, ","); + totalLen += snprintf(sql + totalLen, freeBytes - totalLen, ","); } } --totalLen; - totalLen += snprintf(sql+totalLen, freeBytes - totalLen, ")"); + totalLen += snprintf(sql + totalLen, freeBytes - totalLen, ")"); } free(colKVs); sql[totalLen] = '\0'; - tscDebug("SML:0x%"PRIx64" insert child table table %s of super table %s sql: %s", info->id, cTableName, sTableName, sql); - TAOS_RES* res = taos_query(taos, sql); + tscDebug("SML:0x%" PRIx64 " insert child table table %s of super table %s sql: %s", info->id, cTableName, sTableName, + sql); + + bool tryAgain = false; + int32_t try = 0; + do { + TAOS_RES* res = taos_query(taos, sql); + code = taos_errno(res); + if (code != 0) { + tscError("SML:0x%"PRIx64 " taos_query return %d:%s", info->id, code, taos_errstr(res)); + } + + tscDebug("SML:0x%"PRIx64 " taos_query inserted %d rows", info->id, taos_affected_rows(res)); + info->affectedRows += taos_affected_rows(res); + taos_free_result(res); + + tryAgain = false; + if ((code == TSDB_CODE_TDB_INVALID_TABLE_ID + || code == TSDB_CODE_VND_INVALID_VGROUP_ID + || code == TSDB_CODE_TDB_TABLE_RECONFIGURE + || code == TSDB_CODE_APP_NOT_READY + || code == TSDB_CODE_RPC_NETWORK_UNAVAIL) && try++ < TSDB_MAX_REPLICA) { + tryAgain = true; + } + + if (code == TSDB_CODE_TDB_INVALID_TABLE_ID || code == TSDB_CODE_VND_INVALID_VGROUP_ID) { + TAOS_RES* res2 = taos_query(taos, "RESET QUERY CACHE"); + int32_t code2 = taos_errno(res2); + if (code2 != TSDB_CODE_SUCCESS) { + tscError("SML:0x%" PRIx64 " insert child table by sql. reset query cache. error: %s", info->id, taos_errstr(res2)); + } + taos_free_result(res2); + if (tryAgain) { + taosMsleep(100 * (2 << try)); + } + } + + if (code == TSDB_CODE_APP_NOT_READY || code == TSDB_CODE_RPC_NETWORK_UNAVAIL) { + if (tryAgain) { + taosMsleep( 100 * (2 << try)); + } + } + } while (tryAgain); + free(sql); - code = taos_errno(res); - info->affectedRows += taos_affected_rows(res); - taos_free_result(res); + return code; } diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index 8d1a79e734cabf6694daf30d8887265488bcf630..ea0a3124b234d24db1411c4453ce7bd9d3e73e2d 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -1705,7 +1705,7 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags SSqlObj* pSql = pStmt->pSql; SSqlCmd* pCmd = &pSql->cmd; - uint32_t nameLen = (uint32_t)strlen(name); + int32_t nameLen = (int32_t)strlen(name); if (name == NULL || nameLen <= 0) { tscError("0x%"PRIx64" tbname is NULL", pSql->self); @@ -1727,18 +1727,22 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags SStrToken tname = {0}; tname.type = TK_STRING; tname.z = (char *)strdup(name); - tname.n = (uint32_t)strlen(name); + if (!tname.z) { + tscError("0x%" PRIx64 " out of memory", pSql->self); + STMT_RET(TSDB_CODE_TSC_OUT_OF_MEMORY); + } + tname.n = (uint32_t)strlen(tname.z); bool dbIncluded = false; // Check if the table name available or not if (tscValidateName(&tname, true, &dbIncluded) != TSDB_CODE_SUCCESS) { - tscError("0x%"PRIx64" tbname[%s] is invalid", pSql->self, name); + tscError("0x%" PRIx64 " tbname[%s] is invalid", pSql->self, tname.z); free(tname.z); STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "name is invalid")); } - uint64_t* uid = (uint64_t*)taosHashGet(pStmt->mtb.pTableHash, name, strlen(name)); + uint64_t* uid = (uint64_t*)taosHashGet(pStmt->mtb.pTableHash, tname.z, tname.n); if (uid != NULL) { pStmt->mtb.currentUid = *uid; @@ -1752,6 +1756,7 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags if ((*t1)->pData == NULL) { code = tscCreateDataBlockData(*t1, TSDB_PAYLOAD_SIZE, (*t1)->pTableMeta->tableInfo.rowSize, sizeof(SSubmitBlk)); if (code != TSDB_CODE_SUCCESS) { + free(tname.z); STMT_RET(code); } } @@ -1766,7 +1771,7 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags taosHashPut(pCmd->insertParam.pTableBlockHashList, (void *)&pStmt->mtb.currentUid, sizeof(pStmt->mtb.currentUid), (void*)t1, POINTER_BYTES); - tscDebug("0x%"PRIx64" table:%s is already prepared, uid:%" PRIu64, pSql->self, name, pStmt->mtb.currentUid); + tscDebug("0x%" PRIx64 " table:%s is already prepared, uid:%" PRIu64, pSql->self, tname.z, pStmt->mtb.currentUid); free(tname.z); STMT_RET(TSDB_CODE_SUCCESS); } @@ -1779,18 +1784,19 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags SName fullname = {0}; tscSetTableFullName(&fullname, &tname, pSql, dbIncluded); - free(tname.z); memcpy(&pTableMetaInfo->name, &fullname, sizeof(fullname)); code = tscGetTableMetaEx(pSql, pTableMetaInfo, false, true); if (code != TSDB_CODE_SUCCESS) { + free(tname.z); STMT_RET(code); } pTableMeta = pTableMetaInfo->pTableMeta; if (strcmp(sTableName, pTableMeta->sTableName)) { + free(tname.z); tscError("0x%"PRIx64" only tables belongs to one stable is allowed", pSql->self); STMT_RET(TSDB_CODE_TSC_APP_ERROR); } @@ -1806,25 +1812,26 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags taosHashPut(pCmd->insertParam.pTableBlockHashList, (void *)&pStmt->mtb.currentUid, sizeof(pStmt->mtb.currentUid), (void*)&pBlock, POINTER_BYTES); taosHashPut(pStmt->mtb.pTableBlockHashList, (void *)&pStmt->mtb.currentUid, sizeof(pStmt->mtb.currentUid), (void*)&pBlock, POINTER_BYTES); - taosHashPut(pStmt->mtb.pTableHash, name, strlen(name), (char*) &pTableMeta->id.uid, sizeof(pTableMeta->id.uid)); + taosHashPut(pStmt->mtb.pTableHash, tname.z, tname.n, (char*)&pTableMeta->id.uid, sizeof(pTableMeta->id.uid)); - tscDebug("0x%"PRIx64" table:%s is prepared, uid:%" PRIx64, pSql->self, name, pStmt->mtb.currentUid); + tscDebug("0x%" PRIx64 " table:%s is prepared, uid:%" PRIx64, pSql->self, tname.z, pStmt->mtb.currentUid); + free(tname.z); STMT_RET(TSDB_CODE_SUCCESS); } - free(tname.z); - if (pStmt->mtb.tagSet) { - pStmt->mtb.tbname = tscReplaceStrToken(&pSql->sqlstr, &pStmt->mtb.tbname, name); + pStmt->mtb.tbname = tscReplaceStrToken(&pSql->sqlstr, &pStmt->mtb.tbname, tname.z); } else { if (tags == NULL) { tscError("No tags set"); + free(tname.z); STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "no tags set")); } - int32_t ret = stmtGenInsertStatement(pSql, pStmt, name, tags); + int32_t ret = stmtGenInsertStatement(pSql, pStmt, tname.z, tags); if (ret != TSDB_CODE_SUCCESS) { + free(tname.z); STMT_RET(ret); } } @@ -1859,6 +1866,7 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags code = tscGetDataBlockFromList(pCmd->insertParam.pTableBlockHashList, pTableMeta->id.uid, TSDB_PAYLOAD_SIZE, sizeof(SSubmitBlk), pTableMeta->tableInfo.rowSize, &pTableMetaInfo->name, pTableMeta, &pBlock, NULL); if (code != TSDB_CODE_SUCCESS) { + free(tname.z); STMT_RET(code); } @@ -1869,15 +1877,16 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags pStmt->mtb.tbNum++; taosHashPut(pStmt->mtb.pTableBlockHashList, (void *)&pStmt->mtb.currentUid, sizeof(pStmt->mtb.currentUid), (void*)&pBlock, POINTER_BYTES); - taosHashPut(pStmt->mtb.pTableHash, name, strlen(name), (char*) &pTableMeta->id.uid, sizeof(pTableMeta->id.uid)); + taosHashPut(pStmt->mtb.pTableHash, tname.z, tname.n, (char*)&pTableMeta->id.uid, sizeof(pTableMeta->id.uid)); if (pStmt->mtb.lastBlock == NULL) { insertStmtGenLastBlock(&pStmt->mtb.lastBlock, pBlock); } - tscDebug("0x%"PRIx64" table:%s is prepared, uid:%" PRIx64, pSql->self, name, pStmt->mtb.currentUid); + tscDebug("0x%" PRIx64 " table:%s is prepared, uid:%" PRIx64, pSql->self, tname.z, pStmt->mtb.currentUid); } + free(tname.z); STMT_RET(code); } diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 1f6ff0665515cc99a56e2e604b8c2726a8717006..b53569c078fec12190ba681b18b184778ef494a3 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -192,7 +192,7 @@ bool serializeExprListToVariant(SArray* pList, tVariant **dst, int16_t colType, } if (colType == TSDB_DATA_TYPE_BOOL && (var->i64 > 1 ||var->i64 < 0)) { break; - } + } tbufWriteInt64(&bw, var->i64); } else if (IS_UNSIGNED_NUMERIC_TYPE(colType)) { if (IS_SIGNED_NUMERIC_TYPE(var->nType) || IS_UNSIGNED_NUMERIC_TYPE(var->nType)) { @@ -604,11 +604,11 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { char buf[TSDB_TABLE_FNAME_LEN]; SStrToken sTblToken; sTblToken.z = buf; - + if (pInfo->type != TSDB_SQL_DROP_DNODE) { if ((escapeEnabled && (validateTableName(pzName->z, pzName->n, &sTblToken, &dbIncluded) != TSDB_CODE_SUCCESS)) || ((!escapeEnabled) && (tscValidateName(pzName, escapeEnabled, &dbIncluded) != TSDB_CODE_SUCCESS))){ - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); } } @@ -624,7 +624,7 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { code = tscSetTableFullName(&pTableMetaInfo->name, &sTblToken, pSql, dbIncluded); if(code != TSDB_CODE_SUCCESS) { - return code; + return code; } } else if (pInfo->type == TSDB_SQL_DROP_DNODE) { if (pzName->type == TK_STRING) { @@ -766,7 +766,7 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { char buf[TSDB_TABLE_FNAME_LEN]; SStrToken sTblToken; sTblToken.z = buf; - + if (validateTableName(pToken->z, pToken->n, &sTblToken, &dbIncluded) != TSDB_CODE_SUCCESS) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); } @@ -789,7 +789,7 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { char buf[TSDB_TABLE_FNAME_LEN]; SStrToken sTblToken; sTblToken.z = buf; - + if (validateTableName(pToken->z, pToken->n, &sTblToken, &dbIncluded) != TSDB_CODE_SUCCESS) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); } @@ -805,7 +805,7 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { const char* msg1 = "invalid database name"; SStrToken* pToken = taosArrayGet(pInfo->pMiscInfo->a, 0); - + if (tscValidateName(pToken, false, NULL) != TSDB_CODE_SUCCESS) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); } @@ -1093,7 +1093,7 @@ static int32_t addPrimaryTsColumnForTimeWindowQuery(SQueryInfo* pQueryInfo, SSql tstrncpy(s.name, aAggs[TSDB_FUNC_TS].name, sizeof(s.name)); SColumnIndex index = {tableIndex, PRIMARYKEY_TIMESTAMP_COL_INDEX}; - tscAddFuncInSelectClause(pQueryInfo, 0, TSDB_FUNC_TS, &index, &s, TSDB_COL_NORMAL, getNewResColId(pCmd)); + tscAddFuncInSelectClause(pQueryInfo, 0, TSDB_FUNC_TS, &index, &s, TSDB_COL_NORMAL, 0); return TSDB_CODE_SUCCESS; } @@ -2176,23 +2176,23 @@ int32_t validateSelectNodeList(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SArray* pS pQueryInfo->colList = taosArrayInit(4, POINTER_BYTES); } - + bool hasDistinct = false; - bool hasAgg = false; + bool hasAgg = false; size_t numOfExpr = taosArrayGetSize(pSelNodeList); - int32_t distIdx = -1; + int32_t distIdx = -1; for (int32_t i = 0; i < numOfExpr; ++i) { int32_t outputIndex = (int32_t)tscNumOfExprs(pQueryInfo); tSqlExprItem* pItem = taosArrayGet(pSelNodeList, i); if (hasDistinct == false) { - hasDistinct = (pItem->distinct == true); + hasDistinct = (pItem->distinct == true); distIdx = hasDistinct ? i : -1; } if(pItem->aliasName != NULL && validateColumnName(pItem->aliasName) != TSDB_CODE_SUCCESS){ return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg11); } - if(pItem->aliasName != NULL && validateColumnName(pItem->aliasName) != TSDB_CODE_SUCCESS){ + if(pItem->aliasName != NULL && strcasecmp(pItem->aliasName, DEFAULT_PRIMARY_TIMESTAMP_COL_NAME) == 0){ return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg11); } @@ -2203,7 +2203,7 @@ int32_t validateSelectNodeList(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SArray* pS return code; } } else if (type == SQL_NODE_SQLFUNCTION) { - hasAgg = true; + hasAgg = true; if (hasDistinct) break; pItem->pNode->functionId = isValidFunction(pItem->pNode->Expr.operand.z, pItem->pNode->Expr.operand.n); @@ -2253,12 +2253,12 @@ int32_t validateSelectNodeList(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SArray* pS } } - //TODO(dengyihao), refactor as function - //handle distinct func mixed with other func + //TODO(dengyihao), refactor as function + //handle distinct func mixed with other func if (hasDistinct == true) { if (distIdx != 0 || hasAgg) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4); - } + } if (joinQuery) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6); } @@ -2268,11 +2268,11 @@ int32_t validateSelectNodeList(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SArray* pS if (pQueryInfo->pDownstream != NULL) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg8); } - + pQueryInfo->distinct = true; } - - + + // there is only one user-defined column in the final result field, add the timestamp column. size_t numOfSrcCols = taosArrayGetSize(pQueryInfo->colList); if ((numOfSrcCols <= 0 || !hasNoneUserDefineExpr(pQueryInfo)) && !tscQueryTags(pQueryInfo) && !tscQueryBlockInfo(pQueryInfo)) { @@ -2491,6 +2491,7 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t /*SExprInfo* pExpr = */ tscAddFuncInSelectClause(pQueryInfo, startPos, TSDB_FUNC_TAGPRJ, &index, &colSchema, TSDB_COL_TAG, getNewResColId(pCmd)); } + pQueryInfo->type |= TSDB_QUERY_TYPE_PROJECTION_QUERY; } else { STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex); STableMeta* pTableMeta = pTableMetaInfo->pTableMeta; @@ -2774,12 +2775,17 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); } + pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex); + SSchema* pColumnSchema = tscGetTableColumnSchema(pTableMetaInfo->pTableMeta, index.columnIndex); + // elapsed only can be applied to primary key - if (functionId == TSDB_FUNC_ELAPSED && index.columnIndex != PRIMARYKEY_TIMESTAMP_COL_INDEX) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), "elapsed only can be applied to primary key"); + if (functionId == TSDB_FUNC_ELAPSED) { + if ( index.columnIndex != PRIMARYKEY_TIMESTAMP_COL_INDEX || pColumnSchema->colId != PRIMARYKEY_TIMESTAMP_COL_INDEX) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), "elapsed only can be applied to primary key"); + } } - pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex); + STableComInfo info = tscGetTableInfo(pTableMetaInfo->pTableMeta); // functions can not be applied to tags @@ -2809,7 +2815,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col if (functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE || functionId == TSDB_FUNC_CSUM) { SColumnIndex indexTS = {.tableIndex = index.tableIndex, .columnIndex = 0}; SExprInfo* pExpr = tscExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &indexTS, TSDB_DATA_TYPE_TIMESTAMP, - TSDB_KEYSIZE, getNewResColId(pCmd), TSDB_KEYSIZE, false); + TSDB_KEYSIZE, 0, TSDB_KEYSIZE, false); tstrncpy(pExpr->base.aliasName, aAggs[TSDB_FUNC_TS_DUMMY].name, sizeof(pExpr->base.aliasName)); SColumnList ids = createColumnList(1, 0, 0); @@ -3130,7 +3136,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col // set the first column ts for top/bottom query int32_t tsFuncId = (functionId == TSDB_FUNC_MAVG) ? TSDB_FUNC_TS_DUMMY : TSDB_FUNC_TS; SColumnIndex index1 = {index.tableIndex, PRIMARYKEY_TIMESTAMP_COL_INDEX}; - pExpr = tscExprAppend(pQueryInfo, tsFuncId, &index1, TSDB_DATA_TYPE_TIMESTAMP, TSDB_KEYSIZE, getNewResColId(pCmd), + pExpr = tscExprAppend(pQueryInfo, tsFuncId, &index1, TSDB_DATA_TYPE_TIMESTAMP, TSDB_KEYSIZE, 0, 0, false); tstrncpy(pExpr->base.aliasName, aAggs[tsFuncId].name, sizeof(pExpr->base.aliasName)); @@ -3156,7 +3162,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col // todo REFACTOR // set the first column ts for top/bottom query SColumnIndex index1 = {index.tableIndex, PRIMARYKEY_TIMESTAMP_COL_INDEX}; - pExpr = tscExprAppend(pQueryInfo, TSDB_FUNC_TS, &index1, TSDB_DATA_TYPE_TIMESTAMP, TSDB_KEYSIZE, getNewResColId(pCmd), + pExpr = tscExprAppend(pQueryInfo, TSDB_FUNC_TS, &index1, TSDB_DATA_TYPE_TIMESTAMP, TSDB_KEYSIZE, 0, 0, false); tstrncpy(pExpr->base.aliasName, aAggs[TSDB_FUNC_TS].name, sizeof(pExpr->base.aliasName)); @@ -4694,7 +4700,12 @@ static int32_t validateSQLExprItem(SSqlCmd* pCmd, tSqlExpr* pExpr, if (pExpr->value.nType == (uint32_t)-1) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); } - + + //now allowing now +/- value in select expr + if (pExpr->tokenId == TK_TIMESTAMP) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); + } + if (pExpr->type == SQL_NODE_VALUE) { *type = SQLEXPR_TYPE_VALUE; } @@ -9526,7 +9537,7 @@ static int32_t doLoadAllTableMeta(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNod char buf[TSDB_TABLE_FNAME_LEN]; SStrToken sTblToken; sTblToken.z = buf; - + if (validateTableName(oriName->z, oriName->n, &sTblToken, &dbIncluded) != TSDB_CODE_SUCCESS) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); } diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 35582973c2af7b214d3054807d31a897c7256191..c72dfd105e410a290e19d4c20db9339fdb09d1f3 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -444,7 +444,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) { } pSql->retryReason = rpcMsg->code; - rpcMsg->code = tscRenewTableMeta(pSql, 0); + rpcMsg->code = tscRenewTableMeta(pSql); // if there is an error occurring, proceed to the following error handling procedure. if (rpcMsg->code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) { taosReleaseRef(tscObjRef, handle); @@ -837,7 +837,7 @@ static int32_t serializeSqlExpr(SSqlExpr* pExpr, STableMetaInfo* pTableMetaInfo, return TSDB_CODE_TSC_INVALID_OPERATION; } - if (pExpr->resColId >= 0) { + if (pExpr->resColId > 0) { tscError("result column id underflowed: %d", pExpr->resColId); return TSDB_CODE_TSC_RES_TOO_MANY; } @@ -3074,28 +3074,46 @@ static void freeElem(void* p) { /** * retrieve table meta from mnode, and then update the local table meta hashmap. * @param pSql sql object - * @param tableIndex table index * @return status code */ -int tscRenewTableMeta(SSqlObj *pSql, int32_t tableIndex) { +int tscRenewTableMeta(SSqlObj *pSql) { + int32_t code = TSDB_CODE_SUCCESS; SSqlCmd* pCmd = &pSql->cmd; SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd); - STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, tableIndex); - char name[TSDB_TABLE_FNAME_LEN] = {0}; - int32_t code = tNameExtractFullName(&pTableMetaInfo->name, name); - if (code != TSDB_CODE_SUCCESS) { - tscError("0x%"PRIx64" failed to generate the table full name", pSql->self); - return TSDB_CODE_TSC_INVALID_OPERATION; - } + SArray* pNameList = taosArrayInit(1, POINTER_BYTES); + SArray* vgroupList = taosArrayInit(1, POINTER_BYTES); - STableMeta* pTableMeta = pTableMetaInfo->pTableMeta; - if (pTableMeta) { - tscDebug("0x%"PRIx64" update table meta:%s, old meta numOfTags:%d, numOfCols:%d, uid:%" PRIu64, pSql->self, name, - tscGetNumOfTags(pTableMeta), tscGetNumOfColumns(pTableMeta), pTableMeta->id.uid); + SHashObj *nameTable = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); + + while (pQueryInfo) { + STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); + + char name[TSDB_TABLE_FNAME_LEN] = {0}; + code = tNameExtractFullName(&pTableMetaInfo->name, name); + if (code != TSDB_CODE_SUCCESS) { + tscError("0x%"PRIx64" failed to generate the table full name", pSql->self); + return TSDB_CODE_TSC_INVALID_OPERATION; + } + + //do not add duplicate names + if (!taosHashGet(nameTable, name, strlen(name))) { + STableMeta* pTableMeta = pTableMetaInfo->pTableMeta; + if (pTableMeta) { + tscDebug("0x%"PRIx64" update table meta:%s, old meta numOfTags:%d, numOfCols:%d, uid:%" PRIu64, pSql->self, name, + tscGetNumOfTags(pTableMeta), tscGetNumOfColumns(pTableMeta), pTableMeta->id.uid); + } + + char* n = strdup(name); + taosArrayPush(pNameList, &n); + uint8_t dummy_val = 0; + taosHashPut(nameTable, name, strlen(name), &dummy_val, sizeof(uint8_t)); + } + pQueryInfo = pQueryInfo->sibling; } + taosHashCleanup(nameTable); // remove stored tableMeta info in hash table tscResetSqlCmd(pCmd, true, pSql->self); @@ -3103,18 +3121,13 @@ int tscRenewTableMeta(SSqlObj *pSql, int32_t tableIndex) { SSqlCmd* pCmd2 = &pSql->rootObj->cmd; pCmd2->pTableMetaMap = tscCleanupTableMetaMap(pCmd2->pTableMetaMap); pCmd2->pTableMetaMap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); - + pSql->rootObj->retryReason = pSql->retryReason; SSqlObj *tmpSql = pSql->rootObj; tscFreeSubobj(pSql->rootObj); tfree(tmpSql->pSubs); - SArray* pNameList = taosArrayInit(1, POINTER_BYTES); - SArray* vgroupList = taosArrayInit(1, POINTER_BYTES); - - char* n = strdup(name); - taosArrayPush(pNameList, &n); code = getMultiTableMetaFromMnode(tmpSql, pNameList, vgroupList, NULL, tscTableMetaCallBack, true); taosArrayDestroyEx(pNameList, freeElem); taosArrayDestroyEx(vgroupList, freeElem); diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 5f8964bb34b5939ab768877cb8ae701e20443f75..bcec2ffc57ba46aea9ffd222aa3bf3d3415ab0de 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -3783,7 +3783,7 @@ void tscSetQuerySort(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAttr) { size_t size = taosArrayGetSize(pQueryInfo->pUpstream); for(int32_t i = 0; i < size; ++i) { SQueryInfo* pq = taosArrayGetP(pQueryInfo->pUpstream, i); - if (pq->groupbyTag && pq->interval.interval > 0) { + if (pq->groupbyTag) { pQueryAttr->needSort = true; return; } diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index bbd448e2d8b5069fae438d7adb9de14a31446d1b..7041c922d9b8ff32d6c1340fe313769cf4cf9729 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -113,7 +113,7 @@ int32_t tscAcquireRpc(const char *key, const char *user, const char *secretEncry SRpcObj rpcObj; memset(&rpcObj, 0, sizeof(rpcObj)); - strncpy(rpcObj.key, key, strlen(key)); + tstrncpy(rpcObj.key, key, sizeof(rpcObj.key)); rpcObj.pDnodeConn = rpcOpen(&rpcInit); if (rpcObj.pDnodeConn == NULL) { pthread_mutex_unlock(&rpcObjMutex); diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index d9207411bdf254eb5d2d62b31105f10b30b6cc16..c995c5591364626b856639ea59f366c1e581c9e7 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -132,8 +132,7 @@ int32_t converToStr(char *str, int type, void *buf, int32_t bufSize, int32_t *le return TSDB_CODE_SUCCESS; } - -static void tscStrToLower(char *str, int32_t n) { +UNUSED_FUNC static void tscStrToLower(char* str, int32_t n) { if (str == NULL || n <= 0) { return;} for (int32_t i = 0; i < n; i++) { if (str[i] >= 'A' && str[i] <= 'Z') { @@ -3029,7 +3028,8 @@ int32_t tscValidateName(SStrToken* pToken, bool escapeEnabled, bool *dbIncluded) if (pToken->type == TK_STRING) { tscDequoteAndTrimToken(pToken); - tscStrToLower(pToken->z, pToken->n); + // tscStrToLower(pToken->z, pToken->n); + strntolower(pToken->z, pToken->z, pToken->n); //pToken->n = (uint32_t)strtrim(pToken->z); int len = tGetToken(pToken->z, &pToken->type); @@ -3083,7 +3083,8 @@ int32_t tscValidateName(SStrToken* pToken, bool escapeEnabled, bool *dbIncluded) if (validateQuoteToken(pToken, escapeEnabled, NULL) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_OPERATION; } else { - tscStrToLower(pToken->z,pToken->n); + // tscStrToLower(pToken->z,pToken->n); + strntolower(pToken->z, pToken->z, pToken->n); firstPartQuote = true; } } @@ -3101,7 +3102,8 @@ int32_t tscValidateName(SStrToken* pToken, bool escapeEnabled, bool *dbIncluded) if (validateQuoteToken(pToken, escapeEnabled, NULL) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_OPERATION; } else { - tscStrToLower(pToken->z,pToken->n); + // tscStrToLower(pToken->z,pToken->n); + strntolower(pToken->z, pToken->z, pToken->n); } } @@ -5524,6 +5526,11 @@ int parseJsontoTagData(char* json, SKVRowBuilder* kvRowBuilder, char* errMsg, in tdAddColToKVRow(kvRowBuilder, jsonIndex++, TSDB_DATA_TYPE_NCHAR, tagVal, true); free(tagVal); }else if(item->type == cJSON_Number){ + if(!isfinite(item->valuedouble)){ + tscError("json value is invalidate"); + retCode = tscSQLSyntaxErrMsg(errMsg, "json value number is illegal", NULL); + goto end; + } char tagVal[LONG_BYTES + CHAR_BYTES] = {0}; *tagVal = jsonType2DbType(item->valuedouble, item->type); // type char* tagData = POINTER_SHIFT(tagVal,CHAR_BYTES); diff --git a/src/connector/C#/src/test/Cases/Utils.cs b/src/connector/C#/src/test/Cases/Utils.cs index 1c2ab137930384c0a85ae2103ff6be0893d7733b..5a2962564fb9063e8994e549f0135cedb36b6ec5 100644 --- a/src/connector/C#/src/test/Cases/Utils.cs +++ b/src/connector/C#/src/test/Cases/Utils.cs @@ -3,7 +3,6 @@ using TDengineDriver; using System.Runtime.InteropServices; using System.Text; using System.Collections.Generic; - namespace Test.UtilsTools { public class UtilsTools diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java index d4c30115f851aa0f8b6f80994bbece609649428d..78420083a1d235036203bb3d57b2617663032d8d 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java @@ -14,13 +14,43 @@ import java.math.BigDecimal; import java.sql.*; import java.time.Instant; import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.time.chrono.IsoChronology; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; import java.time.format.DateTimeParseException; +import java.time.format.ResolverStyle; +import java.time.temporal.ChronoField; import java.util.ArrayList; import java.util.Calendar; import java.util.List; public class RestfulResultSet extends AbstractResultSet implements ResultSet { + public static DateTimeFormatter rfc3339Parser = null; + + { + rfc3339Parser = new DateTimeFormatterBuilder() + .parseCaseInsensitive() + .appendValue(ChronoField.YEAR, 4) + .appendLiteral('-') + .appendValue(ChronoField.MONTH_OF_YEAR, 2) + .appendLiteral('-') + .appendValue(ChronoField.DAY_OF_MONTH, 2) + .appendLiteral('T') + .appendValue(ChronoField.HOUR_OF_DAY, 2) + .appendLiteral(':') + .appendValue(ChronoField.MINUTE_OF_HOUR, 2) + .appendLiteral(':') + .appendValue(ChronoField.SECOND_OF_MINUTE, 2) + .optionalStart() + .appendFraction(ChronoField.NANO_OF_SECOND, 2, 9, true) + .optionalEnd() + .appendOffset("+HH:MM", "Z").toFormatter() + .withResolverStyle(ResolverStyle.STRICT) + .withChronology(IsoChronology.INSTANCE); + } + private final Statement statement; // data private final List> resultSet = new ArrayList<>(); @@ -187,25 +217,41 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet { } case UTC: { String value = row.getString(colIndex); - long epochSec = Timestamp.valueOf(value.substring(0, 19).replace("T", " ")).getTime() / 1000; - int fractionalSec = Integer.parseInt(value.substring(20, value.length() - 5)); - long nanoAdjustment; - if (value.length() > 31) { - // ns timestamp: yyyy-MM-ddTHH:mm:ss.SSSSSSSSS+0x00 - nanoAdjustment = fractionalSec; - this.timestampPrecision = TimestampPrecision.NS; - } else if (value.length() > 28) { - // ms timestamp: yyyy-MM-ddTHH:mm:ss.SSSSSS+0x00 - nanoAdjustment = fractionalSec * 1000L; - this.timestampPrecision = TimestampPrecision.US; + if (value.lastIndexOf(":") > 19) { + ZonedDateTime parse = ZonedDateTime.parse(value, rfc3339Parser); + long nanoAdjustment; + if (value.length() > 32) { + // ns timestamp: yyyy-MM-ddTHH:mm:ss.SSSSSSSSS+0x:00 + this.timestampPrecision = TimestampPrecision.NS; + } else if (value.length() > 29) { + // ms timestamp: yyyy-MM-ddTHH:mm:ss.SSSSSS+0x:00 + this.timestampPrecision = TimestampPrecision.US; + } else { + // ms timestamp: yyyy-MM-ddTHH:mm:ss.SSS+0x:00 + this.timestampPrecision = TimestampPrecision.MS; + } + return Timestamp.from(parse.toInstant()); } else { - // ms timestamp: yyyy-MM-ddTHH:mm:ss.SSS+0x00 - nanoAdjustment = fractionalSec * 1000_000L; - this.timestampPrecision = TimestampPrecision.MS; + long epochSec = Timestamp.valueOf(value.substring(0, 19).replace("T", " ")).getTime() / 1000; + int fractionalSec = Integer.parseInt(value.substring(20, value.length() - 5)); + long nanoAdjustment; + if (value.length() > 32) { + // ns timestamp: yyyy-MM-ddTHH:mm:ss.SSSSSSSSS+0x00 + nanoAdjustment = fractionalSec; + this.timestampPrecision = TimestampPrecision.NS; + } else if (value.length() > 29) { + // ms timestamp: yyyy-MM-ddTHH:mm:ss.SSSSSS+0x00 + nanoAdjustment = fractionalSec * 1000L; + this.timestampPrecision = TimestampPrecision.US; + } else { + // ms timestamp: yyyy-MM-ddTHH:mm:ss.SSS+0x00 + nanoAdjustment = fractionalSec * 1000_000L; + this.timestampPrecision = TimestampPrecision.MS; + } + ZoneOffset zoneOffset = ZoneOffset.of(value.substring(value.length() - 5)); + Instant instant = Instant.ofEpochSecond(epochSec, nanoAdjustment).atOffset(zoneOffset).toInstant(); + return Timestamp.from(instant); } - ZoneOffset zoneOffset = ZoneOffset.of(value.substring(value.length() - 5)); - Instant instant = Instant.ofEpochSecond(epochSec, nanoAdjustment).atOffset(zoneOffset).toInstant(); - return Timestamp.from(instant); } case STRING: default: { diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java index cdcd2eec482cc39e940bf20f6ae636568257faf2..dada75e4a04b035cbe20da72075215c77f1c5883 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java @@ -72,6 +72,7 @@ public class RestfulStatement extends AbstractStatement { } this.database = sql.trim().replace("use", "").trim(); this.conn.setCatalog(this.database); + this.conn.setClientInfo(TSDBDriver.PROPERTY_KEY_DBNAME, this.database); result = false; } else if (SqlSyntaxValidator.isDatabaseUnspecifiedQuery(sql)) { executeOneQuery(sql); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ParameterBindTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ParameterBindTest.java index 46f201d1c0a525f52014d133e25fc0db4741050c..63c3a6318a611f7159c0ac16dc85cd5e05de47c0 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ParameterBindTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ParameterBindTest.java @@ -128,8 +128,8 @@ public class ParameterBindTest { @After public void after() { try { -// Statement stmt = conn.createStatement(); -// stmt.execute("drop database if exists test_pd"); + Statement stmt = conn.createStatement(); + stmt.execute("drop database if exists test_pd"); if (conn != null) conn.close(); } catch (SQLException e) { diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SchemalessInsertTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SchemalessInsertTest.java index 712cc0c8c1b0b094a20db0fe36d33f553878d71d..cc47a47f1cd2f0a0c8efdde5ab7afa39b395a16d 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SchemalessInsertTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SchemalessInsertTest.java @@ -187,7 +187,6 @@ public class SchemalessInsertTest { public void after() { try (Statement stmt = conn.createStatement()) { stmt.execute("drop database if exists " + dbname); - stmt.close(); conn.close(); } catch (SQLException e) { e.printStackTrace(); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBConnectionTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBConnectionTest.java index 64b7ab1cabe2c5815ff87d9881873150f21049c6..c69a556ae4e6c6b31dbb106c7ff4a3e2352296ee 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBConnectionTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBConnectionTest.java @@ -380,8 +380,12 @@ public class TSDBConnectionTest { @AfterClass public static void afterClass() throws SQLException { - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists test"); + statement.close(); conn.close(); + } } } \ No newline at end of file diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDriverTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDriverTest.java index 9f297955d687f3cfcc3acef626e1f905ecee6bdf..609523f522724a9bf49e7ded76d2855cbdda6ac1 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDriverTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDriverTest.java @@ -1,6 +1,5 @@ package com.taosdata.jdbc; -import org.junit.BeforeClass; import org.junit.Test; import java.sql.*; diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java index f44d647595e99ae00a355ca25f702cf2e0c1cc36..f508fbdeed5bf617cf81330985981b5715678472 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java @@ -7,6 +7,7 @@ import org.junit.Test; import java.lang.management.ManagementFactory; import java.lang.management.RuntimeMXBean; import java.sql.SQLException; +import java.sql.SQLWarning; import java.util.ArrayList; import java.util.List; import java.util.Properties; @@ -19,115 +20,111 @@ public class TSDBJNIConnectorTest { private static TSDBResultSetRowData rowData; @Test - public void test() { + public void test() throws SQLException { try { - try { - //change sleepSeconds when debugging with attach to process to find PID - int sleepSeconds = -1; - if (sleepSeconds > 0) { - RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean(); - String jvmName = runtimeBean.getName(); - long pid = Long.valueOf(jvmName.split("@")[0]); - System.out.println("JVM PID = " + pid); - - Thread.sleep(sleepSeconds * 1000); - } - } catch (Exception e) { - e.printStackTrace(); + //change sleepSeconds when debugging with attach to process to find PID + int sleepSeconds = -1; + if (sleepSeconds > 0) { + RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean(); + String jvmName = runtimeBean.getName(); + long pid = Long.valueOf(jvmName.split("@")[0]); + System.out.println("JVM PID = " + pid); + + Thread.sleep(sleepSeconds * 1000); } + } catch (Exception e) { + e.printStackTrace(); + } - // init - Properties properties = new Properties(); - properties.setProperty(TSDBDriver.PROPERTY_KEY_CONFIG_DIR, "/etc/taos"); - TSDBJNIConnector.init(properties); - - // connect - TSDBJNIConnector connector = new TSDBJNIConnector(); - connector.connect("127.0.0.1", 6030, null, "root", "taosdata"); - - // setup - String setupSqlStrs[] = {"create database if not exists d precision \"us\"", - "create table if not exists d.t(ts timestamp, f int)", - "create database if not exists d2", - "create table if not exists d2.t2(ts timestamp, f int)", - "insert into d.t values(now+100s, 100)", - "insert into d2.t2 values(now+200s, 200)" - }; - for (String setupSqlStr : setupSqlStrs) { - long setupSql = connector.executeQuery(setupSqlStr); - - assertEquals(0, connector.getResultTimePrecision(setupSql)); - if (connector.isUpdateQuery(setupSql)) { - connector.freeResultSet(setupSql); - } + // init + Properties properties = new Properties(); + properties.setProperty(TSDBDriver.PROPERTY_KEY_CONFIG_DIR, "/etc/taos"); + TSDBJNIConnector.init(properties); + + // connect + TSDBJNIConnector connector = new TSDBJNIConnector(); + connector.connect("127.0.0.1", 6030, null, "root", "taosdata"); + + // setup + String setupSqlStrs[] = {"create database if not exists d precision \"us\"", + "create table if not exists d.t(ts timestamp, f int)", + "create database if not exists d2", + "create table if not exists d2.t2(ts timestamp, f int)", + "insert into d.t values(now+100s, 100)", + "insert into d2.t2 values(now+200s, 200)" + }; + for (String setupSqlStr : setupSqlStrs) { + long setupSql = connector.executeQuery(setupSqlStr); + + assertEquals(0, connector.getResultTimePrecision(setupSql)); + if (connector.isUpdateQuery(setupSql)) { + connector.freeResultSet(setupSql); } + } - { - long sqlObj1 = connector.executeQuery("select * from d2.t2"); - assertEquals(0, connector.getResultTimePrecision(sqlObj1)); - List columnMetaDataList = new ArrayList<>(); - int code = connector.getSchemaMetaData(sqlObj1, columnMetaDataList); - rowData = new TSDBResultSetRowData(columnMetaDataList.size()); - assertTrue(next(connector, sqlObj1)); - assertEquals(0, connector.getResultTimePrecision(sqlObj1)); - connector.freeResultSet(sqlObj1); - } + { + long sqlObj1 = connector.executeQuery("select * from d2.t2"); + assertEquals(0, connector.getResultTimePrecision(sqlObj1)); + List columnMetaDataList = new ArrayList<>(); + int code = connector.getSchemaMetaData(sqlObj1, columnMetaDataList); + rowData = new TSDBResultSetRowData(columnMetaDataList.size()); + assertTrue(next(connector, sqlObj1)); + assertEquals(0, connector.getResultTimePrecision(sqlObj1)); + connector.freeResultSet(sqlObj1); + } - // executeQuery - long pSql = connector.executeQuery("select * from d.t"); + // executeQuery + long pSql = connector.executeQuery("select * from d.t"); - if (connector.isUpdateQuery(pSql)) { - connector.freeResultSet(pSql); - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEQUERY); - } + if (connector.isUpdateQuery(pSql)) { + connector.freeResultSet(pSql); + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEQUERY); + } - assertEquals(1, connector.getResultTimePrecision(pSql)); + assertEquals(1, connector.getResultTimePrecision(pSql)); - // get schema - List columnMetaDataList = new ArrayList<>(); - int code = connector.getSchemaMetaData(pSql, columnMetaDataList); - if (code == TSDBConstants.JNI_CONNECTION_NULL) { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL); - } - if (code == TSDBConstants.JNI_RESULT_SET_NULL) { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_RESULT_SET_NULL); - } - if (code == TSDBConstants.JNI_NUM_OF_FIELDS_0) { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_NUM_OF_FIELDS_0); - } + // get schema + List columnMetaDataList = new ArrayList<>(); + int code = connector.getSchemaMetaData(pSql, columnMetaDataList); + if (code == TSDBConstants.JNI_CONNECTION_NULL) { + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL); + } + if (code == TSDBConstants.JNI_RESULT_SET_NULL) { + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_RESULT_SET_NULL); + } + if (code == TSDBConstants.JNI_NUM_OF_FIELDS_0) { + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_NUM_OF_FIELDS_0); + } + assertEquals(1, connector.getResultTimePrecision(pSql)); + int columnSize = columnMetaDataList.size(); + // print metadata + for (int i = 0; i < columnSize; i++) { +// System.out.println(columnMetaDataList.get(i)); + } + rowData = new TSDBResultSetRowData(columnSize); + // iterate resultSet + for (int i = 0; next(connector, pSql); i++) { assertEquals(1, connector.getResultTimePrecision(pSql)); - int columnSize = columnMetaDataList.size(); - // print metadata - for (int i = 0; i < columnSize; i++) { - System.out.println(columnMetaDataList.get(i)); - } - rowData = new TSDBResultSetRowData(columnSize); - // iterate resultSet - for (int i = 0; next(connector, pSql); i++) { - assertEquals(1, connector.getResultTimePrecision(pSql)); - System.out.println(); - } - // close resultSet - code = connector.freeResultSet(pSql); - if (code == TSDBConstants.JNI_CONNECTION_NULL) { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL); - } else if (code == TSDBConstants.JNI_RESULT_SET_NULL) { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_RESULT_SET_NULL); - } - // close statement - connector.executeQuery("use d"); - String[] lines = new String[]{ - "st,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000", - "st,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000"}; - connector.insertLines(lines, SchemalessProtocolType.LINE, SchemalessTimestampType.NANO_SECONDS); - - // close connection - connector.closeConnection(); - - } catch (SQLException e) { - e.printStackTrace(); } + // close resultSet + code = connector.freeResultSet(pSql); + if (code == TSDBConstants.JNI_CONNECTION_NULL) { + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL); + } else if (code == TSDBConstants.JNI_RESULT_SET_NULL) { + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_RESULT_SET_NULL); + } + // close statement + connector.executeQuery("use d"); + String[] lines = new String[]{ + "st,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000", + "st,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000"}; + connector.insertLines(lines, SchemalessProtocolType.LINE, SchemalessTimestampType.NANO_SECONDS); + + // close connection + connector.executeQuery("drop database if exists d"); + connector.executeQuery("drop database if exists d2"); + connector.closeConnection(); } private static boolean next(TSDBJNIConnector connector, long pSql) throws SQLException { diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBParameterMetaDataTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBParameterMetaDataTest.java index dc41d85cf38c5fbedb6e5f5c26d593c8c9d5c4d7..56e8b96bbd9dee496969a010b0385c4ecd7f1145 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBParameterMetaDataTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBParameterMetaDataTest.java @@ -17,6 +17,7 @@ public class TSDBParameterMetaDataTest { private static PreparedStatement pstmt_select; private static ParameterMetaData parameterMetaData_insert; private static ParameterMetaData parameterMetaData_select; + private static final String dbname = "test_pstmt"; @Test public void getParameterCount() throws SQLException { @@ -152,9 +153,9 @@ public class TSDBParameterMetaDataTest { try { conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"); try (Statement stmt = conn.createStatement()) { - stmt.execute("drop database if exists test_pstmt"); - stmt.execute("create database if not exists test_pstmt"); - stmt.execute("use test_pstmt"); + stmt.execute("drop database if exists " + dbname); + stmt.execute("create database if not exists " + dbname); + stmt.execute("use " + dbname); stmt.execute("create table weather(ts timestamp, f1 int, f2 bigint, f3 float, f4 double, f5 smallint, f6 tinyint, f7 bool, f8 binary(64), f9 nchar(64)) tags(loc nchar(64))"); stmt.execute("create table t1 using weather tags('beijing')"); } @@ -190,8 +191,12 @@ public class TSDBParameterMetaDataTest { pstmt_insert.close(); if (pstmt_select != null) pstmt_select.close(); - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists " + dbname); + statement.close(); conn.close(); + } } catch (SQLException e) { e.printStackTrace(); } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java index 3d76e1f98d4f8aa1d0ba3d68395e4036c5b069e6..8cb4628884fdd85c1bfd6f24ac311d82687da5ab 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java @@ -1233,6 +1233,7 @@ public class TSDBPreparedStatementTest { try { Statement statement = conn.createStatement(); statement.execute("drop database if exists " + dbname); + statement.execute("drop database if exists dbtest"); statement.close(); if (conn != null) conn.close(); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBResultSetTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBResultSetTest.java index f72cbbec8c1b4c0acad1c83ffcbcb35c1fb8ea7b..7b9083bf9be242f8bcb21565a47d6092675e2d6e 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBResultSetTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBResultSetTest.java @@ -668,8 +668,12 @@ public class TSDBResultSetTest { rs.close(); if (stmt != null) stmt.close(); - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists restful_test"); + statement.close(); conn.close(); + } } catch (SQLException e) { e.printStackTrace(); } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertDbwithoutUseDbTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertDbwithoutUseDbTest.java index 05c7b0feca21f3f5b9062f9cbc26921aa607732a..60edcc506e9fea7bc055322b7b00d0f9e9d75591 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertDbwithoutUseDbTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertDbwithoutUseDbTest.java @@ -1,9 +1,6 @@ package com.taosdata.jdbc.cases; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.FixMethodOrder; -import org.junit.Test; +import org.junit.*; import org.junit.runners.MethodSorters; import java.sql.*; @@ -16,36 +13,32 @@ public class InsertDbwithoutUseDbTest { private static final String host = "127.0.0.1"; private static Properties properties; private static final Random random = new Random(System.currentTimeMillis()); + private static final String dbname = "inWithoutDb"; @Test public void case001() throws SQLException { // prepare schema String url = "jdbc:TAOS://127.0.0.1:6030/?user=root&password=taosdata"; Connection conn = DriverManager.getConnection(url, properties); - try (Statement stmt = conn.createStatement()) { - stmt.execute("drop database if exists inWithoutDb"); - stmt.execute("create database if not exists inWithoutDb"); - stmt.execute("create table inWithoutDb.weather(ts timestamp, f1 int)"); - } + Statement stmt = conn.createStatement(); + stmt.execute("drop database if exists " + dbname); + stmt.execute("create database if not exists " + dbname); + stmt.execute("create table " + dbname + ".weather(ts timestamp, f1 int)"); + conn.close(); // execute insert - url = "jdbc:TAOS://127.0.0.1:6030/inWithoutDb?user=root&password=taosdata"; + url = "jdbc:TAOS://127.0.0.1:6030/" + dbname + "?user=root&password=taosdata"; conn = DriverManager.getConnection(url, properties); - try (Statement stmt = conn.createStatement()) { - int affectedRow = stmt.executeUpdate("insert into weather(ts, f1) values(now," + random.nextInt(100) + ")"); - Assert.assertEquals(1, affectedRow); - boolean flag = stmt.execute("insert into weather(ts, f1) values(now + 10s," + random.nextInt(100) + ")"); - Assert.assertEquals(false, flag); - ResultSet rs = stmt.executeQuery("select count(*) from weather"); - rs.next(); - int count = rs.getInt("count(*)"); - Assert.assertEquals(2, count); - - } catch (SQLException e) { - e.printStackTrace(); - } - + stmt = conn.createStatement(); + int affectedRow = stmt.executeUpdate("insert into weather(ts, f1) values(now," + random.nextInt(100) + ")"); + Assert.assertEquals(1, affectedRow); + boolean flag = stmt.execute("insert into weather(ts, f1) values(now + 10s," + random.nextInt(100) + ")"); + Assert.assertEquals(false, flag); + ResultSet rs = stmt.executeQuery("select count(*) from weather"); + rs.next(); + int count = rs.getInt("count(*)"); + Assert.assertEquals(2, count); conn.close(); } @@ -54,28 +47,25 @@ public class InsertDbwithoutUseDbTest { // prepare the schema final String url = "jdbc:TAOS-RS://" + host + ":6041/inWithoutDb?user=root&password=taosdata"; Connection conn = DriverManager.getConnection(url, properties); - try (Statement stmt = conn.createStatement()) { - stmt.execute("drop database if exists inWithoutDb"); - stmt.execute("create database if not exists inWithoutDb"); - stmt.execute("create table inWithoutDb.weather(ts timestamp, f1 int)"); - } - conn.close(); + Statement stmt = conn.createStatement(); + stmt.execute("drop database if exists " + dbname); + stmt.execute("create database if not exists " + dbname); + stmt.execute("create table " + dbname + ".weather(ts timestamp, f1 int)"); + stmt.close(); // execute - conn = DriverManager.getConnection(url, properties); - try (Statement stmt = conn.createStatement()) { - int affectedRow = stmt.executeUpdate("insert into weather(ts, f1) values(now," + random.nextInt(100) + ")"); - Assert.assertEquals(1, affectedRow); - boolean flag = stmt.execute("insert into weather(ts, f1) values(now + 10s," + random.nextInt(100) + ")"); - Assert.assertEquals(false, flag); - ResultSet rs = stmt.executeQuery("select count(*) from weather"); - rs.next(); - int count = rs.getInt("count(*)"); - Assert.assertEquals(2, count); - - } catch (SQLException e) { - e.printStackTrace(); - } + stmt = conn.createStatement(); + int affectedRow = stmt.executeUpdate("insert into weather(ts, f1) values(now," + random.nextInt(100) + ")"); + Assert.assertEquals(1, affectedRow); + boolean flag = stmt.execute("insert into weather(ts, f1) values(now + 10s," + random.nextInt(100) + ")"); + Assert.assertEquals(false, flag); + ResultSet rs = stmt.executeQuery("select count(*) from weather"); + rs.next(); + int count = rs.getInt("count(*)"); + Assert.assertEquals(2, count); + stmt.execute("drop database if exists " + dbname); + stmt.close(); + conn.close(); } @BeforeClass diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertSpecialCharacterJniTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertSpecialCharacterJniTest.java index ac254bebf39f55b358883716e23ba72b695703f7..7cc1c811d136a974a8cd9b8d4b990fe206c9e98d 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertSpecialCharacterJniTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertSpecialCharacterJniTest.java @@ -427,8 +427,12 @@ public class InsertSpecialCharacterJniTest { @AfterClass public static void afterClass() throws SQLException { - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists " + dbName); + statement.close(); conn.close(); + } } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertSpecialCharacterRestfulTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertSpecialCharacterRestfulTest.java index eedccec6f1ad3aecbaebbd525788a68e7c236511..81e424971c90e75a0ca3e8d14b82eefc45e417c8 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertSpecialCharacterRestfulTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertSpecialCharacterRestfulTest.java @@ -391,8 +391,12 @@ public class InsertSpecialCharacterRestfulTest { @AfterClass public static void afterClass() throws SQLException { - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists "+ dbName); + statement.close(); conn.close(); + } } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/JDBCTypeAndTypeCompareTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/JDBCTypeAndTypeCompareTest.java index eb3b2985dfaff1b956909a50ca23470279cb48ca..38e8d99afe4a9fbca8d7167df482b6c2ac6976d8 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/JDBCTypeAndTypeCompareTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/JDBCTypeAndTypeCompareTest.java @@ -1,19 +1,22 @@ package com.taosdata.jdbc.cases; +import org.junit.AfterClass; import org.junit.Test; import java.sql.*; public class JDBCTypeAndTypeCompareTest { + private static Connection conn; + private static final String dbname = "test"; @Test public void test() throws SQLException { - Connection conn = DriverManager.getConnection("jdbc:TAOS://192.168.17.156:6030/", "root", "taosdata"); + conn = DriverManager.getConnection("jdbc:TAOS://127.0.0.1:6030/", "root", "taosdata"); Statement stmt = conn.createStatement(); - stmt.execute("drop database if exists test"); - stmt.execute("create database if not exists test"); - stmt.execute("use test"); + stmt.execute("drop database if exists " + dbname); + stmt.execute("create database if not exists " + dbname); + stmt.execute("use " + dbname); stmt.execute("create table weather(ts timestamp, f1 int, f2 bigint, f3 float, f4 double, f5 smallint, f6 tinyint, f7 bool, f8 binary(10), f9 nchar(10) )"); stmt.execute("insert into weather values(now, 1, 2, 3.0, 4.0, 5, 6, true, 'test','test')"); @@ -29,6 +32,19 @@ public class JDBCTypeAndTypeCompareTest { } stmt.close(); - conn.close(); + } + + @AfterClass + public static void afterClass() { + try { + if (null != conn) { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists " + dbname); + statement.close(); + conn.close(); + } + } catch (SQLException e) { + e.printStackTrace(); + } } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MicroSecondPrecisionJNITest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MicroSecondPrecisionJNITest.java index eb8f134227713e4c41224dc6a561916427290864..0889170e656910181fe39f844e585c11f0d78d5e 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MicroSecondPrecisionJNITest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MicroSecondPrecisionJNITest.java @@ -47,7 +47,7 @@ public class MicroSecondPrecisionJNITest { Assert.assertEquals(timestamp2 % 1000_000l * 1000, nanos); ts = rs.getLong(1); - Assert.assertEquals(timestamp1, ts); + Assert.assertEquals(timestamp2, ts); } catch (SQLException e) { e.printStackTrace(); } @@ -79,8 +79,13 @@ public class MicroSecondPrecisionJNITest { @AfterClass public static void afterClass() { try { - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database " + ms_timestamp_db); + statement.execute("drop database " + us_timestamp_db); + statement.close(); conn.close(); + } } catch (SQLException e) { e.printStackTrace(); } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MicroSecondPrecisionRestfulTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MicroSecondPrecisionRestfulTest.java index f418436a4afac5f16b27789eb43081f131bf1f92..48c5ef8a463452dc205c43247678bfd0f3e761a2 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MicroSecondPrecisionRestfulTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MicroSecondPrecisionRestfulTest.java @@ -47,7 +47,7 @@ public class MicroSecondPrecisionRestfulTest { Assert.assertEquals(timestamp2 % 1000_000l * 1000, nanos); ts = rs.getLong(1); - Assert.assertEquals(timestamp1, ts); + Assert.assertEquals(timestamp2, ts); } } @@ -77,7 +77,7 @@ public class MicroSecondPrecisionRestfulTest { Assert.assertEquals(timestamp2 % 1000_000l * 1000, nanos); ts = rs.getLong(1); - Assert.assertEquals(timestamp1, ts); + Assert.assertEquals(timestamp2, ts); } } @@ -107,7 +107,7 @@ public class MicroSecondPrecisionRestfulTest { Assert.assertEquals(timestamp2 % 1000_000l * 1000, nanos); ts = rs.getLong(1); - Assert.assertEquals(timestamp1, ts); + Assert.assertEquals(timestamp2, ts); } } @@ -142,12 +142,21 @@ public class MicroSecondPrecisionRestfulTest { } @AfterClass - public static void afterClass() throws SQLException { - if (conn1 != null) - conn1.close(); - if (conn2 != null) - conn2.close(); - if (conn3 != null) - conn3.close(); + public static void afterClass() { + try { + if (conn1 != null) { + Statement statement = conn1.createStatement(); + statement.execute("drop database if exists " + ms_timestamp_db); + statement.execute("drop database if exists " + us_timestamp_db); + statement.close(); + conn1.close(); + } + if (conn2 != null) + conn2.close(); + if (conn3 != null) + conn3.close(); + }catch (SQLException e){ + e.printStackTrace(); + } } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MultiConnectionWithDifferentDbTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MultiConnectionWithDifferentDbTest.java index 0bf8334079e630bf61b7955a37c74401da24a947..220ac0e7ce023229c1e897b9125a4ebb2cae3687 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MultiConnectionWithDifferentDbTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MultiConnectionWithDifferentDbTest.java @@ -1,5 +1,6 @@ package com.taosdata.jdbc.cases; +import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -90,4 +91,16 @@ public class MultiConnectionWithDifferentDbTest { } } + @After + public void after() { + String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"; + try (Connection connection = DriverManager.getConnection(url); + Statement statement = connection.createStatement()) { + statement.execute("drop database if exists " + db1); + statement.execute("drop database if exists " + db2); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NanoSecondTimestampJNITest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NanoSecondTimestampJNITest.java index a84f5233974e9bd9acdbbe3ca8ae0404c11b34a1..c85c6f95a93df565cd5ff8eca91c0beeac3b3c02 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NanoSecondTimestampJNITest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NanoSecondTimestampJNITest.java @@ -1,9 +1,6 @@ package com.taosdata.jdbc.cases; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.*; import java.sql.*; import java.time.Instant; @@ -83,9 +80,9 @@ public class NanoSecondTimestampJNITest { // then long actual = rs.getLong(1); - Assert.assertEquals(ms, actual); + Assert.assertEquals(ns, actual); actual = rs.getLong("ts"); - Assert.assertEquals(ms, actual); + Assert.assertEquals(ns, actual); } @Test @@ -160,4 +157,18 @@ public class NanoSecondTimestampJNITest { } } + @AfterClass + public static void afterClass(){ + try { + if (null != conn){ + Statement statement = conn.createStatement(); + statement.execute("drop database if exists " + dbname); + statement.close(); + conn.close(); + } + }catch (SQLException e){ + e.printStackTrace(); + } + } + } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NanoSecondTimestampRestfulTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NanoSecondTimestampRestfulTest.java index c8aaf5c6788d18e782e431ba4ed97fb69f4702ab..796f21ed21bb69e952042e89f61e0eb98fcf4273 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NanoSecondTimestampRestfulTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NanoSecondTimestampRestfulTest.java @@ -1,9 +1,6 @@ package com.taosdata.jdbc.cases; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.*; import java.sql.*; import java.time.Instant; @@ -83,9 +80,9 @@ public class NanoSecondTimestampRestfulTest { // then long actual = rs.getLong(1); - Assert.assertEquals(ms, actual); + Assert.assertEquals(ns, actual); actual = rs.getLong("ts"); - Assert.assertEquals(ms, actual); + Assert.assertEquals(ns, actual); } @Test @@ -160,4 +157,14 @@ public class NanoSecondTimestampRestfulTest { } } + @AfterClass + public static void afterClass() throws SQLException { + if (conn != null){ + try (Statement stmt = conn.createStatement()) { + stmt.execute("drop database if exists " + dbname); + } + conn.close(); + } + } + } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetJNITest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetJNITest.java index 6efd9f5ebee29a122c2106439117738c44241597..8bbc2fe077a1292b24ee7cb67158620c96f9a605 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetJNITest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetJNITest.java @@ -45,7 +45,11 @@ public class NullValueInResultSetJNITest { @After public void after() throws SQLException { - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists test_null"); + statement.close(); conn.close(); + } } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetRestfulTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetRestfulTest.java index f331a58583db832124465492d07f24f1772348ce..08f641b96e86398d72d9ab42ccaed57e2227ecdc 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetRestfulTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetRestfulTest.java @@ -47,7 +47,11 @@ public class NullValueInResultSetRestfulTest { @After public void after() throws SQLException { - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists test_null"); + statement.close(); conn.close(); + } } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetTest.java index 61d767b5cf2bcd2e478de74e5f4bb8d66ad21678..890505ac65cf02deb85dd362ebd700291317e849 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetTest.java @@ -85,7 +85,11 @@ public class NullValueInResultSetTest { public static void afterClass() throws SQLException { if (conn_restful != null) conn_restful.close(); - if (conn_jni != null) + if (conn_jni != null) { + Statement statement = conn_jni.createStatement(); + statement.execute("drop database if exists test_null"); + statement.close(); conn_jni.close(); + } } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TimestampPrecisionInNanoInJniTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TimestampPrecisionInNanoInJniTest.java index 2d336135e5d1dc28db010387ab838f17d9b9a9cc..76053ccc41895fcdc00ffe9da2252bf63313894e 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TimestampPrecisionInNanoInJniTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TimestampPrecisionInNanoInJniTest.java @@ -62,8 +62,12 @@ public class TimestampPrecisionInNanoInJniTest { @AfterClass public static void afterClass() { try { - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists " + ns_timestamp_db); + statement.close(); conn.close(); + } } catch (SQLException e) { e.printStackTrace(); } @@ -83,7 +87,7 @@ public class TimestampPrecisionInNanoInJniTest { int nanos = rs.getTimestamp(1).getNanos(); Assert.assertEquals(ts % 1000_000_000l, nanos); long test_ts = rs.getLong(1); - Assert.assertEquals(ts / 1000_000l, test_ts); + Assert.assertEquals(ts, test_ts); } @Test diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TimestampPrecisonInNanoRestTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TimestampPrecisonInNanoRestTest.java index cfd6a066acc2c2abd94e525fb69d4027a317134c..4aedf867d408536fde6896e01f61ef13873d1624 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TimestampPrecisonInNanoRestTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TimestampPrecisonInNanoRestTest.java @@ -62,8 +62,12 @@ public class TimestampPrecisonInNanoRestTest { @AfterClass public static void afterClass() { try { - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists " + ns_timestamp_db); + statement.close(); conn.close(); + } } catch (SQLException e) { e.printStackTrace(); } @@ -83,7 +87,7 @@ public class TimestampPrecisonInNanoRestTest { int nanos = rs.getTimestamp(1).getNanos(); Assert.assertEquals(ts % 1000_000_000l, nanos); long test_ts = rs.getLong(1); - Assert.assertEquals(ts / 1000_000l, test_ts); + Assert.assertEquals(ts, test_ts); } @Test diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UnsignedNumberJniTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UnsignedNumberJniTest.java index 0be6b90e7a9b5e1e7707b88c1c60d2751b7d245b..cff353093aca6772e96a88f1083bc428a49ab9b2 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UnsignedNumberJniTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UnsignedNumberJniTest.java @@ -156,8 +156,12 @@ public class UnsignedNumberJniTest { @AfterClass public static void afterClass() throws SQLException { - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists unsign_jni"); + statement.close(); conn.close(); + } } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UnsignedNumberRestfulTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UnsignedNumberRestfulTest.java index 842dbfeff8478115df93b48cfe29fe376c4cff05..b3ca6871db7cbf0888737856e66d236c4cc80d49 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UnsignedNumberRestfulTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UnsignedNumberRestfulTest.java @@ -14,6 +14,7 @@ public class UnsignedNumberRestfulTest { private static final String host = "127.0.0.1"; private static Connection conn; private static long ts; + private static final String dbname = "unsign_restful"; @Test public void testCase001() throws SQLException { @@ -148,9 +149,9 @@ public class UnsignedNumberRestfulTest { final String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"; conn = DriverManager.getConnection(url, properties); Statement stmt = conn.createStatement(); - stmt.execute("drop database if exists unsign_restful"); - stmt.execute("create database if not exists unsign_restful"); - stmt.execute("use unsign_restful"); + stmt.execute("drop database if exists " + dbname); + stmt.execute("create database if not exists " + dbname); + stmt.execute("use " + dbname); stmt.execute("create table us_table(ts timestamp, f1 tinyint unsigned, f2 smallint unsigned, f3 int unsigned, f4 bigint unsigned)"); stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(" + ts + ", 127, 32767,2147483647, 9223372036854775807)"); stmt.close(); @@ -162,8 +163,12 @@ public class UnsignedNumberRestfulTest { @AfterClass public static void afterClass() { try { - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists " + dbname); + statement.close(); conn.close(); + } } catch (SQLException e) { e.printStackTrace(); } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UseNowInsertTimestampTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UseNowInsertTimestampTest.java index 2e0448bc248bb2a962466e632443d4e6d918ab9f..c4f2cba446e6138679ae9f8b8efff3666c056deb 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UseNowInsertTimestampTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UseNowInsertTimestampTest.java @@ -1,5 +1,6 @@ package com.taosdata.jdbc.cases; +import org.junit.AfterClass; import org.junit.Test; import java.sql.*; @@ -8,7 +9,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; public class UseNowInsertTimestampTest { - String url = "jdbc:TAOS://127.0.0.1:6030/?user=root&password=taosdata"; + private static String url = "jdbc:TAOS://127.0.0.1:6030/?user=root&password=taosdata"; @Test public void millisec() throws SQLException { @@ -55,13 +56,14 @@ public class UseNowInsertTimestampTest { @Test public void nanosec() throws SQLException { + long now_time = System.currentTimeMillis() * 1000_000L + System.nanoTime() % 1000_000L; try (Connection conn = DriverManager.getConnection(url)) { Statement stmt = conn.createStatement(); stmt.execute("drop database if exists test"); stmt.execute("create database if not exists test precision 'ns'"); stmt.execute("use test"); stmt.execute("create table weather(ts timestamp, f1 int)"); - stmt.execute("insert into weather values(now, 1)"); + stmt.execute("insert into weather values(" + now_time + ", 1)"); ResultSet rs = stmt.executeQuery("select * from weather"); rs.next(); @@ -74,4 +76,15 @@ public class UseNowInsertTimestampTest { stmt.execute("drop database if exists test"); } } + + @AfterClass + public static void afterClass() { + try (Connection conn = DriverManager.getConnection(url); + Statement stmt = conn.createStatement()) { + stmt.execute("drop database if exists test"); + } catch (SQLException e) { + e.printStackTrace(); + } + + } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/BadLocaleSettingTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/BadLocaleSettingTest.java index bbf71349b85c7bdc51fde30f293c7cd724de3699..7ad7c23136f8e24b0c7139e97fb4b46c04a98abb 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/BadLocaleSettingTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/BadLocaleSettingTest.java @@ -45,7 +45,11 @@ public class BadLocaleSettingTest { @AfterClass public static void afterClass() throws SQLException { - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database " + dbName); + statement.close(); conn.close(); + } } } \ No newline at end of file diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/BatchFetchTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/BatchFetchTest.java index e8c799e86c61c6b4a7cb8b3396c6c3e09548ee0e..94a5382410ba05c1fbf3afb4f8bb73d6c5271c3a 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/BatchFetchTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/BatchFetchTest.java @@ -79,4 +79,15 @@ public class BatchFetchTest { } return builder.toString(); } + + @AfterClass + public static void afterClass(){ + String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"; + try (Connection conn = DriverManager.getConnection(url); + Statement stmt = conn.createStatement()) { + stmt.execute("drop database if exists test"); + } catch (SQLException e) { + e.printStackTrace(); + } + } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/CharsetTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/CharsetTest.java index e28faeb280a9f9f9ae931e7b610910fb912278b3..41629189aea4658514bd317c90bc055340397a23 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/CharsetTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/CharsetTest.java @@ -1,6 +1,7 @@ package com.taosdata.jdbc.confprops; import com.taosdata.jdbc.TSDBDriver; +import org.junit.AfterClass; import org.junit.Assert; import org.junit.Test; @@ -37,4 +38,18 @@ public class CharsetTest { } } + @AfterClass + public static void afterClass(){ + String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"; + Properties props = new Properties(); + props.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); + + try (Connection conn = DriverManager.getConnection(url, props); + Statement stmt = conn.createStatement()) { + stmt.execute("drop database if exists test"); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/TimeZoneTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/TimeZoneTest.java index 6569aa5f085f5d389144a9e8ddc0787786f9fff3..bc19e63ba6e05c8170366de4375148ebde0138d0 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/TimeZoneTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/TimeZoneTest.java @@ -29,7 +29,7 @@ public class TimeZoneTest { } @Test - public void taosTimeZone() { + public void taosTimeZone() throws SQLException { // given Properties props = new Properties(); props.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); @@ -39,7 +39,7 @@ public class TimeZoneTest { Statement stmt = connection.createStatement(); stmt.execute("drop database if exists timezone_test"); - stmt.execute("create database if not exists timezone_test keep 365000"); + stmt.execute("create database if not exists timezone_test keep 36500"); stmt.execute("use timezone_test"); stmt.execute("create table weather(ts timestamp, temperature float)"); @@ -51,7 +51,7 @@ public class TimeZoneTest { System.out.println("ts: " + ts.getTime() + "," + ts); } - stmt.execute("insert into timezone_test.weather(ts, temperature, humidity) values('1970-01-02 00:00:00', 1.0, 2.0)"); + stmt.execute("insert into timezone_test.weather(ts, temperature) values('1970-01-02 00:00:00', 1.0)"); rs = stmt.executeQuery("select * from timezone_test.weather"); while (rs.next()) { @@ -63,8 +63,6 @@ public class TimeZoneTest { stmt.execute("drop database if exists timezone_test"); stmt.close(); - } catch (SQLException e) { - e.printStackTrace(); } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/TimestampFormatTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/TimestampFormatTest.java index 7e3701c153fa3f45852dd1a5860cf30910dc906d..a6f8cf7c0ad79d1a046a5075f05f6930ea1d19ce 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/TimestampFormatTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/TimestampFormatTest.java @@ -1,17 +1,17 @@ package com.taosdata.jdbc.confprops; import com.taosdata.jdbc.TSDBDriver; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.*; import java.sql.*; import java.time.Instant; +import java.util.Calendar; import java.util.Properties; public class TimestampFormatTest { private static final String host = "127.0.0.1"; private long ts = Instant.now().toEpochMilli(); + private Connection conn; @Test public void string() throws SQLException { @@ -154,13 +154,27 @@ public class TimestampFormatTest { @Before public void before() throws SQLException { String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"; - try (Connection conn = DriverManager.getConnection(url); - Statement stmt = conn.createStatement()) { - stmt.execute("drop database if exists test"); - stmt.execute("create database if not exists test"); - stmt.execute("use test"); - stmt.execute("create table weather(ts timestamp, temperature nchar(10))"); - stmt.execute("insert into weather values(" + ts + ", '北京')"); + conn = DriverManager.getConnection(url); + Statement stmt = conn.createStatement(); + stmt.execute("drop database if exists test"); + stmt.execute("create database if not exists test"); + stmt.execute("use test"); + stmt.execute("create table weather(ts timestamp, temperature nchar(10))"); + stmt.execute("insert into weather values(" + ts + ", '北京')"); + stmt.close(); + } + + @After + public void after() { + try { + if (null != conn) { + Statement stmt = conn.createStatement(); + stmt.execute("drop database if exists test"); + stmt.close(); + conn.close(); + } + } catch (SQLException e) { + e.printStackTrace(); } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/DatabaseSpecifiedTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/DatabaseSpecifiedTest.java index 9fe51e7203fac7133783e47fd5b0cc07f33b2494..0a37e255a4ac8e8db2b07fc915ab7ba6dd54397c 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/DatabaseSpecifiedTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/DatabaseSpecifiedTest.java @@ -33,7 +33,6 @@ public class DatabaseSpecifiedTest { String loc = rs.getString("loc"); assertEquals("beijing", loc); } - connection.close(); } @Before @@ -59,8 +58,12 @@ public class DatabaseSpecifiedTest { @After public void after() { try { - if (connection != null) + if (connection != null) { + Statement statement = connection.createStatement(); + statement.execute("drop database if exists " + dbname); + statement.close(); connection.close(); + } } catch (SQLException e) { e.printStackTrace(); } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulConnectionTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulConnectionTest.java index e7ce1d76f123a043d49eb64931c0d537d09664df..e4785a197e659977ae22745e14e664fd803464f7 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulConnectionTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulConnectionTest.java @@ -383,8 +383,12 @@ public class RestfulConnectionTest { @AfterClass public static void afterClass() throws SQLException { - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists test"); + statement.close(); conn.close(); + } } } \ No newline at end of file diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulParameterMetaDataTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulParameterMetaDataTest.java index 81d7f5b56c4b4e67b9573522ee031006a7e11a2b..c8ca1a5de7ac870c01d248a8b042cffefa4857b7 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulParameterMetaDataTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulParameterMetaDataTest.java @@ -18,6 +18,7 @@ public class RestfulParameterMetaDataTest { private static PreparedStatement pstmt_select; private static ParameterMetaData parameterMetaData_insert; private static ParameterMetaData parameterMetaData_select; + private static final String dbname = "test_pstmt"; @Test public void getParameterCount() throws SQLException { @@ -148,9 +149,9 @@ public class RestfulParameterMetaDataTest { Class.forName("com.taosdata.jdbc.rs.RestfulDriver"); conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"); try (Statement stmt = conn.createStatement()) { - stmt.execute("drop database if exists test_pstmt"); - stmt.execute("create database if not exists test_pstmt"); - stmt.execute("use test_pstmt"); + stmt.execute("drop database if exists " + dbname); + stmt.execute("create database if not exists " + dbname); + stmt.execute("use " + dbname); stmt.execute("create table weather(ts timestamp, f1 int, f2 bigint, f3 float, f4 double, f5 smallint, f6 tinyint, f7 bool, f8 binary(64), f9 nchar(64)) tags(loc nchar(64))"); stmt.execute("create table t1 using weather tags('beijing')"); } @@ -186,8 +187,12 @@ public class RestfulParameterMetaDataTest { pstmt_insert.close(); if (pstmt_select != null) pstmt_select.close(); - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists " + dbname); + statement.close(); conn.close(); + } } catch (SQLException e) { e.printStackTrace(); } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulPreparedStatementTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulPreparedStatementTest.java index 4760a723e4b4e662326987290c2c630803f8f470..40d0e0214fe1016df8d42e9dfd8d31472165c798 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulPreparedStatementTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulPreparedStatementTest.java @@ -400,8 +400,12 @@ public class RestfulPreparedStatementTest { pstmt_select.close(); if (pstmt_without_parameters != null) pstmt_without_parameters.close(); - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists test_pstmt"); + statement.close(); conn.close(); + } } catch (SQLException e) { e.printStackTrace(); } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulResultSetMetaDataTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulResultSetMetaDataTest.java index f3011af799c987ed399920875ae512fd8533ec77..6e5851474f2697022eef5dc62be3f69ca5878df9 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulResultSetMetaDataTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulResultSetMetaDataTest.java @@ -15,6 +15,7 @@ public class RestfulResultSetMetaDataTest { private static Statement stmt; private static ResultSet rs; private static ResultSetMetaData meta; + private static final String dbname = "restful_test"; @Test public void getColumnCount() throws SQLException { @@ -206,8 +207,12 @@ public class RestfulResultSetMetaDataTest { rs.close(); if (stmt != null) stmt.close(); - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists " + dbname); + statement.close(); conn.close(); + } } catch (SQLException e) { e.printStackTrace(); } diff --git a/src/connector/nodejs/nodetaos/cinterface.js b/src/connector/nodejs/nodetaos/cinterface.js index fa0eb20055df38c2a8092637e30ae807e473fa30..2403ffa4c68ca9571f2ec583fa263765208bfb2b 100644 --- a/src/connector/nodejs/nodetaos/cinterface.js +++ b/src/connector/nodejs/nodetaos/cinterface.js @@ -14,7 +14,12 @@ const _ = require('lodash') const TaosObjects = require('./taosobjects'); module.exports = CTaosInterface; - +const TAOSFIELD = { + NAME_LENGTH: 65, + TYPE_OFFSET: 65, + BYTES_OFFSET: 66, + STRUCT_SIZE: 68, +} function convertTimestamp(data, num_of_rows, nbytes = 0, offset = 0, precision = 0) { data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset); let res = []; @@ -195,6 +200,24 @@ function convertNchar(data, num_of_rows, nbytes = 0, offset = 0, precision = 0) return res; } +function convertJsonTag(data, num_of_rows, nbytes = 0, offset = 0, precision = 0) { + data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset); + let res = []; + + let currOffset = 0; + while (currOffset < data.length) { + let len = data.readIntLE(currOffset, 2); + let dataEntry = data.slice(currOffset + 2, currOffset + len + 2); //one entry in a row under a column; + if (dataEntry[0] == 255 && dataEntry[1] == 255) { + res.push(null) + } else { + res.push(dataEntry.toString("utf-8")); + } + currOffset += nbytes; + } + return res; +} + // Object with all the relevant converters from pblock data to javascript readable data let convertFunctions = { [FieldTypes.C_BOOL]: convertBool, @@ -210,7 +233,8 @@ let convertFunctions = { [FieldTypes.C_TINYINT_UNSIGNED]: convertTinyintUnsigned, [FieldTypes.C_SMALLINT_UNSIGNED]: convertSmallintUnsigned, [FieldTypes.C_INT_UNSIGNED]: convertIntUnsigned, - [FieldTypes.C_BIGINT_UNSIGNED]: convertBigintUnsigned + [FieldTypes.C_BIGINT_UNSIGNED]: convertBigintUnsigned, + [FieldTypes.C_JSON_TAG]: convertJsonTag, } // Define TaosField structure @@ -219,8 +243,8 @@ var TaosField = Struct({ 'name': char_arr, }); TaosField.fields.name.type.size = 65; -TaosField.defineProperty('type', ref.types.char); -TaosField.defineProperty('bytes', ref.types.short); +TaosField.defineProperty('type', ref.types.uint8); +TaosField.defineProperty('bytes', ref.types.int16); //define schemaless line array var smlLine = ArrayType(ref.coerceType('char *')) @@ -390,14 +414,14 @@ CTaosInterface.prototype.useResult = function useResult(result) { let fields = []; let pfields = this.fetchFields(result); + if (ref.isNull(pfields) == false) { - pfields = ref.reinterpret(pfields, this.fieldsCount(result) * 68, 0); - for (let i = 0; i < pfields.length; i += 68) { - //0 - 63 = name //64 - 65 = bytes, 66 - 67 = type + pfields = ref.reinterpret(pfields, this.fieldsCount(result) * TAOSFIELD.STRUCT_SIZE, 0); + for (let i = 0; i < pfields.length; i += TAOSFIELD.STRUCT_SIZE) { fields.push({ - name: ref.readCString(ref.reinterpret(pfields, 65, i)), - type: pfields[i + 65], - bytes: pfields[i + 66] + name: ref.readCString(ref.reinterpret(pfields, TAOSFIELD.NAME_LENGTH, i)), + type: pfields[i + TAOSFIELD.TYPE_OFFSET], + bytes: pfields[i + TAOSFIELD.BYTES_OFFSET] + pfields[i + TAOSFIELD.BYTES_OFFSET + 1] * 256 }) } } @@ -532,13 +556,12 @@ CTaosInterface.prototype.fetchFields_a = function fetchFields_a(result) { let pfieldscount = this.numFields(result); let fields = []; if (ref.isNull(pfields) == false) { - pfields = ref.reinterpret(pfields, 68 * pfieldscount, 0); - for (let i = 0; i < pfields.length; i += 68) { - //0 - 64 = name //65 = type, 66 - 67 = bytes + pfields = ref.reinterpret(pfields, pfieldscount * TAOSFIELD.STRUCT_SIZE, 0); + for (let i = 0; i < pfields.length; i += TAOSFIELD.STRUCT_SIZE) { fields.push({ - name: ref.readCString(ref.reinterpret(pfields, 65, i)), - type: pfields[i + 65], - bytes: pfields[i + 66] + name: ref.readCString(ref.reinterpret(pfields, TAOSFIELD.NAME_LENGTH, i)), + type: pfields[i + TAOSFIELD.TYPE_OFFSET], + bytes: pfields[i + TAOSFIELD.BYTES_OFFSET] + pfields[i + TAOSFIELD.BYTES_OFFSET + 1] * 256 }) } } @@ -594,13 +617,12 @@ CTaosInterface.prototype.consume = function consume(subscription) { let fields = []; let pfields = this.fetchFields(result); if (ref.isNull(pfields) == false) { - pfields = ref.reinterpret(pfields, this.numFields(result) * 68, 0); - for (let i = 0; i < pfields.length; i += 68) { - //0 - 63 = name //64 - 65 = bytes, 66 - 67 = type + pfields = ref.reinterpret(pfields, this.numFields(result) * TAOSFIELD.STRUCT_SIZE, 0); + for (let i = 0; i < pfields.length; i += TAOSFIELD.STRUCT_SIZE) { fields.push({ - name: ref.readCString(ref.reinterpret(pfields, 64, i)), - bytes: pfields[i + 64], - type: pfields[i + 66] + name: ref.readCString(ref.reinterpret(pfields, TAOSFIELD.NAME_LENGTH, i)), + bytes: pfields[TAOSFIELD.TYPE_OFFSET], + type: pfields[i + TAOSFIELD.BYTES_OFFSET] + pfields[i + TAOSFIELD.BYTES_OFFSET + 1] * 256 }) } } @@ -684,23 +706,23 @@ CTaosInterface.prototype.closeStream = function closeStream(stream) { * @returns TAOS_RES * */ -CTaosInterface.prototype.schemalessInsert = function schemalessInsert(connection,lines, protocal, precision) { +CTaosInterface.prototype.schemalessInsert = function schemalessInsert(connection, lines, protocal, precision) { let _numLines = null; let _lines = null; - - if(_.isString(lines)){ + + if (_.isString(lines)) { _numLines = 1; _lines = Buffer.alloc(_numLines * ref.sizeof.pointer); - ref.set(_lines,0,ref.allocCString(lines),ref.types.char_ptr); + ref.set(_lines, 0, ref.allocCString(lines), ref.types.char_ptr); } - else if(_.isArray(lines)){ + else if (_.isArray(lines)) { _numLines = lines.length; _lines = Buffer.alloc(_numLines * ref.sizeof.pointer); - for(let i = 0; i < _numLines ; i++){ - ref.set(_lines,i*ref.sizeof.pointer,ref.allocCString(lines[i]),ref.types.char_ptr) + for (let i = 0; i < _numLines; i++) { + ref.set(_lines, i * ref.sizeof.pointer, ref.allocCString(lines[i]), ref.types.char_ptr) } } - else{ + else { throw new errors.InterfaceError("Unsupport lines input") } return this.libtaos.taos_schemaless_insert(connection, _lines, _numLines, protocal, precision); diff --git a/src/connector/nodejs/nodetaos/constants.js b/src/connector/nodejs/nodetaos/constants.js index 551cfce71677fbd6635a76884474e1b1aeac7ab9..b055e0ed01522348556475fa72e8bf34a9d3fe70 100644 --- a/src/connector/nodejs/nodetaos/constants.js +++ b/src/connector/nodejs/nodetaos/constants.js @@ -6,13 +6,13 @@ const SCHEMALESS_PROTOCOL = { TSDB_SML_JSON_PROTOCOL: 3 } const SCHEMALESS_PRECISION = { - TSDB_SML_TIMESTAMP_NOT_CONFIGURED : 0, - TSDB_SML_TIMESTAMP_HOURS : 1, - TSDB_SML_TIMESTAMP_MINUTES : 2, - TSDB_SML_TIMESTAMP_SECONDS : 3, - TSDB_SML_TIMESTAMP_MILLI_SECONDS : 4, - TSDB_SML_TIMESTAMP_MICRO_SECONDS : 5, - TSDB_SML_TIMESTAMP_NANO_SECONDS : 6 + TSDB_SML_TIMESTAMP_NOT_CONFIGURED: 0, + TSDB_SML_TIMESTAMP_HOURS: 1, + TSDB_SML_TIMESTAMP_MINUTES: 2, + TSDB_SML_TIMESTAMP_SECONDS: 3, + TSDB_SML_TIMESTAMP_MILLI_SECONDS: 4, + TSDB_SML_TIMESTAMP_MICRO_SECONDS: 5, + TSDB_SML_TIMESTAMP_NANO_SECONDS: 6 } const typeCodesToName = { 0: 'Null', @@ -30,6 +30,7 @@ const typeCodesToName = { 12: 'Smallint Unsigned', 13: 'Int Unsigned', 14: 'Bigint Unsigned', + 15: 'Json', } /** @@ -80,6 +81,7 @@ module.exports = { C_SMALLINT_UNSIGNED: 12, C_INT_UNSIGNED: 13, C_BIGINT_UNSIGNED: 14, + C_JSON_TAG: 15, // NULL value definition // NOTE: These values should change according to C definition in tsdb.h C_BOOL_NULL: 2, diff --git a/src/connector/nodejs/nodetaos/taosresult.js b/src/connector/nodejs/nodetaos/taosresult.js index 4138ebbec6e1b792691d17a25b7c18d35b6a922a..1ea5abee9f6c3c2754081ad82ecdb51c3b5bd4d3 100644 --- a/src/connector/nodejs/nodetaos/taosresult.js +++ b/src/connector/nodejs/nodetaos/taosresult.js @@ -29,19 +29,19 @@ function TaosResult(data, fields) { TaosResult.prototype.pretty = function pretty() { let fieldsStr = ""; let sizing = []; - this.fields.forEach((field,i) => { - if (field._field.type == 8 || field._field.type == 10){ + this.fields.forEach((field, i) => { + if (field._field.type == 8 || field._field.type == 10 ) { sizing.push(Math.max(field.name.length, field._field.bytes)); } else { sizing.push(Math.max(field.name.length, suggestedMinWidths[field._field.type])); } - fieldsStr += fillEmpty(Math.floor(sizing[i]/2 - field.name.length / 2)) + field.name + fillEmpty(Math.ceil(sizing[i]/2 - field.name.length / 2)) + " | "; + fieldsStr += fillEmpty(Math.floor(sizing[i] / 2 - field.name.length / 2)) + field.name + fillEmpty(Math.ceil(sizing[i] / 2 - field.name.length / 2)) + " | "; }); - var sumLengths = sizing.reduce((a,b)=> a+=b,(0)) + sizing.length * 3; + var sumLengths = sizing.reduce((a, b) => a += b, (0)) + sizing.length * 3; console.log("\n" + fieldsStr); - console.log(printN("=",sumLengths)); + console.log(printN("=", sumLengths)); this.data.forEach(row => { let rowStr = ""; row.data.forEach((entry, i) => { @@ -62,16 +62,21 @@ const suggestedMinWidths = { 2: 4, 3: 6, 4: 11, - 5: 12, + 5: 20, 6: 24, 7: 24, 8: 10, 9: 25, 10: 10, + 11: 4, + 12: 6, + 13: 11, + 14: 20, + 15: 20, } function printN(s, n) { let f = ""; - for (let i = 0; i < n; i ++) { + for (let i = 0; i < n; i++) { f += s; } return f; diff --git a/src/connector/nodejs/package.json b/src/connector/nodejs/package.json index d7eba48a463643dd293960251f6eebcb253d93c4..3d8dfc7e0135d8d5e8ba0eacf110d527f9e3f7bf 100644 --- a/src/connector/nodejs/package.json +++ b/src/connector/nodejs/package.json @@ -7,7 +7,7 @@ "test": "test" }, "scripts": { - "test": "node test/test.js && node test/testMicroseconds.js && node test/testNanoseconds.js && node test/testUnsignedType.js && node test/testSchemalessInsert.js " + "test": "node test/test.js && node test/testMicroseconds.js && node test/testNanoseconds.js && node test/testUnsignedType.js && node test/testSchemalessInsert.js && node test/testJsonTag.js" }, "repository": { "type": "git", diff --git a/src/connector/nodejs/test/testJsonTag.js b/src/connector/nodejs/test/testJsonTag.js new file mode 100644 index 0000000000000000000000000000000000000000..a922afb8e6b6614b208a6ba7cd82a8d00f983282 --- /dev/null +++ b/src/connector/nodejs/test/testJsonTag.js @@ -0,0 +1,280 @@ +const taos = require('../tdengine'); +var conn = taos.connect({ host: "127.0.0.1", user: "root", password: "taosdata", config: "/etc/taos", port: 10 }); +var c1 = conn.cursor(); + +function executeUpdate(sql) { + console.log(sql); + c1.execute(sql); +} +function executeQuery(sql, flag = "all") { + console.log(sql); + c1.execute(sql) + var data = c1.fetchall(); + if (flag == "metadata" || flag == "all") { + // Latest query's Field metadata is stored in cursor.fields + console.log(c1.fields); + } 2 + if (flag == "data" || flag == "all") { + // Latest query's result data is stored in cursor.data, also returned by fetchall. + console.log(c1.data); + } + console.log(""); +} + +function prettyQuery(sql) { + try { + c1.query(sql).execute().then(function (result) { + result.pretty(); + }); + } + catch (err) { + conn.close(); + throw err; + } +} + +function executeError(sql) { + console.log(sql); + try { + c1.execute(sql) + } catch (e) { + console.log(e.message); + console.log(""); + } +} + +executeUpdate("create database if not exists nodedb keep 36500;"); +executeUpdate("use nodedb;"); +console.log("# STEP 1 prepare data & validate json string"); +executeUpdate("create table if not exists jsons1(ts timestamp, dataInt int, dataBool bool, dataStr nchar(50), dataStrBin binary(150)) tags(jtag json);"); +executeUpdate("insert into jsons1_1 using jsons1 tags('{\"tag1\":\"fff\",\"tag2\":5, \"tag3\":true}') values(1591060618000, 1, false, 'json1', '涛思数据') (1591060608000, 23, true, '涛思数据', 'json')"); +executeUpdate("insert into jsons1_2 using jsons1 tags('{\"tag1\":5,\"tag2\":\"beijing\"}') values (1591060628000, 2, true, 'json2', 'sss')"); +executeUpdate("insert into jsons1_3 using jsons1 tags('{\"tag1\":false,\"tag2\":\"beijing\"}') values (1591060668000, 3, false, 'json3', 'efwe')"); +executeUpdate("insert into jsons1_4 using jsons1 tags('{\"tag1\":null,\"tag2\":\"shanghai\",\"tag3\":\"hello\"}') values (1591060728000, 4, true, 'json4', '323sd')"); +executeUpdate("insert into jsons1_5 using jsons1 tags('{\"tag1\":1.232, \"tag2\":null}') values(1591060928000, 1, false, '涛思数据', 'ewe')"); +executeUpdate("insert into jsons1_6 using jsons1 tags('{\"tag1\":11,\"tag2\":\"\",\"tag2\":null}') values(1591061628000, 11, false, '涛思数据','')"); +executeUpdate("insert into jsons1_7 using jsons1 tags('{\"tag1\":\"涛思数据\",\"tag2\":\"\",\"tag3\":null}') values(1591062628000, 2, NULL, '涛思数据', 'dws')"); + +console.log("## test duplicate key using the first one. elimate empty key"); +executeUpdate("CREATE TABLE if not exists jsons1_8 using jsons1 tags('{\"tag1\":null, \"tag1\":true, \"tag1\":45, \"1tag$\":2, \" \":90}')"); + +console.log("## test empty json string, save as jtag is NULL"); +executeUpdate("insert into jsons1_9 using jsons1 tags('\t') values (1591062328000, 24, NULL, '涛思数据', '2sdw')"); +executeUpdate("CREATE TABLE if not exists jsons1_10 using jsons1 tags('')"); +executeUpdate("CREATE TABLE if not exists jsons1_11 using jsons1 tags(' ')"); +executeUpdate("CREATE TABLE if not exists jsons1_12 using jsons1 tags('{}')"); +executeUpdate("CREATE TABLE if not exists jsons1_13 using jsons1 tags('null')"); + +console.log("## test invalidate json"); +executeError("CREATE TABLE if not exists jsons1_14 using jsons1 tags('\"efwewf\"')"); +executeError("CREATE TABLE if not exists jsons1_14 using jsons1 tags('3333')"); +executeError("CREATE TABLE if not exists jsons1_14 using jsons1 tags('33.33')"); +executeError("CREATE TABLE if not exists jsons1_14 using jsons1 tags('false')"); +executeError("CREATE TABLE if not exists jsons1_14 using jsons1 tags('[1,true]')"); +executeError("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{222}')"); +executeError("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"fe\"}')"); +executeQuery("select * from jsons1;", "data"); + +console.log("## test invalidate json key, key must can be printed assic char="); +executeError("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"tag1\":[1,true]}')"); +executeError("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"tag1\":{}}')"); +executeError("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"。loc\":\"fff\"}')"); +executeError("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"\":\"fff\"}')"); +executeError("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"\t\":\"fff\"}')"); +executeError("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"涛思数据\":\"fff\"}')"); + +console.log("# STEP 2 alter table json tag"); +executeError("ALTER STABLE jsons1 add tag tag2 nchar(20)"); +executeError("ALTER STABLE jsons1 drop tag jtag"); +executeError("ALTER TABLE jsons1_1 SET TAG jtag=4"); +executeUpdate("ALTER TABLE jsons1_1 SET TAG jtag='{\"tag1\":\"femail\",\"tag2\":35,\"tag3\":true}'") + +console.log("# STEP 3 query table"); +console.log("## test error syntax"); +executeError("select * from jsons1 where jtag->tag1='beijing'"); +executeError("select * from jsons1 where jtag->'location'"); +executeError("select * from jsons1 where jtag->''"); +executeError("select * from jsons1 where jtag->''=9"); +executeError("select -> from jsons1"); +executeError("select * from jsons1 where contains"); +executeError("select * from jsons1 where jtag->"); +executeError("select jtag->location from jsons1"); +executeError("select jtag contains location from jsons1"); +executeError("select * from jsons1 where jtag contains location"); +executeError("select * from jsons1 where jtag contains''"); +executeError("select * from jsons1 where jtag contains 'location'='beijing'"); + +console.log("## test select normal column"); +executeQuery("select dataint from jsons1"); + +console.log("## test select json tag"); +executeQuery("select * from jsons1", "data") +executeQuery("select jtag from jsons1", "data"); +executeQuery("select jtag from jsons1 where jtag is null", "data"); +executeQuery("select jtag from jsons1 where jtag is not null", "data"); +executeQuery("select jtag from jsons1_8", "data"); +executeQuery("select jtag from jsons1_1", "data"); + +console.log("## test jtag is NULL"); +executeQuery("select jtag from jsons1_9", "data"); + +console.log("## test select json tag->'key', value is string"); +executeQuery("select jtag->'tag1' from jsons1_1", "data"); +executeQuery("select jtag->'tag2' from jsons1_6", "data"); + +console.log("### test select json tag->'key', value is int"); +executeQuery("select jtag->'tag2' from jsons1_1", "data"); + +console.log("### test select json tag->'key', value is bool"); +executeQuery("select jtag->'tag3' from jsons1_1", "data"); + +console.log("### test select json tag->'key', value is null"); +executeQuery("select jtag->'tag1' from jsons1_4", "data"); + +console.log("### test select json tag->'key', value is double"); +executeQuery("select jtag->'tag1' from jsons1_5", "data"); + +console.log("### test select json tag->'key', key is not exist"); +executeQuery("select jtag->'tag10' from jsons1_4", "data"); +executeQuery("select jtag->'tag1' from jsons1", "data"); + +console.log("### test header name"); +executeQuery("select jtag->'tag1' from jsons1", "metadata"); + +console.log("## test where with json tag"); +executeError("select * from jsons1_1 where jtag is not null"); +executeError("select * from jsons1 where jtag='{\"tag1\":11,\"tag2\":\"\"}'"); +executeError("select * from jsons1 where jtag->'tag1'={}"); + +console.log("### where json value is string"); +executeQuery("select * from jsons1 where jtag->'tag2'='beijing'", "data"); +executeQuery("select dataint,tbname,jtag->'tag1',jtag from jsons1 where jtag->'tag2'='beijing'"); +executeQuery("select * from jsons1 where jtag->'tag1'='beijing'", "data"); +executeQuery("select * from jsons1 where jtag->'tag1'='涛思数据'", "data"); +executeQuery("select * from jsons1 where jtag->'tag2'>'beijing'", "data"); +executeQuery("select * from jsons1 where jtag->'tag2'>='beijing'", "data"); +executeQuery("select * from jsons1 where jtag->'tag2'<'beijing'", "data"); +executeQuery("select * from jsons1 where jtag->'tag2'<='beijing'", "data"); +executeQuery("select * from jsons1 where jtag->'tag2'!='beijing'", "data"); +executeQuery("select * from jsons1 where jtag->'tag2'=''", "data"); + +console.log("### where json value is int"); +executeQuery("select * from jsons1 where jtag->'tag1'=5", "data"); +executeQuery("select * from jsons1 where jtag->'tag1'=10", "data"); +executeQuery("select * from jsons1 where jtag->'tag1'<54", "data"); +executeQuery("select * from jsons1 where jtag->'tag1'<=11", "data"); +executeQuery("select * from jsons1 where jtag->'tag1'>4", "data"); +executeQuery("select * from jsons1 where jtag->'tag1'>=5", "data"); +executeQuery("select * from jsons1 where jtag->'tag1'!=5", "data"); +executeQuery("select * from jsons1 where jtag->'tag1'!=55", "data"); + +console.log("### where json value is double"); +executeQuery("select * from jsons1 where jtag->'tag1'=1.232", "data"); +executeQuery("select * from jsons1 where jtag->'tag1'<1.232", "data"); +executeQuery("select * from jsons1 where jtag->'tag1'<=1.232", "data"); +executeQuery("select * from jsons1 where jtag->'tag1'>1.23", "data"); +executeQuery("select * from jsons1 where jtag->'tag1'>=1.232", "data"); +executeQuery("select * from jsons1 where jtag->'tag1'!=1.232", "data"); +executeQuery("select * from jsons1 where jtag->'tag1'!=3.232", "data"); +executeError("select * from jsons1 where jtag->'tag1'/0=3", "data"); +executeError("select * from jsons1 where jtag->'tag1'/5=1", "data"); + +console.log("### where json value is bool"); +executeQuery("select * from jsons1 where jtag->'tag1'=true", "data"); +executeQuery("select * from jsons1 where jtag->'tag1'=false", "data"); +executeQuery("select * from jsons1 where jtag->'tag1'!=false", "data"); +executeError("select * from jsons1 where jtag->'tag1'>false"); + +console.log("### where json value is null"); +executeQuery("select * from jsons1 where jtag->'tag1'=null"); //only json suport =null. This synatx will change later. + +console.log("### where json is null"); +executeQuery("select * from jsons1 where jtag is null", "data"); +executeQuery("select * from jsons1 where jtag is not null", "data"); + +console.log("### where json key is null"); +executeQuery("select * from jsons1 where jtag->'tag_no_exist'=3", "data") + +console.log("### where json value is not exist"); +executeQuery("select * from jsons1 where jtag->'tag1' is null", "data"); +executeQuery("select * from jsons1 where jtag->'tag4' is null", "data"); +executeQuery("select * from jsons1 where jtag->'tag3' is not null", "data") + +console.log("### test contains"); +executeQuery("select * from jsons1 where jtag contains 'tag1'", "data") +executeQuery("select * from jsons1 where jtag contains 'tag3'", "data") +executeQuery("select * from jsons1 where jtag contains 'tag_no_exist'", "data") + +console.log("### test json tag in where condition with and/or"); +executeQuery("select * from jsons1 where jtag->'tag1'=false and jtag->'tag2'='beijing'", "data"); +executeQuery("select * from jsons1 where jtag->'tag1'=false or jtag->'tag2'='beijing'", "data"); +executeQuery("select * from jsons1 where jtag->'tag1'=false and jtag->'tag2'='shanghai'", "data"); +executeQuery("select * from jsons1 where jtag->'tag1'=false and jtag->'tag2'='shanghai'", "data"); +executeQuery("select * from jsons1 where jtag->'tag1'=13 or jtag->'tag2'>35", "data"); +executeQuery("select * from jsons1 where jtag->'tag1'=13 or jtag->'tag2'>35", "data"); +executeQuery("select * from jsons1 where jtag->'tag1' is not null and jtag contains 'tag3'", "data"); +executeQuery("select * from jsons1 where jtag->'tag1'='femail' and jtag contains 'tag3'", "data"); + +console.log("### test with tbname/normal column"); +executeQuery("select * from jsons1 where tbname = 'jsons1_1'", "data") +executeQuery("select * from jsons1 where tbname = 'jsons1_1' and jtag contains 'tag3'", "data") +executeQuery("select * from jsons1 where tbname = 'jsons1_1' and jtag contains 'tag3' and dataint=3", "data") +executeQuery("select * from jsons1 where tbname = 'jsons1_1' and jtag contains 'tag3' and dataint=23", "data") + +console.log("### test where condition like"); +executeQuery("select *,tbname from jsons1 where jtag->'tag2' like 'bei%'", "data"); +executeQuery("select *,tbname from jsons1 where jtag->'tag1' like 'fe%' and jtag->'tag2' is not null", "data"); + +console.log("### test where condition in no support in"); +executeError("select * from jsons1 where jtag->'tag1' in ('beijing')"); + +console.log("### test where condition match"); +executeQuery("select * from jsons1 where jtag->'tag1' match 'ma'", "data"); +executeQuery("select * from jsons1 where jtag->'tag1' match 'ma$'", "data"); +executeQuery("select * from jsons1 where jtag->'tag2' match 'jing$'", "data"); +executeQuery("select * from jsons1 where jtag->'tag1' match '收到'", "data"); + +console.log("### test distinct"); +executeUpdate("insert into jsons1_14 using jsons1 tags('{\"tag1\":\"涛思数据\",\"tag2\":\"\",\"tag3\":null}') values(1591062628000, 2, NULL, '涛思数据', 'dws')", "data"); +executeQuery("select distinct jtag->'tag1' from jsons1", "data"); +executeQuery("select distinct jtag from jsons1", "data"); + +console.log("### test dumplicate key with normal colomn"); +executeUpdate("INSERT INTO jsons1_15 using jsons1 tags('{\"tbname\":\"tt\",\"databool\":true,\"datastr\":\"涛思数据\"}') values(1591060828000, 4, false, 'jjsf', \"涛思数据\")"); +executeQuery("select *,tbname,jtag from jsons1 where jtag->'datastr' match '涛思' and datastr match 'js'", "data"); +executeQuery("select tbname,jtag->'tbname' from jsons1 where jtag->'tbname'='tt' and tbname='jsons1_14'", "data"); + +console.log("## test join"); +executeUpdate("create table if not exists jsons2(ts timestamp, dataInt int, dataBool bool, dataStr nchar(50), dataStrBin binary(150)) tags(jtag json)") +executeUpdate("insert into jsons2_1 using jsons2 tags('{\"tag1\":\"fff\",\"tag2\":5, \"tag3\":true}') values(1591060618000, 2, false, 'json2', '你是2')") +executeUpdate("insert into jsons2_2 using jsons2 tags('{\"tag1\":5,\"tag2\":null}') values (1591060628000, 2, true, 'json2', 'sss')") +executeUpdate("create table if not exists jsons3(ts timestamp, dataInt int, dataBool bool, dataStr nchar(50), dataStrBin binary(150)) tags(jtag json)") +executeUpdate("insert into jsons3_1 using jsons3 tags('{\"tag1\":\"fff\",\"tag2\":5, \"tag3\":true}') values(1591060618000, 3, false, 'json3', '你是3')") +executeUpdate("insert into jsons3_2 using jsons3 tags('{\"tag1\":5,\"tag2\":\"beijing\"}') values (1591060638000, 2, true, 'json3', 'sss')") + +executeQuery("select 'sss',33,a.jtag->'tag3' from jsons2 a,jsons3 b where a.ts=b.ts and a.jtag->'tag1'=b.jtag->'tag1'", "data"); +executeQuery("select 'sss',33,a.jtag->'tag3' from jsons2 a,jsons3 b where a.ts=b.ts and a.jtag->'tag1'=b.jtag->'tag1'", "metadata"); + +console.log("## test group by & order by json tag"); + +executeQuery("select count(*) from jsons1 group by jtag->'tag1' order by jtag->'tag1' desc", "data"); +executeQuery("select count(*) from jsons1 group by jtag->'tag1' order by jtag->'tag1' asc", "data"); + +console.log("## test stddev with group by json tag"); +executeQuery("select stddev(dataint) from jsons1 group by jtag->'tag1'", "data"); +executeQuery("select stddev(dataint) from jsons1 group by jsons1.jtag->'tag1'", "metadata"); + +console.log("## test top/bottom with group by json tag"); +executeQuery("select top(dataint,100) from jsons1 group by jtag->'tag1'", "metadata"); + +console.log("## subquery with json tag"); +executeQuery("select * from (select jtag, dataint from jsons1)", "metadata"); +executeQuery("select jtag->'tag1' from (select jtag->'tag1', dataint from jsons1)", "metadata"); +executeQuery("select jtag->'tag1' from (select jtag->'tag1', dataint from jsons1)", "metada"); +executeQuery("select ts,tbname,jtag->'tag1' from (select jtag->'tag1',tbname,ts from jsons1 order by ts)", "data") + + +executeUpdate("drop database nodedb;"); + + +setTimeout(() => conn.close(), 2000); diff --git a/src/connector/nodejs/test/testUnsignedType.js b/src/connector/nodejs/test/testUnsignedType.js index 14b102972a898c582e0011698bfd7b3cd771bc42..3f0b0c20459959fe7ea863757220ea77fe377694 100644 --- a/src/connector/nodejs/test/testUnsignedType.js +++ b/src/connector/nodejs/test/testUnsignedType.js @@ -1,14 +1,6 @@ const taos = require('../tdengine'); var conn = taos.connect({ host: "127.0.0.1", user: "root", password: "taosdata", config: "/etc/taos", port: 10 }); var c1 = conn.cursor(); -executeUpdate("create database if not exists nodedb;"); -executeUpdate("use nodedb;"); -executeUpdate("create table if not exists unsigntest(ts timestamp,ut tinyint unsigned,us smallint unsigned,ui int unsigned,ub bigint unsigned,bi bigint);"); -executeUpdate("insert into unsigntest values (now, 254,65534,4294967294,18446744073709551614,9223372036854775807);"); -executeUpdate("insert into unsigntest values (now, 0,0,0,0,-9223372036854775807);"); -executeQuery("select * from unsigntest;"); -executeUpdate("drop database if exists nodedb;"); - function executeUpdate(sql) { console.log(sql); c1.execute(sql); @@ -21,5 +13,28 @@ function executeQuery(sql) { // Latest query's result data is stored in cursor.data, also returned by fetchall. console.log(c1.data); } + +function prettyQuery(sql){ + try { + c1.query(sql).execute().then(function(result){ + result.pretty(); + }); + } + catch (err) { + conn.close(); + throw err; + } +} + +executeUpdate("create database nodedb;"); +executeUpdate("use nodedb;"); +executeUpdate("create table unsigntest(ts timestamp,ut tinyint unsigned,us smallint unsigned,ui int unsigned,ub bigint unsigned,bi bigint);"); +executeUpdate("insert into unsigntest values (now, 254,65534,4294967294,18446744073709551614,9223372036854775807);"); +executeUpdate("insert into unsigntest values (now, 0,0,0,0,-9223372036854775807);"); +executeQuery("select * from unsigntest;"); +prettyQuery("select * from unsigntest;"); +executeUpdate("drop database nodedb;"); + + setTimeout(()=>conn.close(),2000); diff --git a/src/mnode/src/mnodeVgroup.c b/src/mnode/src/mnodeVgroup.c index 838aa577ae0fe396f3e80d2fca9066de10d3bc7a..fd6d60c034c702e12a5d996f5b130e54bf3c6a4f 100644 --- a/src/mnode/src/mnodeVgroup.c +++ b/src/mnode/src/mnodeVgroup.c @@ -298,7 +298,7 @@ void mnodeCheckUnCreatedVgroup(SDnodeObj *pDnode, SVnodeLoad *pVloads, int32_t o if (have) continue; - if (pVgroup->status == TAOS_VG_STATUS_CREATING || pVgroup->status == TAOS_VG_STATUS_DROPPING) { + if (/*pVgroup->status == TAOS_VG_STATUS_CREATING ||*/ pVgroup->status == TAOS_VG_STATUS_DROPPING) { mDebug("vgId:%d, not exist in dnode:%d and status is %s, do nothing", pVgroup->vgId, pDnode->dnodeId, vgroupStatus[pVgroup->status]); } else { diff --git a/src/plugins/http/inc/httpInt.h b/src/plugins/http/inc/httpInt.h index de595907659ffc84c42afb7802b1a7902b126ea1..2aa01244c6877a8ec614fbe5a2f63f296f3df4f5 100644 --- a/src/plugins/http/inc/httpInt.h +++ b/src/plugins/http/inc/httpInt.h @@ -37,7 +37,7 @@ #define HTTP_BUFFER_SIZE 8388608 #define HTTP_STEP_SIZE 4096 //http message get process step by step #define HTTP_METHOD_SCANNER_SIZE 7 //http method fp size -#define HTTP_GC_TARGET_SIZE 512 +#define HTTP_GC_TARGET_SIZE 16384 #define HTTP_WRITE_RETRY_TIMES 500 #define HTTP_WRITE_WAIT_TIME_MS 5 #define HTTP_PASSWORD_LEN TSDB_UNI_LEN diff --git a/src/plugins/http/src/httpGcJson.c b/src/plugins/http/src/httpGcJson.c index 2d361d37940a93c3627ef53883a342d12183e6a1..7e4658b36465e88e30ceb4315730d784becb99d4 100644 --- a/src/plugins/http/src/httpGcJson.c +++ b/src/plugins/http/src/httpGcJson.c @@ -130,14 +130,34 @@ bool gcBuildQueryJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result, // for group by if (groupFields != -1) { char target[HTTP_GC_TARGET_SIZE] = {0}; - int32_t len; - len = snprintf(target, HTTP_GC_TARGET_SIZE, "%s{", aliasBuffer); + int32_t len = 0, cur = 0; + cur = snprintf(target, HTTP_GC_TARGET_SIZE, "%s{", aliasBuffer); + if (cur < 0 || cur >= HTTP_GC_TARGET_SIZE) { + httpError("context:%p, fd:%d, too long alias: %s", pContext, pContext->fd, aliasBuffer); + return false; + } + + len += cur; for (int32_t i = dataFields + 1; i < num_fields; i++) { + // -2 means the last '}' and '\0' +#define HTTP_GC_CHECK_SIZE(name) if (cur < 0 || cur >= HTTP_GC_TARGET_SIZE - len - 2) { \ + if (cur < 0) { \ + httpError("context:%p, fd:%d, failed to snprintf for: %s", pContext, pContext->fd, name); \ + } else { \ + httpError("context:%p, fd:%d, snprintf overflow for: %s", pContext, pContext->fd, name); \ + target[len] = '\0'; \ + } \ + break; \ + } else { \ + len += cur; \ + } if (row[i] == NULL) { - len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "%s:nil", fields[i].name); + cur = snprintf(target + len, HTTP_GC_TARGET_SIZE - len - 2, "%s:nil", fields[i].name); + HTTP_GC_CHECK_SIZE(fields[i].name) if (i < num_fields - 1) { - len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, ", "); + cur = snprintf(target + len, HTTP_GC_TARGET_SIZE - len - 2, ", "); + HTTP_GC_CHECK_SIZE(fields[i].name) } continue; @@ -146,40 +166,49 @@ bool gcBuildQueryJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result, switch (fields[i].type) { case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_TINYINT: - len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "%s:%d", fields[i].name, *((int8_t *)row[i])); + cur = snprintf(target + len, HTTP_GC_TARGET_SIZE - len - 2, "%s:%d", fields[i].name, *((int8_t *)row[i])); + HTTP_GC_CHECK_SIZE(fields[i].name) break; case TSDB_DATA_TYPE_SMALLINT: - len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "%s:%d", fields[i].name, *((int16_t *)row[i])); + cur = snprintf(target + len, HTTP_GC_TARGET_SIZE - len - 2, "%s:%d", fields[i].name, *((int16_t *)row[i])); + HTTP_GC_CHECK_SIZE(fields[i].name) break; case TSDB_DATA_TYPE_INT: - len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "%s:%d,", fields[i].name, *((int32_t *)row[i])); + cur = snprintf(target + len, HTTP_GC_TARGET_SIZE - len - 2, "%s:%d,", fields[i].name, *((int32_t *)row[i])); + HTTP_GC_CHECK_SIZE(fields[i].name) break; case TSDB_DATA_TYPE_BIGINT: - len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "%s:%" PRId64, fields[i].name, *((int64_t *)row[i])); + cur = snprintf(target + len, HTTP_GC_TARGET_SIZE - len - 2, "%s:%" PRId64, fields[i].name, *((int64_t *)row[i])); + HTTP_GC_CHECK_SIZE(fields[i].name) break; case TSDB_DATA_TYPE_FLOAT: - len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "%s:%.5f", fields[i].name, GET_FLOAT_VAL(row[i])); + cur = snprintf(target + len, HTTP_GC_TARGET_SIZE - len - 2, "%s:%.5f", fields[i].name, GET_FLOAT_VAL(row[i])); + HTTP_GC_CHECK_SIZE(fields[i].name) break; case TSDB_DATA_TYPE_DOUBLE: - len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "%s:%.9f", fields[i].name, GET_DOUBLE_VAL(row[i])); + cur = snprintf(target + len, HTTP_GC_TARGET_SIZE - len - 2, "%s:%.9f", fields[i].name, GET_DOUBLE_VAL(row[i])); + HTTP_GC_CHECK_SIZE(fields[i].name) break; case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_NCHAR: if (row[i] != NULL) { - len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "%s:", fields[i].name); - memcpy(target + len, (char *)row[i], length[i]); + cur = snprintf(target + len, HTTP_GC_TARGET_SIZE - len - 2, "%s:", fields[i].name); + HTTP_GC_CHECK_SIZE(fields[i].name) + memcpy(target + len, (char *)row[i], MIN(length[i], HTTP_GC_TARGET_SIZE - len - 3)); len = (int32_t)strlen(target); } break; default: - len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "%s:%s", fields[i].name, "-"); + cur = snprintf(target + len, HTTP_GC_TARGET_SIZE - len - 2, "%s:%s", fields[i].name, "-"); + HTTP_GC_CHECK_SIZE(fields[i].name) break; } if (i < num_fields - 1) { - len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, ", "); + cur = snprintf(target + len, HTTP_GC_TARGET_SIZE - len - 2, ", "); + HTTP_GC_CHECK_SIZE(fields[i].name) } } - len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "}"); + cur = snprintf(target + len, HTTP_GC_TARGET_SIZE - len - 1, "}"); if (strcmp(target, targetBuffer) != 0) { // first target not write this section diff --git a/src/query/inc/tdigest.h b/src/query/inc/tdigest.h index 625311eaabebec1f3d3b8303f34a361ba0129094..f9b615318f5c33f0cf386653367ddfe36ae759f8 100644 --- a/src/query/inc/tdigest.h +++ b/src/query/inc/tdigest.h @@ -29,7 +29,7 @@ #define DOUBLE_MAX 1.79e+308 #define ADDITION_CENTROID_NUM 2 -#define COMPRESSION 400 +#define COMPRESSION 300 #define GET_CENTROID(compression) (ceil(compression * M_PI / 2) + 1 + ADDITION_CENTROID_NUM) #define GET_THRESHOLD(compression) (7.5 + 0.37 * compression - 2e-4 * pow(compression, 2)) #define TDIGEST_SIZE(compression) (sizeof(TDigest) + sizeof(SCentroid)*GET_CENTROID(compression) + sizeof(SPt)*GET_THRESHOLD(compression)) diff --git a/src/query/src/qPlan.c b/src/query/src/qPlan.c index 4c61cbb0f730780c6c7106a02c765974b2d21706..389f188258bbb471addf21c08562bba3bb56da40 100644 --- a/src/query/src/qPlan.c +++ b/src/query/src/qPlan.c @@ -588,6 +588,13 @@ SArray* createExecOperatorPlan(SQueryAttr* pQueryAttr) { op = OP_Fill; taosArrayPush(plan, &op); } + // outer query order by support + int32_t orderColId = pQueryAttr->order.orderColId; + + if (pQueryAttr->vgId == 0 && orderColId != INT32_MIN) { + op = OP_Order; + taosArrayPush(plan, &op); + } } } else if (pQueryAttr->groupbyColumn) { @@ -658,7 +665,7 @@ SArray* createExecOperatorPlan(SQueryAttr* pQueryAttr) { // outer query order by support int32_t orderColId = pQueryAttr->order.orderColId; - if (pQueryAttr->vgId == 0 && orderColId != PRIMARYKEY_TIMESTAMP_COL_INDEX && orderColId != INT32_MIN) { + if (pQueryAttr->vgId == 0 && orderColId != INT32_MIN) { op = OP_Order; taosArrayPush(plan, &op); } diff --git a/src/query/src/queryMain.c b/src/query/src/queryMain.c index 2a2ccf9cae0f9e2aab60bddca7c27a8ceb719239..9bdb0efc4d3ed7769aa99ded02e460fe0624ae27 100644 --- a/src/query/src/queryMain.c +++ b/src/query/src/queryMain.c @@ -279,6 +279,7 @@ bool qTableQuery(qinfo_t qinfo, uint64_t *qId) { if (isQueryKilled(pQInfo)) { qDebug("QInfo:0x%"PRIx64" it is already killed, abort", pQInfo->qId); + setQueryKilled(pQInfo); pQInfo->runtimeEnv.outputBuf = NULL; return doBuildResCheck(pQInfo); } diff --git a/src/tfs/src/tfs.c b/src/tfs/src/tfs.c index 43ccb324b235c2bfed6b121ed2049474cc5ecb74..b3aabe177bd4c34151cbe2778825bed6262679ab 100644 --- a/src/tfs/src/tfs.c +++ b/src/tfs/src/tfs.c @@ -265,7 +265,10 @@ int tfsMkdirRecurAt(const char *rname, int level, int id) { if (errno == ENOENT) { // Try to create upper char *s = strdup(rname); - + if (strcmp(s, ".") == 0){ // TD-12238, if mkdir failed, rname will be ".", it will be always failed, so need to jump recursion + free(s); + return -1; + } // Make a copy of dirname(s) because the implementation of 'dirname' differs on different platforms. // Some platform may modify the contents of the string passed into dirname(). Others may return a pointer to // internal static storage space that will be overwritten by next call. For case like that, we should not use diff --git a/src/util/src/tlog.c b/src/util/src/tlog.c index 232d10a7d07594c9c62cd13767c320da27af2a73..7b5dafcc8e771ba7d6e7b5691226bbc84a556ef8 100644 --- a/src/util/src/tlog.c +++ b/src/util/src/tlog.c @@ -131,7 +131,7 @@ void taosCloseLog() { taosStopLog(); //tsem_post(&(tsLogObj.logHandle->buffNotEmpty)); taosMsleep(MAX_LOG_INTERVAL/1000); - if (taosCheckPthreadValid(tsLogObj.logHandle->asyncThread)) { + if (tsLogObj.logHandle && taosCheckPthreadValid(tsLogObj.logHandle->asyncThread)) { pthread_join(tsLogObj.logHandle->asyncThread, NULL); } // In case that other threads still use log resources causing invalid write in valgrind diff --git a/src/util/src/tnettest.c b/src/util/src/tnettest.c index 8dc2d4c993e001c95f63d72c60db8b8fe3ac3df8..7d1076abbf1eb0c35385b769bfc6a88cfd8a21a7 100644 --- a/src/util/src/tnettest.c +++ b/src/util/src/tnettest.c @@ -356,7 +356,7 @@ static int32_t taosNetCheckRpc(const char* serverFqdn, uint16_t port, uint16_t p epSet.inUse = 0; epSet.numOfEps = 1; epSet.port[0] = port; - strcpy(epSet.fqdn[0], serverFqdn); + tstrncpy(epSet.fqdn[0], serverFqdn, sizeof(epSet.fqdn[0])); reqMsg.msgType = TSDB_MSG_TYPE_NETWORK_TEST; reqMsg.pCont = rpcMallocCont(pktLen); @@ -364,7 +364,7 @@ static int32_t taosNetCheckRpc(const char* serverFqdn, uint16_t port, uint16_t p reqMsg.code = 0; reqMsg.handle = NULL; // rpc handle returned to app reqMsg.ahandle = NULL; // app handle set by client - strcpy(reqMsg.pCont, "nettest"); + tstrncpy((char*)reqMsg.pCont, "nettest", pktLen); rpcSendRecv(pRpcConn, &epSet, &reqMsg, &rspMsg); @@ -606,7 +606,7 @@ static void taosNetCheckSpeed(char *host, int32_t port, int32_t pkgLen, epSet.inUse = 0; epSet.numOfEps = 1; epSet.port[0] = port; - strcpy(epSet.fqdn[0], host); + tstrncpy(epSet.fqdn[0], host, sizeof(epSet.fqdn[0])); reqMsg.msgType = TSDB_MSG_TYPE_NETWORK_TEST; reqMsg.pCont = rpcMallocCont(pkgLen); @@ -614,8 +614,8 @@ static void taosNetCheckSpeed(char *host, int32_t port, int32_t pkgLen, reqMsg.code = 0; reqMsg.handle = NULL; // rpc handle returned to app reqMsg.ahandle = NULL; // app handle set by client - strcpy(reqMsg.pCont, "nettest speed"); - + tstrncpy((char*)reqMsg.pCont, "nettest speed", pkgLen); + rpcSendRecv(pRpcConn, &epSet, &reqMsg, &rspMsg); int code = 0; diff --git a/src/util/src/tutil.c b/src/util/src/tutil.c index c15197b7537601c0f0ca72420a6711547d1ed0ed..02498e222212fada5b7a9f39fbcfe5c76494a651 100644 --- a/src/util/src/tutil.c +++ b/src/util/src/tutil.c @@ -57,36 +57,32 @@ int32_t strdequote(char *z) { return j + 1; // only one quote, do nothing } - +// delete escape character: \\, \', \" int32_t strRmquote(char *z, int32_t len){ - // delete escape character: \\, \', \" - char delim = z[0]; - if (delim != '\'' && delim != '\"') { - return len; + char delim = 0; + int32_t cnt = 0; + int32_t j = 0; + for (size_t k = 0; k < len; ++k) { + if (!delim && (z[k] == '\'' || z[k] == '"')){ // find the start ' or " + delim = z[k]; } - int32_t cnt = 0; - int32_t j = 0; - for (uint32_t k = 1; k < len - 1; ++k) { - if (z[k] == '\\' || (z[k] == delim && z[k + 1] == delim)) { - if ((z[k] == '\\' && z[k + 1] == '_') || (z[k] == '\\' && z[k + 1] == '%')) { - //match '_' self - } else { - z[j] = z[k + 1]; - cnt++; - j++; - k++; - continue; - } - } - - z[j] = z[k]; + if ((z[k] == '\\' && z[k + 1] == '_') || (z[k] == '\\' && z[k + 1] == '%')) { + //match '_' '%' self + }else if(z[k] == '\\'){ + z[j] = z[k + 1]; + cnt++; j++; + k++; + continue; + }else if(z[k] == delim){ + continue; } - - z[j] = 0; - - return len - 2 - cnt; + z[j] = z[k]; + j++; + } + z[j] = 0; + return j; } int32_t strRmquoteEscape(char *z, int32_t len) { diff --git a/src/util/tests/stringTest.cpp b/src/util/tests/stringTest.cpp index 95fba0cd3e2b62da2b2dadb0b7e592aef5893543..e304ccaec6753ed627418ea8bf2fd428ae710859 100644 --- a/src/util/tests/stringTest.cpp +++ b/src/util/tests/stringTest.cpp @@ -6,6 +6,44 @@ #include "taos.h" #include "tutil.h" +TEST(testCase, str_rmquote_test) { + char t1[] = "\"\".dd"; + int32_t len = strRmquote(t1, strlen(t1)); + printf("t1:%s, len:%d\n", t1, len); + EXPECT_EQ(3, len); + EXPECT_STRCASEEQ(t1, ".dd"); + + char t2[] = "\"fsd\\\"fs\".dd"; + len = strRmquote(t2, strlen(t2)); + printf("t2:%s, len:%d\n", t2, len); + EXPECT_EQ(9, len); + EXPECT_STRCASEEQ(t2, "fsd\"fs.dd"); + + char t3[] = "fs\\_d\\%.d\\d"; + len = strRmquote(t3, strlen(t3)); + printf("t3:%s, len:%d\n", t3, len); + EXPECT_EQ(10, len); + EXPECT_STRCASEEQ(t3, "fs\\_d\\%.dd"); + + char t4[] = "\"fs\\_d\\%\".dd"; + len = strRmquote(t4, strlen(t4)); + printf("t4:%s, len:%d\n", t4, len); + EXPECT_EQ(10, len); + EXPECT_STRCASEEQ(t4, "fs\\_d\\%.dd"); + + char t5[] = "\"fs\\_d\\%\""; + len = strRmquote(t5, strlen(t5)); + printf("t5:%s, len:%d\n", t5, len); + EXPECT_EQ(7, len); + EXPECT_STRCASEEQ(t5, "fs\\_d\\%"); + + char t6[] = "'fs\\_d\\%'"; + len = strRmquote(t6, strlen(t6)); + printf("t6:%s, len:%d\n", t6, len); + EXPECT_EQ(7, len); + EXPECT_STRCASEEQ(t6, "fs\\_d\\%"); +} + TEST(testCase, string_dequote_test) { char t1[] = "'abc'"; int32_t len = strdequote(t1); diff --git a/tests/develop-test/0-management/3-tag/json_tag.py b/tests/develop-test/0-management/3-tag/json_tag.py index dc7affe870f4462526aa1095311278d280abe77f..b6a15ca770ea7e4885973a03bfc8e3bd08c3f54d 100644 --- a/tests/develop-test/0-management/3-tag/json_tag.py +++ b/tests/develop-test/0-management/3-tag/json_tag.py @@ -75,6 +75,10 @@ class TDTestCase: tdSql.error("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"\t\":\"fff\"}')") tdSql.error("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"试试\":\"fff\"}')") + # test invalidate json value, value number can not be inf,nan TD-12166 + tdSql.error("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"k\":1.8e308}')") + tdSql.error("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"k\":-1.8e308}')") + #test length limit char1= ''.join(['abcd']*64) char3= ''.join(['abcd']*1022) diff --git a/tests/develop-test/1-insert/0-sql/basic.py b/tests/develop-test/1-insert/0-sql/basic.py deleted file mode 100644 index 273ff8ba488db609cfa4aa5978c689288d14750b..0000000000000000000000000000000000000000 --- a/tests/develop-test/1-insert/0-sql/basic.py +++ /dev/null @@ -1,68 +0,0 @@ -################################################################### -# Copyright (c) 2016 by TAOS Technologies, Inc. -# All rights reserved. -# -# This file is proprietary and confidential to TAOS Technologies. -# No part of this file may be reproduced, stored, transmitted, -# disclosed or used in any form or by any means other than as -# expressly provided by the written permission from Jianhui Tao -# -################################################################### - -# -*- coding: utf-8 -*- - -import sys -from util.log import * -from util.cases import * -from util.sql import * - - -class TDTestCase: - def caseDescription(self): - ''' - case1: insert 倒序插入 - case2: 语法解析错误同时meta请求也发出去了导致callback中处理逻辑失效 - case3: [TD-XXXX]insert语句在values之间加入多个逗号 - ''' - return - - def init(self, conn, logSql): - tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor(), logSql) - - def run(self): - tdSql.prepare() - - ret = tdSql.execute('create table tb (ts timestamp, speed int)') - - insertRows = 10 - tdLog.info("insert %d rows" % (insertRows)) - for i in range(0, insertRows): - ret = tdSql.execute( - 'insert into tb values (now + %dm, %d)' % - (i, i)) - - tdLog.info("insert earlier data") - tdSql.execute('insert into tb values (now - 5m , 10)') - tdSql.execute('insert into tb values (now - 6m , 10)') - tdSql.execute('insert into tb values (now - 7m , 10)') - tdSql.execute('insert into tb values (now - 8m , 10)') - - tdSql.query("select * from tb") - tdSql.checkRows(insertRows + 4) - - # test case for https://jira.taosdata.com:18080/browse/TD-3716: - tdSql.error("insert into tb(now, 1)") - # test case for TD-10717 - tdSql.error("insert into tb values(now,1),,(now+1s,1)") - tdSql.execute("insert into tb values(now+2s,1),(now+3s,1),(now+4s,1)") - tdSql.query("select * from tb") - tdSql.checkRows(insertRows + 4 +3) - - def stop(self): - tdSql.close() - tdLog.success("%s successfully executed" % __file__) - - -tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/develop-test/2-query/7-nest/ts_hidden_column.py b/tests/develop-test/2-query/7-nest/ts_hidden_column.py new file mode 100644 index 0000000000000000000000000000000000000000..2e882bb892271037afeb91250f49b359e115ab4e --- /dev/null +++ b/tests/develop-test/2-query/7-nest/ts_hidden_column.py @@ -0,0 +1,59 @@ +################################################################### +# Copyright (c) 2021 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +from util.log import * +from util.cases import * +from util.sql import * + + +class TDTestCase: + def caseDescription(self): + ''' + case1: [TD-12145]function/clause program inserted column will be use as ts in outerquery + case2: [TD-12164]elapsed function can only take primary timestamp as first parameter + case3: [TD-12165]_c0 can not be alias name + ''' + return + + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + self._conn = conn + + def run(self): + print("running {}".format(__file__)) + tdSql.execute("drop database if exists td12145") + tdSql.execute("create database if not exists td12145") + tdSql.execute('use td12145') + + tdSql.execute('create stable st(ts timestamp , value int ) tags (ind int)') + tdSql.execute('insert into tb1 using st tags(1) values(now ,1)') + tdSql.execute('insert into tb1 using st tags(1) values(now+1s ,2)') + tdSql.execute('insert into tb1 using st tags(1) values(now+2s ,3)') + tdSql.error('select elapsed(ts00 ,1s) from (select elapsed(ts,1s) ts00 from tb1)') + tdSql.error('select elapsed(ts00 ,1s) from (select value ts00 from tb1)') + tdSql.error('select _c0 from (select value as _c0 , _c0 from st)') + tdSql.error('select ts from (select value as _c0 , ts from st)') + tdSql.query('select ts, max(nestvalue) from (select csum(value) nestvalue from tb1)') + tdSql.checkRows(1) + tdSql.checkData(0, 1, 6) + + tdSql.execute('drop database td12145') + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/develop-test/fulltest.sh b/tests/develop-test/fulltest.sh index 9ec1dd23ac27928950befc35bd49ba8b4e6270eb..e7f272fc073a66685bdca709cc6434bb9838b5aa 100755 --- a/tests/develop-test/fulltest.sh +++ b/tests/develop-test/fulltest.sh @@ -1,3 +1,3 @@ python3 test.py -f 0-management/3-tag/json_tag.py -python3 test.py -f 1-insert/0-sql/basic.py -python3 test.py -f 1-insert/0-sql/batchInsert.py \ No newline at end of file +python3 test.py -f 1-insert/0-sql/batchInsert.py +python3 test.py -f 2-query/7-nest/ts_hidden_column.py diff --git a/tests/examples/JDBC/JDBCDemo/pom.xml b/tests/examples/JDBC/JDBCDemo/pom.xml index 5f0e35fa8f739453651ce3a7af092437531c00c6..b0b07d58f4e59645e5ebe78a938d0043558a9c80 100644 --- a/tests/examples/JDBC/JDBCDemo/pom.xml +++ b/tests/examples/JDBC/JDBCDemo/pom.xml @@ -17,7 +17,7 @@ com.taosdata.jdbc taos-jdbcdriver - 2.0.35 + 2.0.36 diff --git a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/ClientParameterSetting.java b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/ClientParameterSetting.java new file mode 100644 index 0000000000000000000000000000000000000000..09fb8f1b19f069305464a52df15f748d29ddd5d8 --- /dev/null +++ b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/ClientParameterSetting.java @@ -0,0 +1,54 @@ +package com.taosdata.example; + +import com.taosdata.jdbc.TSDBDriver; + +import java.sql.*; +import java.util.Properties; + +public class ClientParameterSetting { + private static final String host = "127.0.0.1"; + + public static void main(String[] args) throws SQLException { + setParameterInJdbcUrl(); + + setParameterInProperties(); + } + + private static void setParameterInJdbcUrl() throws SQLException { + String jdbcUrl = "jdbc:TAOS://" + host + ":6030/?debugFlag=135&asyncLog=0"; + + Connection connection = DriverManager.getConnection(jdbcUrl, "root", "taosdata"); + + printDatabase(connection); + + connection.close(); + } + + private static void setParameterInProperties() throws SQLException { + String jdbcUrl = "jdbc:TAOS://" + host + ":6030/"; + Properties properties = new Properties(); + properties.setProperty("user", "root"); + properties.setProperty("password", "taosdata"); + properties.setProperty("debugFlag", "135"); + properties.setProperty("asyncLog", "0"); + properties.setProperty("maxSQLLength", "1048576"); + + try (Connection conn = DriverManager.getConnection(jdbcUrl, properties)) { + printDatabase(conn); + } + } + + private static void printDatabase(Connection connection) throws SQLException { + try (Statement stmt = connection.createStatement()) { + ResultSet rs = stmt.executeQuery("show databases"); + + ResultSetMetaData meta = rs.getMetaData(); + while (rs.next()) { + for (int i = 1; i <= meta.getColumnCount(); i++) { + System.out.print(meta.getColumnLabel(i) + ": " + rs.getString(i) + "\t"); + } + System.out.println(); + } + } + } +} diff --git a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/ParameterBindingDemo.java b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/ParameterBindingDemo.java new file mode 100644 index 0000000000000000000000000000000000000000..726b57b1465f678d703f0dc9c524f92b856e034e --- /dev/null +++ b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/ParameterBindingDemo.java @@ -0,0 +1,237 @@ +package com.taosdata.example; + +import com.taosdata.jdbc.TSDBPreparedStatement; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.Random; + +public class ParameterBindingDemo { + + private static final String host = "127.0.0.1"; + private static final Random random = new Random(System.currentTimeMillis()); + private static final int BINARY_COLUMN_SIZE = 20; + private static final String[] schemaList = { + "create table stable1(ts timestamp, f1 tinyint, f2 smallint, f3 int, f4 bigint) tags(t1 tinyint, t2 smallint, t3 int, t4 bigint)", + "create table stable2(ts timestamp, f1 float, f2 double) tags(t1 float, t2 double)", + "create table stable3(ts timestamp, f1 bool) tags(t1 bool)", + "create table stable4(ts timestamp, f1 binary(" + BINARY_COLUMN_SIZE + ")) tags(t1 binary(" + BINARY_COLUMN_SIZE + "))", + "create table stable5(ts timestamp, f1 nchar(" + BINARY_COLUMN_SIZE + ")) tags(t1 nchar(" + BINARY_COLUMN_SIZE + "))" + }; + private static final int numOfSubTable = 10, numOfRow = 10; + + public static void main(String[] args) throws SQLException { + + String jdbcUrl = "jdbc:TAOS://" + host + ":6030/"; + Connection conn = DriverManager.getConnection(jdbcUrl, "root", "taosdata"); + + init(conn); + + bindInteger(conn); + + bindFloat(conn); + + bindBoolean(conn); + + bindBytes(conn); + + bindString(conn); + + conn.close(); + } + + private static void init(Connection conn) throws SQLException { + try (Statement stmt = conn.createStatement()) { + stmt.execute("drop database if exists test_parabind"); + stmt.execute("create database if not exists test_parabind"); + stmt.execute("use test_parabind"); + for (int i = 0; i < schemaList.length; i++) { + stmt.execute(schemaList[i]); + } + } + } + + private static void bindInteger(Connection conn) throws SQLException { + String sql = "insert into ? using stable1 tags(?,?,?,?) values(?,?,?,?,?)"; + + try (TSDBPreparedStatement pstmt = conn.prepareStatement(sql).unwrap(TSDBPreparedStatement.class)) { + + for (int i = 1; i <= numOfSubTable; i++) { + // set table name + pstmt.setTableName("t1_" + i); + // set tags + pstmt.setTagByte(0, Byte.parseByte(Integer.toString(random.nextInt(Byte.MAX_VALUE)))); + pstmt.setTagShort(1, Short.parseShort(Integer.toString(random.nextInt(Short.MAX_VALUE)))); + pstmt.setTagInt(2, random.nextInt(Integer.MAX_VALUE)); + pstmt.setTagLong(3, random.nextLong()); + // set columns + ArrayList tsList = new ArrayList<>(); + long current = System.currentTimeMillis(); + for (int j = 0; j < numOfRow; j++) + tsList.add(current + j); + pstmt.setTimestamp(0, tsList); + + ArrayList f1List = new ArrayList<>(); + for (int j = 0; j < numOfRow; j++) + f1List.add(Byte.parseByte(Integer.toString(random.nextInt(Byte.MAX_VALUE)))); + pstmt.setByte(1, f1List); + + ArrayList f2List = new ArrayList<>(); + for (int j = 0; j < numOfRow; j++) + f2List.add(Short.parseShort(Integer.toString(random.nextInt(Short.MAX_VALUE)))); + pstmt.setShort(2, f2List); + + ArrayList f3List = new ArrayList<>(); + for (int j = 0; j < numOfRow; j++) + f3List.add(random.nextInt(Integer.MAX_VALUE)); + pstmt.setInt(3, f3List); + + ArrayList f4List = new ArrayList<>(); + for (int j = 0; j < numOfRow; j++) + f4List.add(random.nextLong()); + pstmt.setLong(4, f4List); + + // add column + pstmt.columnDataAddBatch(); + } + // execute column + pstmt.columnDataExecuteBatch(); + } + + } + + private static void bindFloat(Connection conn) throws SQLException { + String sql = "insert into ? using stable2 tags(?,?) values(?,?,?)"; + + TSDBPreparedStatement pstmt = conn.prepareStatement(sql).unwrap(TSDBPreparedStatement.class); + + for (int i = 1; i <= numOfSubTable; i++) { + // set table name + pstmt.setTableName("t2_" + i); + // set tags + pstmt.setTagFloat(0, random.nextFloat()); + pstmt.setTagDouble(1, random.nextDouble()); + // set columns + ArrayList tsList = new ArrayList<>(); + long current = System.currentTimeMillis(); + for (int j = 0; j < numOfRow; j++) + tsList.add(current + j); + pstmt.setTimestamp(0, tsList); + + ArrayList f1List = new ArrayList<>(); + for (int j = 0; j < numOfRow; j++) + f1List.add(random.nextFloat()); + pstmt.setFloat(1, f1List); + + ArrayList f2List = new ArrayList<>(); + for (int j = 0; j < numOfRow; j++) + f2List.add(random.nextDouble()); + pstmt.setDouble(2, f2List); + + // add column + pstmt.columnDataAddBatch(); + } + // execute + pstmt.columnDataExecuteBatch(); + // close if no try-with-catch statement is used + pstmt.close(); + } + + private static void bindBoolean(Connection conn) throws SQLException { + String sql = "insert into ? using stable3 tags(?) values(?,?)"; + + try (TSDBPreparedStatement pstmt = conn.prepareStatement(sql).unwrap(TSDBPreparedStatement.class)) { + for (int i = 1; i <= numOfSubTable; i++) { + // set table name + pstmt.setTableName("t3_" + i); + // set tags + pstmt.setTagBoolean(0, random.nextBoolean()); + // set columns + ArrayList tsList = new ArrayList<>(); + long current = System.currentTimeMillis(); + for (int j = 0; j < numOfRow; j++) + tsList.add(current + j); + pstmt.setTimestamp(0, tsList); + + ArrayList f1List = new ArrayList<>(); + for (int j = 0; j < numOfRow; j++) + f1List.add(random.nextBoolean()); + pstmt.setBoolean(1, f1List); + + // add column + pstmt.columnDataAddBatch(); + } + // execute + pstmt.columnDataExecuteBatch(); + } + } + + private static void bindBytes(Connection conn) throws SQLException { + String sql = "insert into ? using stable4 tags(?) values(?,?)"; + + try (TSDBPreparedStatement pstmt = conn.prepareStatement(sql).unwrap(TSDBPreparedStatement.class)) { + + for (int i = 1; i <= numOfSubTable; i++) { + // set table name + pstmt.setTableName("t4_" + i); + // set tags + pstmt.setTagString(0, new String("abc")); + + // set columns + ArrayList tsList = new ArrayList<>(); + long current = System.currentTimeMillis(); + for (int j = 0; j < numOfRow; j++) + tsList.add(current + j); + pstmt.setTimestamp(0, tsList); + + ArrayList f1List = new ArrayList<>(); + for (int j = 0; j < numOfRow; j++) { + f1List.add(new String("abc")); + } + pstmt.setString(1, f1List, BINARY_COLUMN_SIZE); + + // add column + pstmt.columnDataAddBatch(); + } + // execute + pstmt.columnDataExecuteBatch(); + } + } + + private static void bindString(Connection conn) throws SQLException { + String sql = "insert into ? using stable5 tags(?) values(?,?)"; + + try (TSDBPreparedStatement pstmt = conn.prepareStatement(sql).unwrap(TSDBPreparedStatement.class)) { + + for (int i = 1; i <= numOfSubTable; i++) { + // set table name + pstmt.setTableName("t5_" + i); + // set tags + pstmt.setTagNString(0, "北京-abc"); + + // set columns + ArrayList tsList = new ArrayList<>(); + long current = System.currentTimeMillis(); + for (int j = 0; j < numOfRow; j++) + tsList.add(current + j); + pstmt.setTimestamp(0, tsList); + + ArrayList f1List = new ArrayList<>(); + for (int j = 0; j < numOfRow; j++) { + f1List.add("北京-abc"); + } + pstmt.setNString(1, f1List, BINARY_COLUMN_SIZE); + + // add column + pstmt.columnDataAddBatch(); + } + // execute + pstmt.columnDataExecuteBatch(); + } + } + + +} diff --git a/tests/examples/JDBC/connectionPools/pom.xml b/tests/examples/JDBC/connectionPools/pom.xml index 91f1cb36f28840b7d5eeb428aca3f940365ed59d..aad2923b823c1fcf2cb87eba4f18865fede063a1 100644 --- a/tests/examples/JDBC/connectionPools/pom.xml +++ b/tests/examples/JDBC/connectionPools/pom.xml @@ -53,7 +53,7 @@ org.apache.logging.log4j log4j-core - 2.15.0 + 2.17.0 diff --git a/tests/examples/JDBC/taosdemo/pom.xml b/tests/examples/JDBC/taosdemo/pom.xml index c6e61f5d22ca83c5d56deef7db9354913a3321b1..23c74ef1b72e0f2fd8b2a647a798872062a9c216 100644 --- a/tests/examples/JDBC/taosdemo/pom.xml +++ b/tests/examples/JDBC/taosdemo/pom.xml @@ -88,7 +88,7 @@ org.apache.logging.log4j log4j-core - 2.15.0 + 2.17.0 diff --git a/tests/examples/c/CMakeLists.txt b/tests/examples/c/CMakeLists.txt index 9d5dfc37b1045cb771cf6bd20da7087d7523e2e2..62a82f20156fccd314aab13d0a52f805a1a9a7af 100644 --- a/tests/examples/c/CMakeLists.txt +++ b/tests/examples/c/CMakeLists.txt @@ -7,6 +7,8 @@ IF (TD_LINUX) TARGET_LINK_LIBRARIES(demo taos_static trpc tutil pthread ) ADD_EXECUTABLE(sml schemaless.c) TARGET_LINK_LIBRARIES(sml taos_static trpc tutil pthread ) + ADD_EXECUTABLE(sqlperf sqlperf.c) + TARGET_LINK_LIBRARIES(sqlperf taos_static trpc tutil pthread ) ADD_EXECUTABLE(subscribe subscribe.c) TARGET_LINK_LIBRARIES(subscribe taos_static trpc tutil pthread ) ADD_EXECUTABLE(epoll epoll.c) diff --git a/tests/examples/c/makefile b/tests/examples/c/makefile index 83a9a75271ef5d841a784b69c328e12c0cdf36be..355d1a2d54c1293e909309dafe986daa716ac293 100644 --- a/tests/examples/c/makefile +++ b/tests/examples/c/makefile @@ -25,7 +25,6 @@ clean: rm $(ROOT)asyncdemo rm $(ROOT)demo rm $(ROOT)prepare - rm $(ROOT)batchprepare rm $(ROOT)stream rm $(ROOT)subscribe rm $(ROOT)apitest diff --git a/tests/examples/c/prepare.c b/tests/examples/c/prepare.c index b62aca727905f6b632d191e08f87cfeb061266e0..14acba3b0d691b4d9bb61db3d8bf95e10e6c20fe 100644 --- a/tests/examples/c/prepare.c +++ b/tests/examples/c/prepare.c @@ -857,6 +857,542 @@ void verify_prepare3(TAOS* taos) { } +/** + * @brief Verify the upper/lower case of tableName for create(by setTableName)/query/show/describe/drop. + * https://jira.taosdata.com:18080/browse/TS-904 + * https://jira.taosdata.com:18090/pages/viewpage.action?pageId=129140555 + * @param taos + */ +void verify_prepare4(TAOS* taos) { + printf("Verify the upper/lower case of tableName for create(by setTableName)/query/show/describe/drop etc.\n"); + + TAOS_RES* result = taos_query(taos, "drop database if exists test;"); + taos_free_result(result); + usleep(100000); + result = taos_query(taos, "create database test;"); + + int code = taos_errno(result); + if (code != 0) { + printf("\033[31mfailed to create database, reason:%s\033[0m\n", taos_errstr(result)); + taos_free_result(result); + exit(EXIT_FAILURE); + } + taos_free_result(result); + + usleep(100000); + taos_select_db(taos, "test"); + + // create table + const char* sql = + "create stable st1 (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin " + "binary(40), blob nchar(10), u1 tinyint unsigned, u2 smallint unsigned, u4 int unsigned, u8 bigint unsigned) " + "tags " + "(b_tag bool, v1_tag tinyint, v2_tag smallint, v4_tag int, v8_tag bigint, f4_tag float, f8_tag double, bin_tag " + "binary(40), blob_tag nchar(10), u1_tag tinyint unsigned, u2_tag smallint unsigned, u4_tag int unsigned, u8_tag " + "bigint " + "unsigned)"; + result = taos_query(taos, sql); + code = taos_errno(result); + if (code != 0) { + printf("\033[31mfailed to create table, reason:%s\033[0m\n", taos_errstr(result)); + taos_free_result(result); + exit(EXIT_FAILURE); + } + taos_free_result(result); + + TAOS_BIND tags[13]; + + struct { + int8_t b; + int8_t v1; + int16_t v2; + int32_t v4; + int64_t v8; + float f4; + double f8; + char bin[40]; + char blob[80]; + uint8_t u1; + uint16_t u2; + uint32_t u4; + uint64_t u8; + } id = {0}; + + id.b = (int8_t)1; + id.v1 = (int8_t)1; + id.v2 = (int16_t)2; + id.v4 = (int32_t)4; + id.v8 = (int64_t)8; + id.f4 = (float)40; + id.f8 = (double)80; + for (int j = 0; j < sizeof(id.bin); ++j) { + id.bin[j] = (char)('1' + '0'); + } + strcpy(id.blob, "一二三四五六七八九十"); + id.u1 = (uint8_t)1; + id.u2 = (uint16_t)2; + id.u4 = (uint32_t)4; + id.u8 = (uint64_t)8; + + tags[0].buffer_type = TSDB_DATA_TYPE_BOOL; + tags[0].buffer_length = sizeof(id.b); + tags[0].buffer = &id.b; + tags[0].length = &tags[0].buffer_length; + tags[0].is_null = NULL; + + tags[1].buffer_type = TSDB_DATA_TYPE_TINYINT; + tags[1].buffer_length = sizeof(id.v1); + tags[1].buffer = &id.v1; + tags[1].length = &tags[1].buffer_length; + tags[1].is_null = NULL; + + tags[2].buffer_type = TSDB_DATA_TYPE_SMALLINT; + tags[2].buffer_length = sizeof(id.v2); + tags[2].buffer = &id.v2; + tags[2].length = &tags[2].buffer_length; + tags[2].is_null = NULL; + + tags[3].buffer_type = TSDB_DATA_TYPE_INT; + tags[3].buffer_length = sizeof(id.v4); + tags[3].buffer = &id.v4; + tags[3].length = &tags[3].buffer_length; + tags[3].is_null = NULL; + + tags[4].buffer_type = TSDB_DATA_TYPE_BIGINT; + tags[4].buffer_length = sizeof(id.v8); + tags[4].buffer = &id.v8; + tags[4].length = &tags[4].buffer_length; + tags[4].is_null = NULL; + + tags[5].buffer_type = TSDB_DATA_TYPE_FLOAT; + tags[5].buffer_length = sizeof(id.f4); + tags[5].buffer = &id.f4; + tags[5].length = &tags[5].buffer_length; + tags[5].is_null = NULL; + + tags[6].buffer_type = TSDB_DATA_TYPE_DOUBLE; + tags[6].buffer_length = sizeof(id.f8); + tags[6].buffer = &id.f8; + tags[6].length = &tags[6].buffer_length; + tags[6].is_null = NULL; + + tags[7].buffer_type = TSDB_DATA_TYPE_BINARY; + tags[7].buffer_length = sizeof(id.bin); + tags[7].buffer = &id.bin; + tags[7].length = &tags[7].buffer_length; + tags[7].is_null = NULL; + + tags[8].buffer_type = TSDB_DATA_TYPE_NCHAR; + tags[8].buffer_length = strlen(id.blob); + tags[8].buffer = &id.blob; + tags[8].length = &tags[8].buffer_length; + tags[8].is_null = NULL; + + tags[9].buffer_type = TSDB_DATA_TYPE_UTINYINT; + tags[9].buffer_length = sizeof(id.u1); + tags[9].buffer = &id.u1; + tags[9].length = &tags[9].buffer_length; + tags[9].is_null = NULL; + + tags[10].buffer_type = TSDB_DATA_TYPE_USMALLINT; + tags[10].buffer_length = sizeof(id.u2); + tags[10].buffer = &id.u2; + tags[10].length = &tags[10].buffer_length; + tags[10].is_null = NULL; + + tags[11].buffer_type = TSDB_DATA_TYPE_UINT; + tags[11].buffer_length = sizeof(id.u4); + tags[11].buffer = &id.u4; + tags[11].length = &tags[11].buffer_length; + tags[11].is_null = NULL; + + tags[12].buffer_type = TSDB_DATA_TYPE_UBIGINT; + tags[12].buffer_length = sizeof(id.u8); + tags[12].buffer = &id.u8; + tags[12].length = &tags[12].buffer_length; + tags[12].is_null = NULL; + // insert 10 records + struct { + int64_t ts[10]; + int8_t b[10]; + int8_t v1[10]; + int16_t v2[10]; + int32_t v4[10]; + int64_t v8[10]; + float f4[10]; + double f8[10]; + char bin[10][40]; + char blob[10][80]; + uint8_t u1[10]; + uint16_t u2[10]; + uint32_t u4[10]; + uint64_t u8[10]; + } v; + + int32_t* t8_len = malloc(sizeof(int32_t) * 10); + int32_t* t16_len = malloc(sizeof(int32_t) * 10); + int32_t* t32_len = malloc(sizeof(int32_t) * 10); + int32_t* t64_len = malloc(sizeof(int32_t) * 10); + int32_t* float_len = malloc(sizeof(int32_t) * 10); + int32_t* double_len = malloc(sizeof(int32_t) * 10); + int32_t* bin_len = malloc(sizeof(int32_t) * 10); + int32_t* blob_len = malloc(sizeof(int32_t) * 10); + int32_t* u8_len = malloc(sizeof(int32_t) * 10); + int32_t* u16_len = malloc(sizeof(int32_t) * 10); + int32_t* u32_len = malloc(sizeof(int32_t) * 10); + int32_t* u64_len = malloc(sizeof(int32_t) * 10); + + TAOS_MULTI_BIND params[14]; + char is_null[10] = {0}; + params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; + params[0].buffer_length = sizeof(v.ts[0]); + params[0].buffer = v.ts; + params[0].length = t64_len; + params[0].is_null = is_null; + params[0].num = 10; + + params[1].buffer_type = TSDB_DATA_TYPE_BOOL; + params[1].buffer_length = sizeof(v.b[0]); + params[1].buffer = v.b; + params[1].length = t8_len; + params[1].is_null = is_null; + params[1].num = 10; + + params[2].buffer_type = TSDB_DATA_TYPE_TINYINT; + params[2].buffer_length = sizeof(v.v1[0]); + params[2].buffer = v.v1; + params[2].length = t8_len; + params[2].is_null = is_null; + params[2].num = 10; + + params[3].buffer_type = TSDB_DATA_TYPE_SMALLINT; + params[3].buffer_length = sizeof(v.v2[0]); + params[3].buffer = v.v2; + params[3].length = t16_len; + params[3].is_null = is_null; + params[3].num = 10; + + params[4].buffer_type = TSDB_DATA_TYPE_INT; + params[4].buffer_length = sizeof(v.v4[0]); + params[4].buffer = v.v4; + params[4].length = t32_len; + params[4].is_null = is_null; + params[4].num = 10; + + params[5].buffer_type = TSDB_DATA_TYPE_BIGINT; + params[5].buffer_length = sizeof(v.v8[0]); + params[5].buffer = v.v8; + params[5].length = t64_len; + params[5].is_null = is_null; + params[5].num = 10; + + params[6].buffer_type = TSDB_DATA_TYPE_FLOAT; + params[6].buffer_length = sizeof(v.f4[0]); + params[6].buffer = v.f4; + params[6].length = float_len; + params[6].is_null = is_null; + params[6].num = 10; + + params[7].buffer_type = TSDB_DATA_TYPE_DOUBLE; + params[7].buffer_length = sizeof(v.f8[0]); + params[7].buffer = v.f8; + params[7].length = double_len; + params[7].is_null = is_null; + params[7].num = 10; + + params[8].buffer_type = TSDB_DATA_TYPE_BINARY; + params[8].buffer_length = sizeof(v.bin[0]); + params[8].buffer = v.bin; + params[8].length = bin_len; + params[8].is_null = is_null; + params[8].num = 10; + + params[9].buffer_type = TSDB_DATA_TYPE_NCHAR; + params[9].buffer_length = sizeof(v.blob[0]); + params[9].buffer = v.blob; + params[9].length = blob_len; + params[9].is_null = is_null; + params[9].num = 10; + + params[10].buffer_type = TSDB_DATA_TYPE_UTINYINT; + params[10].buffer_length = sizeof(v.u1[0]); + params[10].buffer = v.u1; + params[10].length = u8_len; + params[10].is_null = is_null; + params[10].num = 10; + + params[11].buffer_type = TSDB_DATA_TYPE_USMALLINT; + params[11].buffer_length = sizeof(v.u2[0]); + params[11].buffer = v.u2; + params[11].length = u16_len; + params[11].is_null = is_null; + params[11].num = 10; + + params[12].buffer_type = TSDB_DATA_TYPE_UINT; + params[12].buffer_length = sizeof(v.u4[0]); + params[12].buffer = v.u4; + params[12].length = u32_len; + params[12].is_null = is_null; + params[12].num = 10; + + params[13].buffer_type = TSDB_DATA_TYPE_UBIGINT; + params[13].buffer_length = sizeof(v.u8[0]); + params[13].buffer = v.u8; + params[13].length = u64_len; + params[13].is_null = is_null; + params[13].num = 10; + +// verify table names for upper/lower case +#define VERIFY_CNT 5 + + typedef struct { + char setTbName[20]; + char showName[20]; + char describeName[20]; + char queryName[20]; + char dropName[20]; + } STbNames; + + /** + * @brief + * 0 - success expected + * NonZero - fail expected + */ + typedef struct { + int32_t setTbName; + int32_t showName; + int32_t describeName; + int32_t queryName; + int32_t dropName; + } STbNamesResult; + + STbNames tbName[VERIFY_CNT] = {0}; + STbNamesResult tbNameResult[VERIFY_CNT] = {0}; + + STbNames* pTbName = NULL; + STbNamesResult* pTbNameResult = NULL; + + pTbName = &tbName[0]; + pTbNameResult = &tbNameResult[0]; + strcpy(pTbName->setTbName, "Mn1"); + strcpy(pTbName->showName, "mn1"); + strcpy(pTbName->describeName, "mn1"); + strcpy(pTbName->queryName, "mn1"); + strcpy(pTbName->dropName, "mn1"); + + pTbName = &tbName[1]; + pTbNameResult = &tbNameResult[1]; + strcpy(pTbName->setTbName, "'Mn1'"); + strcpy(pTbName->showName, "'mn1'"); + strcpy(pTbName->describeName, "'mn1'"); + strcpy(pTbName->queryName, "'mn1'"); + strcpy(pTbName->dropName, "'mn1'"); + + pTbName = &tbName[2]; + pTbNameResult = &tbNameResult[2]; + strcpy(pTbName->setTbName, "\"Mn1\""); + strcpy(pTbName->showName, "\"mn1\""); + strcpy(pTbName->describeName, "\"mn1\""); + strcpy(pTbName->queryName, "\"mn1\""); + strcpy(pTbName->dropName, "\"mn1\""); + + pTbName = &tbName[3]; + pTbNameResult = &tbNameResult[3]; + strcpy(pTbName->setTbName, "\"Mn1\""); + strcpy(pTbName->showName, "'mn1'"); + strcpy(pTbName->describeName, "'mn1'"); + strcpy(pTbName->queryName, "mn1"); + strcpy(pTbName->dropName, "\"mn1\""); + + pTbName = &tbName[4]; + pTbNameResult = &tbNameResult[4]; + strcpy(pTbName->setTbName, "`Mn1`"); + strcpy(pTbName->showName, "Mn1"); // TODO support uniform of `` + strcpy(pTbName->describeName, "`Mn1`"); + strcpy(pTbName->queryName, "`Mn1`"); + strcpy(pTbName->dropName, "`Mn1`"); + + TAOS_STMT* stmt = NULL; + + for (int n = 0; n < VERIFY_CNT; ++n) { + printf("\033[31m[%d] ===================================\033[0m\n", n); + pTbName = &tbName[n]; + pTbNameResult = &tbNameResult[n]; + char tmpStr[256] = {0}; + + // set table name + stmt = taos_stmt_init(taos); + if (!stmt) { + printf("\033[31m[%d] failed to execute taos_stmt_init. error:%s\033[0m\n", n); + exit(EXIT_FAILURE); + } + + sql = "insert into ? using st1 tags(?,?,?,?,?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + code = taos_stmt_prepare(stmt, sql, 0); + if (code != 0) { + printf("\033[31mfailed to execute taos_stmt_prepare. error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); + exit(EXIT_FAILURE); + } + + printf("[%d] taos_stmt_set_tbname_tags, tbname=%s\n", n, pTbName->setTbName); + code = taos_stmt_set_tbname_tags(stmt, pTbName->setTbName, tags); + if ((!pTbNameResult->setTbName && (0 != code)) || (pTbNameResult->setTbName && (0 == code))) { + printf("\033[31m[%d] failed to execute taos_stmt_set_tbname_tags. error:%s\033[0m\n", n, taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); + exit(EXIT_FAILURE); + } + + if (code == 0) { + int64_t ts = 1591060628000 + 1000 * n; + for (int i = 0; i < 10; ++i) { + v.ts[i] = ts++; + is_null[i] = 0; + + v.b[i] = (int8_t)i % 2; + v.v1[i] = (int8_t)i; + v.v2[i] = (int16_t)(i * 2); + v.v4[i] = (int32_t)(i * 4); + v.v8[i] = (int64_t)(i * 8); + v.f4[i] = (float)(i * 40); + v.f8[i] = (double)(i * 80); + for (int j = 0; j < sizeof(v.bin[0]); ++j) { + v.bin[i][j] = (char)(i + '0'); + } + strcpy(v.blob[i], "一二三四五六七八九十"); + v.u1[i] = (uint8_t)i; + v.u2[i] = (uint16_t)(i * 2); + v.u4[i] = (uint32_t)(i * 4); + v.u8[i] = (uint64_t)(i * 8); + + t8_len[i] = sizeof(int8_t); + t16_len[i] = sizeof(int16_t); + t32_len[i] = sizeof(int32_t); + t64_len[i] = sizeof(int64_t); + float_len[i] = sizeof(float); + double_len[i] = sizeof(double); + bin_len[i] = sizeof(v.bin[0]); + blob_len[i] = (int32_t)strlen(v.blob[i]); + u8_len[i] = sizeof(uint8_t); + u16_len[i] = sizeof(uint16_t); + u32_len[i] = sizeof(uint32_t); + u64_len[i] = sizeof(uint64_t); + } + + taos_stmt_bind_param_batch(stmt, params); + taos_stmt_add_batch(stmt); + + if (taos_stmt_execute(stmt) != 0) { + printf("\033[31m[%d] failed to execute insert statement.error:%s\033[0m\n", n, taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); + exit(EXIT_FAILURE); + } + } + taos_stmt_close(stmt); + + // show the table + printf("[%d] show tables, tbName = %s\n", n, pTbName->showName); + stmt = taos_stmt_init(taos); + sprintf(tmpStr, "show tables like %s", pTbName->showName); + taos_stmt_prepare(stmt, tmpStr, 0); + code = taos_stmt_execute(stmt); + if ((!pTbNameResult->showName && (0 != code)) || (pTbNameResult->showName && (0 == code))) { + printf("\033[31m[%d] failed to execute show tables like. error:%s\033[0m\n", n, taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); + exit(EXIT_FAILURE); + } + taos_stmt_close(stmt); + + // describe the table + printf("[%d] describe tables, tbName = %s\n", n, pTbName->describeName); + stmt = taos_stmt_init(taos); + sprintf(tmpStr, "describe %s", pTbName->describeName); + taos_stmt_prepare(stmt, tmpStr, 0); + code = taos_stmt_execute(stmt); + if ((!pTbNameResult->describeName && (0 != code)) || (pTbNameResult->describeName && (0 == code))) { + printf("\033[31m[%d] failed to execute describe tables. error:%s\033[0m\n", n, taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); + exit(EXIT_FAILURE); + } + taos_stmt_close(stmt); + + // query the records + printf("[%d] select statement, tbName = %s\n", n, pTbName->queryName); + stmt = taos_stmt_init(taos); + sprintf(tmpStr, "SELECT * FROM %s", pTbName->queryName); + taos_stmt_prepare(stmt, tmpStr, 0); + + TAOS_BIND qparams[2]; + + int8_t v1 = 5; + int16_t v2 = 15; + qparams[0].buffer_type = TSDB_DATA_TYPE_TINYINT; + qparams[0].buffer_length = sizeof(v1); + qparams[0].buffer = &v1; + qparams[0].length = &qparams[0].buffer_length; + qparams[0].is_null = NULL; + + qparams[1].buffer_type = TSDB_DATA_TYPE_SMALLINT; + qparams[1].buffer_length = sizeof(v2); + qparams[1].buffer = &v2; + qparams[1].length = &qparams[1].buffer_length; + qparams[1].is_null = NULL; + + taos_stmt_bind_param(stmt, qparams); + + code = taos_stmt_execute(stmt); + if ((!pTbNameResult->queryName && (0 != code)) || (pTbNameResult->queryName && (0 == code))) { + printf("\033[31m[%d] failed to execute select statement.error:%s\033[0m\n", n, taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); + exit(EXIT_FAILURE); + } + + result = taos_stmt_use_result(stmt); + + TAOS_ROW row; + int rows = 0; + int num_fields = taos_num_fields(result); + TAOS_FIELD* fields = taos_fetch_fields(result); + + // fetch the records row by row + while ((row = taos_fetch_row(result))) { + char temp[256] = {0}; + rows++; + taos_print_row(temp, row, fields, num_fields); + printf("[%d] row = %s\n", n, temp); + } + + taos_free_result(result); + taos_stmt_close(stmt); + + // drop table + printf("[%d] drop table, tbName = %s\n", n, pTbName->dropName); + stmt = taos_stmt_init(taos); + sprintf(tmpStr, "drop table %s", pTbName->dropName); + taos_stmt_prepare(stmt, tmpStr, 0); + code = taos_stmt_execute(stmt); + if ((!pTbNameResult->dropName && (0 != code)) || (pTbNameResult->dropName && (0 == code))) { + printf("\033[31m[%d] failed to drop table. error:%s\033[0m\n", n, taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); + exit(EXIT_FAILURE); + } + taos_stmt_close(stmt); + } + + free(t8_len); + free(t16_len); + free(t32_len); + free(t64_len); + free(float_len); + free(double_len); + free(bin_len); + free(blob_len); + free(u8_len); + free(u16_len); + free(u32_len); + free(u64_len); +} + int main(int argc, char* argv[]) { const char* host = "127.0.0.1"; const char* user = "root"; @@ -880,5 +1416,7 @@ int main(int argc, char* argv[]) { printf("************ verify prepare3 *************\n"); verify_prepare3(taos); printf("************ verify prepare4 *************\n"); + verify_prepare4(taos); + printf("************ verify end *************\n"); exit(EXIT_SUCCESS); } diff --git a/tests/examples/c/schemaless.c b/tests/examples/c/schemaless.c index 0b46d2ff134689992d648065511dd5c21766759e..e7f62ffdfe5628689a290730062f429d09170f6f 100644 --- a/tests/examples/c/schemaless.c +++ b/tests/examples/c/schemaless.c @@ -105,6 +105,35 @@ int32_t generateLine(char* line, int lineLen, char* lineTemplate, int protocol, return TSDB_CODE_SUCCESS; } +int32_t setupSuperTables(TAOS* taos, char* lineTemplate, int protocol, + int numSuperTables, int numChildTables, int numRowsPerChildTable, + int maxBatchesPerThread, int64_t ts) { + printf("setup supertables..."); + { + char** linesStb = calloc(numSuperTables, sizeof(char*)); + for (int i = 0; i < numSuperTables; i++) { + char* lineStb = calloc(strlen(lineTemplate)+128, 1); + generateLine(lineStb, strlen(lineTemplate)+128, lineTemplate, protocol, i, + numSuperTables * numChildTables, + ts + numSuperTables * numChildTables * numRowsPerChildTable); + linesStb[i] = lineStb; + } + SThreadInsertArgs args = {0}; + args.protocol = protocol; + args.batches = calloc(maxBatchesPerThread, sizeof(maxBatchesPerThread)); + args.taos = taos; + args.batches[0].lines = linesStb; + args.batches[0].numLines = numSuperTables; + insertLines(&args); + free(args.batches); + for (int i = 0; i < numSuperTables; ++i) { + free(linesStb[i]); + } + free(linesStb); + } + return TSDB_CODE_SUCCESS; +} + int main(int argc, char* argv[]) { int numThreads = 8; int maxBatchesPerThread = 1024; @@ -117,9 +146,10 @@ int main(int argc, char* argv[]) { int maxLinesPerBatch = 16384; int protocol = TSDB_SML_TELNET_PROTOCOL; + int assembleSTables = 0; int opt; - while ((opt = getopt(argc, argv, "s:c:r:f:t:b:p:hv")) != -1) { + while ((opt = getopt(argc, argv, "s:c:r:f:t:b:p:w:hv")) != -1) { switch (opt) { case 's': numSuperTables = atoi(optarg); @@ -142,6 +172,9 @@ int main(int argc, char* argv[]) { case 'v': verbose = true; break; + case 'a': + assembleSTables = atoi(optarg); + break; case 'p': if (optarg[0] == 't') { protocol = TSDB_SML_TELNET_PROTOCOL; @@ -152,11 +185,11 @@ int main(int argc, char* argv[]) { } break; case 'h': - fprintf(stderr, "Usage: %s -s supertable -c childtable -r rows -f fields -t threads -b maxlines_per_batch -p [t|l|j] -v\n", + fprintf(stderr, "Usage: %s -s supertable -c childtable -r rows -f fields -t threads -b maxlines_per_batch -p [t|l|j] -a assemble-stables -v\n", argv[0]); exit(0); default: /* '?' */ - fprintf(stderr, "Usage: %s -s supertable -c childtable -r rows -f fields -t threads -b maxlines_per_batch -p [t|l|j] -v\n", + fprintf(stderr, "Usage: %s -s supertable -c childtable -r rows -f fields -t threads -b maxlines_per_batch -p [t|l|j] -a assemble-stables -v\n", argv[0]); exit(-1); } @@ -200,28 +233,9 @@ int main(int argc, char* argv[]) { getTelenetTemplate(lineTemplate, 65535); } - printf("setup supertables..."); - { - char** linesStb = calloc(numSuperTables, sizeof(char*)); - for (int i = 0; i < numSuperTables; i++) { - char* lineStb = calloc(strlen(lineTemplate)+128, 1); - generateLine(lineStb, strlen(lineTemplate)+128, lineTemplate, protocol, i, - numSuperTables * numChildTables, - ts + numSuperTables * numChildTables * numRowsPerChildTable); - linesStb[i] = lineStb; - } - SThreadInsertArgs args = {0}; - args.protocol = protocol; - args.batches = calloc(maxBatchesPerThread, sizeof(maxBatchesPerThread)); - args.taos = taos; - args.batches[0].lines = linesStb; - args.batches[0].numLines = numSuperTables; - insertLines(&args); - free(args.batches); - for (int i = 0; i < numSuperTables; ++i) { - free(linesStb[i]); - } - free(linesStb); + if (assembleSTables) { + setupSuperTables(taos, lineTemplate, protocol, + numSuperTables, numChildTables, numRowsPerChildTable, maxBatchesPerThread, ts); } printf("generate lines...\n"); diff --git a/tests/examples/c/sqlperf.c b/tests/examples/c/sqlperf.c new file mode 100644 index 0000000000000000000000000000000000000000..bde69149651f2b2afffc9c4dffca6f42604f4f2c --- /dev/null +++ b/tests/examples/c/sqlperf.c @@ -0,0 +1,141 @@ +#include +#include +#include +#include +#include "taos.h" // TAOS header file +#include "taoserror.h" +#include "os.h" + +bool verbose = false; +bool describeTableFirst = false; + +typedef struct{ + TAOS* taos; + int numThreads; + int threadId; + int numSTables; +} SThreadArgs; + +static int executeSql(TAOS *taos, char *command) { + if (verbose) { + printf("sql: %s\n", command); + } + TAOS_RES *pSql = NULL; + int32_t code = TSDB_CODE_SUCCESS; + + pSql = taos_query(taos, command); + code = taos_errno(pSql); + + if (code != 0) { + if (verbose) fprintf(stderr, "Failed to run %s, reason: %s\n", command, taos_errstr(pSql)); + taos_free_result(pSql); + return code; + } + + taos_free_result(pSql); + return 0; +} + +void* threadFunc(void* args) { + char* sqlDescribeSTable = "describe st%d"; + char* sqlCreateSTable = "create table st%d (ts timestamp, value double) " + "tags(t0 nchar(20), t1 nchar(20), t2 nchar(20), t3 nchar(20), t4 nchar(20), " + "t5 nchar(20), t6 nchar(20), t7 nchar(20), t8 nchar(20), t9 nchar(20))"; + + char* sqlInsertData = "insert into t%d using st%d tags('t%d', 't%d', 't%d', 't%d', 't%d', 't%d', 't%d', 't%d', 't%d', 't%d') values(%lld, %d.%d)"; + + SThreadArgs* param = args; + + int interval = param->numSTables/param->numThreads; + if (param->numSTables % param->numThreads != 0) { + ++interval; + } + int start = param->threadId*interval; + int end = (param->threadId+1)*interval > param->numSTables ? param->numSTables : (param->threadId+1)*interval; + int r = rand(); + + for (int i = start; i < end; ++i) { + int tableId = i; + char sql0[1024] = {0}; + char sql1[1024] = {0}; + char sql2[1024] = {0}; + sprintf(sql0, sqlDescribeSTable, tableId); + sprintf(sql1, sqlCreateSTable, tableId); + time_t ct = time(0); + int64_t ts = ct * 1000; + sprintf(sql2, sqlInsertData, tableId, tableId, r, r, r, r, r, r, r, r, r, r, ts + tableId, r, r); + + if (describeTableFirst) { + executeSql(param->taos, sql0); + } + + executeSql(param->taos, sql1); + + executeSql(param->taos, sql2); + } + return NULL; +} + + +int main(int argc, char *argv[]) { + int numSTables = 20000; + int numThreads = 32; + + int opt; + while ((opt = getopt(argc, argv, "s:t:fvh")) != -1) { + switch (opt) { + case 's': + numSTables = atoi(optarg); + break; + case 't': + numThreads = atoi(optarg); + break; + case 'f': + describeTableFirst = true; + break; + case 'v': + verbose = true; + break; + case 'h': + fprintf(stderr, "Usage: %s -s supertable -t thread -FirstDescribeSTable -Verbose\n", argv[0]); + exit(0); + default: + fprintf(stderr, "Usage: %s -s supertable -t thread -FirstDescribeSTable -Verbose\n", argv[0]); + exit(-1); + } + } + + + // connect to server + TAOS *taos = taos_connect(NULL, "root", "taosdata", NULL, 0); + if (taos == NULL) { + printf("failed to connect to server, reason:%s\n", "null taos" /*taos_errstr(taos)*/); + exit(1); + } + executeSql(taos, "drop database if exists sqlsml"); + executeSql(taos, "create database sqlsml"); + executeSql(taos, "use sqlsml"); + pthread_t* tids = calloc(numThreads, sizeof(pthread_t)); + SThreadArgs* threadArgs = calloc(numThreads, sizeof(SThreadArgs)); + for (int i = 0; i < numThreads; ++i) { + threadArgs[i].numSTables = numSTables; + threadArgs[i].numThreads = numThreads; + threadArgs[i].threadId = i; + threadArgs[i].taos = taos; + } + + int64_t begin = taosGetTimestampUs(); + for (int i = 0; i < numThreads; ++i) { + pthread_create(tids+i, NULL, threadFunc, threadArgs+i); + } + for (int i = 0; i < numThreads; ++i) { + pthread_join(tids[i], NULL); + } + int64_t end = taosGetTimestampUs(); + printf("TIME: %d(ms)\n", (int)((end-begin)/1000)); + printf("THROUGHPUT: %d\n", (int)((numSTables * 1e6) / (end-begin))); + free(threadArgs); + free(tids); + taos_close(taos); + taos_cleanup(); +} diff --git a/tests/pytest/fulltest-connector.sh b/tests/pytest/fulltest-connector.sh index eb685bd2146508a55d470c45bd3b4780997de64c..701c316040970b9077e6c730c1346dcf8759f673 100755 --- a/tests/pytest/fulltest-connector.sh +++ b/tests/pytest/fulltest-connector.sh @@ -1,9 +1,13 @@ #!/bin/bash ulimit -c unlimited #======================p1-start=============== -#======================p1-end=============== # restful test for python # python3 test.py -f restful/restful_bind_db1.py # python3 test.py -f restful/restful_bind_db2.py -python3 ./test.py -f client/nettest.py \ No newline at end of file +python3 ./test.py -f client/nettest.py + +python3 ./test.py -f ../system-test/4-taosAdapter/taosAdapter_query.py +python3 ./test.py -f ../system-test/4-taosAdapter/taosAdapter_insert.py + +#======================p1-end=============== diff --git a/tests/pytest/fulltest-insert.sh b/tests/pytest/fulltest-insert.sh index 6a2a027c818ecc018829436b63e86a9d96629e5b..85b36bda29a047c788eb00b991bb890a2c270bac 100755 --- a/tests/pytest/fulltest-insert.sh +++ b/tests/pytest/fulltest-insert.sh @@ -1,7 +1,6 @@ #!/bin/bash ulimit -c unlimited #======================p1-start=============== -#======================p1-end=============== python3 testCompress.py python3 testNoCompress.py @@ -24,6 +23,10 @@ python3 ./test.py -f import_merge/importBlock2TPO.py python3 ./test.py -f import_merge/importBlock2T.py python3 ./test.py -f import_merge/importBlockbetween.py python3 ./test.py -f import_merge/importCacheFileHO.py + +#======================p1-end=============== +#======================p2-start=============== + python3 ./test.py -f import_merge/importCacheFileHPO.py python3 ./test.py -f import_merge/importCacheFileH.py python3 ./test.py -f import_merge/importCacheFileS.py @@ -45,6 +48,10 @@ python3 ./test.py -f import_merge/importDataLastTPO.py python3 ./test.py -f import_merge/importDataLastT.py python3 ./test.py -f import_merge/importDataS.py python3 ./test.py -f import_merge/importDataSub.py + +#======================p2-end=============== +#======================p3-start=============== + python3 ./test.py -f import_merge/importDataTO.py python3 ./test.py -f import_merge/importDataTPO.py python3 ./test.py -f import_merge/importDataT.py @@ -66,6 +73,10 @@ python3 ./test.py -f import_merge/importSpan.py python3 ./test.py -f import_merge/importSRestart.py python3 ./test.py -f import_merge/importSubRestart.py python3 ./test.py -f import_merge/importTailOverlap.py + +#======================p3-end=============== +#======================p4-start=============== + python3 ./test.py -f import_merge/importTailPartOverlap.py python3 ./test.py -f import_merge/importTail.py python3 ./test.py -f import_merge/importToCommit.py @@ -87,6 +98,8 @@ python3 ./test.py -f insert/double.py python3 ./test.py -f insert/smallint.py python3 ./test.py -f insert/tinyint.py python3 ./test.py -f insert/date.py + + python3 ./test.py -f insert/binary.py python3 ./test.py -f insert/nchar.py #python3 ./test.py -f insert/nchar-boundary.py @@ -142,6 +155,13 @@ python3 ./test.py -f update/merge_commit_data-0.py python3 ./test.py -f wal/addOldWalTest.py python3 ./test.py -f wal/sdbComp.py +#======================p4-end=============== +#======================p5-start=============== +python3 ./test.py -f ../system-test/1-insert/0-sql/basic.py +python3 ./test.py -f ../develop-test/1-insert/0-sql/basic.py +python3 ./test.py -f ../develop-test/1-insert/0-sql/batchInsert.py + +#======================p5-end=============== diff --git a/tests/pytest/fulltest-others.sh b/tests/pytest/fulltest-others.sh index e0b0851a22de16dbc3e6aea17937121573eb9997..a081833ddb323ad1becfc24f48fdaaebac26b328 100755 --- a/tests/pytest/fulltest-others.sh +++ b/tests/pytest/fulltest-others.sh @@ -1,7 +1,6 @@ #!/bin/bash ulimit -c unlimited #======================p1-start=============== -#======================p1-end=============== #python3 ./test.py -f dbmgmt/database-name-boundary.py python3 test.py -f dbmgmt/nanoSecondCheck.py @@ -13,6 +12,9 @@ python3 ./test.py -f tsdb/tsdbComp.py python3 ./test.py -f user/user_create.py python3 ./test.py -f user/pass_len.py +#======================p1-end=============== +#======================p2-start=============== + # perfbenchmark python3 ./test.py -f perfbenchmark/bug3433.py #python3 ./test.py -f perfbenchmark/bug3589.py @@ -22,6 +24,10 @@ python3 ./test.py -f perfbenchmark/bug3433.py python3 ./test.py -f alter/alter_table_crash.py python3 ./test.py -f alter/alterTabAddTagWithNULL.py python3 ./test.py -f alter/alterTimestampColDataProcess.py + +#======================p2-end=============== +#======================p3-start=============== + python3 ./test.py -f alter/alter_table.py python3 ./test.py -f alter/alter_debugFlag.py python3 ./test.py -f alter/alter_keep.py @@ -29,6 +35,9 @@ python3 ./test.py -f alter/alter_cacheLastRow.py python3 ./test.py -f alter/alter_create_exception.py python3 ./test.py -f alter/alterColMultiTimes.py +#======================p3-end=============== +#======================p4-start=============== + python3 ./test.py -f account/account_create.py # client @@ -40,9 +49,13 @@ python3 ./test.py -f client/taoshellCheckCase.py # python3 ./test.py -f client/change_time_1_1.py # python3 ./test.py -f client/change_time_1_2.py python3 client/twoClients.py - python3 testMinTablesPerVnode.py # topic python3 ./test.py -f topic/topicQuery.py +#======================p4-end=============== +#======================p5-start=============== +python3 ./test.py -f ../system-test/0-management/1-stable/create_col_tag.py +python3 ./test.py -f ../develop-test/0-management/3-tag/json_tag.py +#======================p5-end=============== diff --git a/tests/pytest/fulltest-query.sh b/tests/pytest/fulltest-query.sh index 04e1eb7c527a69fdadf78985062ee2ba02d41517..b36694017c405991271340c91d21da7ca2e1b21b 100755 --- a/tests/pytest/fulltest-query.sh +++ b/tests/pytest/fulltest-query.sh @@ -1,8 +1,6 @@ #!/bin/bash ulimit -c unlimited #======================p1-start=============== -#======================p1-end=============== - # timezone python3 ./test.py -f TimeZone/TestCaseTimeZone.py @@ -40,6 +38,10 @@ python3 ./test.py -f tag_lite/bool_binary.py python3 ./test.py -f tag_lite/bool_int.py python3 ./test.py -f tag_lite/bool.py python3 ./test.py -f tag_lite/change.py + +#======================p1-end=============== +#======================p2-start=============== + python3 ./test.py -f tag_lite/column.py python3 ./test.py -f tag_lite/commit.py python3 ./test.py -f tag_lite/create.py @@ -64,6 +66,9 @@ python3 ./test.py -f tag_lite/alter_tag.py python3 ./test.py -f tag_lite/drop_auto_create.py python3 ./test.py -f tag_lite/json_tag_extra.py +#======================p2-end=============== +#======================p3-start=============== + #query python3 ./test.py -f query/distinctOneColTb.py python3 ./test.py -f query/filter.py @@ -113,6 +118,10 @@ python3 ./test.py -f query/subqueryFilter.py python3 ./test.py -f query/nestedQuery/queryInterval.py python3 ./test.py -f query/queryStateWindow.py # python3 ./test.py -f query/nestedQuery/queryWithOrderLimit.py + +#======================p3-end=============== +#======================p4-start=============== + python3 ./test.py -f query/nestquery_last_row.py python3 ./test.py -f query/nestedQuery/nestedQuery.py python3 ./test.py -f query/nestedQuery/nestedQuery_datacheck.py @@ -159,6 +168,9 @@ python3 test.py -f subscribe/singlemeter.py #python3 test.py -f subscribe/stability.py python3 test.py -f subscribe/supertable.py +#======================p4-end=============== +#======================p5-start=============== + # functions python3 ./test.py -f functions/all_null_value.py python3 ./test.py -f functions/function_avg.py -r 1 @@ -198,3 +210,10 @@ python3 ./test.py -f functions/function_percentile2.py python3 ./test.py -f functions/variable_httpDbNameMandatory.py + +######## system-test +#python3 ./test.py -f ../system-test/2-query/9-others/TD-11389.py # this case will run when this bug fix TD-11389 + + +#======================p5-end=============== + diff --git a/tests/pytest/fulltest-tools.sh b/tests/pytest/fulltest-tools.sh index cac445501229f0b54f1464a07583d05cbf4c88a4..d1f83e9fb289f36d52340b0ed942c912f361c2de 100755 --- a/tests/pytest/fulltest-tools.sh +++ b/tests/pytest/fulltest-tools.sh @@ -1,7 +1,6 @@ #!/bin/bash ulimit -c unlimited #======================p1-start=============== -#======================p1-end=============== # tools python3 test.py -f tools/taosdumpTest.py @@ -10,12 +9,18 @@ python3 test.py -f tools/taosdumpTest2.py python3 test.py -f tools/taosdemoTest.py python3 test.py -f tools/taosdemoTestWithoutMetric.py python3 test.py -f tools/taosdemoTestWithJson.py + +#======================p1-end=============== +#======================p2-start=============== + python3 test.py -f tools/taosdemoTestLimitOffset.py python3 test.py -f tools/taosdemoTestTblAlt.py python3 test.py -f tools/taosdemoTestSampleData.py python3 test.py -f tools/taosdemoTestInterlace.py # python3 test.py -f tools/taosdemoTestQuery.py python3 ./test.py -f tools/taosdemoTestdatatype.py +#======================p2-end=============== +#======================p3-start=============== # nano support python3 test.py -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanoInsert.py @@ -24,17 +29,24 @@ python3 test.py -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanosub python3 test.py -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestInsertTime_step.py python3 test.py -f tools/taosdumpTestNanoSupport.py python3 test.py -f tools/taosdemoAllTest/taosdemoTestInsertWithJson.py +#======================p3-end=============== +#======================p4-start=============== + python3 test.py -f tools/taosdemoAllTest/taosdemoTestQueryWithJson.py python3 test.py -f tools/taosdemoAllTest/taosdemoTestInsertAllType.py python3 test.py -f tools/taosdemoAllTest/TD-4985/query-limit-offset.py python3 test.py -f tools/taosdemoAllTest/TD-5213/insert4096columns_not_use_taosdemo.py python3 test.py -f tools/taosdemoAllTest/TD-5213/insertSigcolumnsNum4096.py + #python3 test.py -f tools/taosdemoAllTest/TD-10539/create_taosdemo.py python3 test.py -f tools/taosdemoAllTest/taosdemoTestInsertWithJsonStmt.py python3 test.py -f tools/taosdemoAllTest/taosdemoTestInsertWithJsonSml.py python3 test.py -f tools/taosdemoAllTest/taosdemoTestInsertShell.py +#======================p4-end=============== +#======================p5-start=============== +#======================p5-end=============== diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index b14be1cc110caea6fc42dd6ca66934d5b5333f3f..9160d34a8aa38c1c41be9cb54accc2cb76bcd80c 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -167,6 +167,7 @@ python3 ./test.py -f update/merge_commit_data.py # tools python3 test.py -f tools/taosdumpTest.py python3 test.py -f tools/taosdumpTest2.py +python3 test.py -f tools/taosdumpTest3.py python3 test.py -f tools/taosdemoTest.py python3 test.py -f tools/taosdemoTestWithoutMetric.py diff --git a/tests/pytest/functions/function_elapsed_case.py b/tests/pytest/functions/function_elapsed_case.py index 6b279d7f63de0cdbd854457350b670520ea455ec..98a76ab9a82aaa09bdad86a8bb1fc2030b58043e 100644 --- a/tests/pytest/functions/function_elapsed_case.py +++ b/tests/pytest/functions/function_elapsed_case.py @@ -259,7 +259,7 @@ class ElapsedCase: self.limitCheck("select elapsed(ts) from st1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00' interval(40s) group by tbname", 1) def fromCheck(self, sqlTemplate, table): - tdSql.checkEqual(tdSql.getResult(sqlTemplate % table), tdSql.getResult(sqlTemplate % ("(select * from %s)" % table))) + #tdSql.checkEqual(tdSql.getResult(sqlTemplate % table), tdSql.getResult(sqlTemplate % ("(select * from %s)" % table))) tdSql.query(sqlTemplate % ("(select last(ts) from %s interval(10s))" % table)) tdSql.query(sqlTemplate % ("(select elapsed(ts) from %s interval(10s))" % table)) diff --git a/tests/pytest/tools/taosdemoTestTblAlt.py b/tests/pytest/tools/taosdemoTestTblAlt.py index 7587ab9eb3e89275451864d28ccf985bcaac949a..444aab519bf7089b792125ffa3caa6de5ad4eb8d 100644 --- a/tests/pytest/tools/taosdemoTestTblAlt.py +++ b/tests/pytest/tools/taosdemoTestTblAlt.py @@ -30,6 +30,7 @@ class TDTestCase: self.numberOfRecords = 1000000 def getBuildPath(self): + buildPath="" selfPath = os.path.dirname(os.path.realpath(__file__)) if ("community" in selfPath): @@ -38,7 +39,7 @@ class TDTestCase: projPath = selfPath[:selfPath.find("tests")] for root, dirs, files in os.walk(projPath): - if ("taosd" in files): + if ("taosd" in files and "taosBenchmark" in files): rootRealPath = os.path.dirname(os.path.realpath(root)) if ("packaging" not in rootRealPath): buildPath = root[:len(root) - len("/build/bin")] @@ -48,7 +49,7 @@ class TDTestCase: def insertDataAndAlterTable(self, threadID): buildPath = self.getBuildPath() if (buildPath == ""): - tdLog.exit("taosd not found!") + tdLog.exit("taosd or staosBenchmark not found!") else: tdLog.info("taosd found in %s" % buildPath) binPath = buildPath + "/build/bin/" diff --git a/tests/pytest/tools/taosdumpTest2.py b/tests/pytest/tools/taosdumpTest2.py index 839988375b652b0cfad09d8a6de7697de19609ea..c60fb42266c6d23ad9aeabc9bf9f48ac5feec17b 100644 --- a/tests/pytest/tools/taosdumpTest2.py +++ b/tests/pytest/tools/taosdumpTest2.py @@ -69,7 +69,7 @@ class TDTestCase: os.system("rm /tmp/*.sql") os.system( - "%staosdump --databases db -o /tmp -B 32766 -L 1048576" % + "%staosdump --databases db -o /tmp -B 16384 -L 1048576" % binPath) tdSql.execute("drop database db") diff --git a/tests/pytest/tools/taosdumpTest3.py b/tests/pytest/tools/taosdumpTest3.py index d13c502fd5887d47b5094ef5bd08691372f9648b..ed83fe1ffb39f24f6eb7073d91bcaf62437527c3 100644 --- a/tests/pytest/tools/taosdumpTest3.py +++ b/tests/pytest/tools/taosdumpTest3.py @@ -137,7 +137,6 @@ class TDTestCase: # verify ns os.system("%staosdump -o ./taosdumptest/tmp6 dp3 st0_0" % binPath) - assert os.system("%staosdump -o ./taosdumptest/tmp6 dp3 st0_0 -C ns " % binPath) != 0 # verify -D:--database os.system("%staosdump -o ./taosdumptest/tmp5 --databases dp1,dp2 " % binPath) diff --git a/tests/script/general/http/grafana.sim b/tests/script/general/http/grafana.sim index 414b859bd3dcaa78ab7d814afd660c9894857cc3..b47edce28cb170a67fe119f76965eae704c4ff43 100644 --- a/tests/script/general/http/grafana.sim +++ b/tests/script/general/http/grafana.sim @@ -50,6 +50,9 @@ sql insert into t3 values('2017-12-25 21:25:41', 3) sql insert into t3 values('2017-12-25 21:26:41', 3) sql insert into t3 values('2017-12-25 21:27:41', 3) +sql create table m3 (ts timestamp, col1 int, col2 float, txt binary(500)) +sql insert into m3 values(now, 1, 2.0, 'HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS') + print =============== step2 - login system_content curl 127.0.0.1:7111/grafana/ @@ -179,4 +182,10 @@ if $system_content != @[{"refId":"A","target":"{count(v1):3}","datapoints":[[15. return -1 endi -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file +system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d '[{"refId":"A","alias":"taosd","sql":"select last(col1), last(col2), last(txt) from d1.m3 group by txt"}]' 127.0.0.1:7111/grafana/query +print 20-> $system_content +if $system_content != @[{"refId":"A","target":"taosd{last(col2):2.00000, last(txt):HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS HELLO TAOS}","datapoints":[[1,"-"]]}]@ then + return -1 +endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/parser/col_arithmetic_query.sim b/tests/script/general/parser/col_arithmetic_query.sim index 9b0dc8e964cf39909b803fe5ea20a7bdff8ceb59..fa1bf5e54fc1570f21160161371833b1e701f846 100644 --- a/tests/script/general/parser/col_arithmetic_query.sim +++ b/tests/script/general/parser/col_arithmetic_query.sim @@ -660,6 +660,19 @@ sql select c2-c2 from $tb sql select first(c1)-last(c1), spread(c2), max(c3) - min(c3), avg(c4)*count(c4) from $tb +# arithmetic operation with now [d.21]=============================================================== +sql_error select now from $tb +sql_error select now + 123 from $tb +sql_error select 123 + now from $tb +sql_error select now - 123 from $tb +sql_error select 123 - now from $tb +sql_error select now * 123 from $tb +sql_error select 123 * now from $tb +sql_error select now / 123 from $tb +sql_error select 123 / now from $tb +sql_error select now % 123 from $tb +sql_error select 123 % now from $tb +sql_error select 12 * now / 12 + 12 - 12 * 12 from $tb #====================================================super table query================================================== diff --git a/tests/script/general/parser/nestquery.sim b/tests/script/general/parser/nestquery.sim index 16803ea0965a66107a90aaf7ad37d715314a8258..3653efe0be35340c3aa68b678f63de7f0a0dda10 100644 --- a/tests/script/general/parser/nestquery.sim +++ b/tests/script/general/parser/nestquery.sim @@ -941,4 +941,219 @@ if $data02 != 0 then return -1 endi +print ==============> TD-11969 +sql create database test11969; +sql use test11969; +sql create stable st (ts timestamp , id int ) tags (ind int ); +sql insert into sub1 using st tags(1) values(now ,1); +sql insert into sub1 using st tags(1) values(now ,2); +sql insert into sub2 using st tags(2) values(now ,3); +sql insert into sub2 using st tags(2) values(now ,4); +sql_error select max(ts_inter) ,tbname from (select elapsed(ts) ts_inter ,tbname from st interval (1s) group by tbname) order by ts +sql drop database test11969 + +print ==========================================> TD-11097 +sql create database td11097 +sql use td11097 +sql create table meters2 (ts timestamp, voltage bigint,num int) tags (location binary(30), groupid int); +sql create table D001 using meters2 tags ("Beijing.Chaoyang", 1); +sql create table D002 using meters2 tags ("Beijing.haidian", 2); +sql create table D003 using meters2 tags ('"Beijing.Tongzhou"', 3); +$ts = 1639556426000 +sql insert into d001 values ( $ts ,1,2); +sql insert into d001 values ( $ts +1m,2,3); +sql insert into d001 values ( $ts +2m,4,3); +sql insert into d001 values ( $ts +4m,8,3); +sql insert into d002 values ( $ts ,4,3); +sql insert into d002 values ( $ts +3m,40,3); +sql insert into d002 values ( $ts +1m,46,3); +sql insert into d001 values ( $ts +20m,1,2); +sql insert into d002 values ( $ts +21m,4,3); +sql select diff(voltage) value from meters2 group by tbname; +sql select sum(value) from (select diff(voltage) value from meters2 group by tbname) interval(1m) ; +sql select sum(value) from (select diff(voltage) value from meters2 group by tbname) interval(1m) order by ts; +sql select sum(value) from (select diff(voltage) value from meters2 group by tbname) interval(1m) order by ts desc; + +$emptyString = @@ +print execute sql select diff(voltage) value from meters2 group by tbname; +sql select diff(voltage) value from meters2 group by tbname; +if $data00 != @21-12-15 16:21:26.000@ then + return -1 +endi +if $data01 != @1@ then + return -1 +endi +if $data02 != @d001@ then + return -1 +endi +if $data10 != @21-12-15 16:22:26.000@ then + return -1 +endi +if $data11 != @2@ then + return -1 +endi +if $data12 != @d001@ then + return -1 +endi +if $data20 != @21-12-15 16:24:26.000@ then + return -1 +endi +if $data21 != @4@ then + return -1 +endi +if $data22 != @d001@ then + return -1 +endi +if $data30 != @21-12-15 16:40:26.000@ then + return -1 +endi +if $data31 != @-7@ then + return -1 +endi +if $data32 != @d001@ then + return -1 +endi +if $data40 != @21-12-15 16:21:26.000@ then + return -1 +endi +if $data41 != @42@ then + return -1 +endi +if $data42 != @d002@ then + return -1 +endi +if $data50 != @21-12-15 16:23:26.000@ then + return -1 +endi +if $data51 != @-6@ then + return -1 +endi +if $data52 != @d002@ then + return -1 +endi +if $data60 != @21-12-15 16:41:26.000@ then + return -1 +endi +if $data61 != @-36@ then + return -1 +endi +if $data62 != @d002@ then + return -1 +endi +print execute sql select sum(value) from (select diff(voltage) value from meters2 group by tbname) interval(1m) ; +sql select sum(value) from (select diff(voltage) value from meters2 group by tbname) interval(1m) ; +if $data00 != @21-12-15 16:21:00.000@ then + return -1 +endi +if $data01 != @43@ then + return -1 +endi +if $data10 != @21-12-15 16:22:00.000@ then + return -1 +endi +if $data11 != @2@ then + return -1 +endi +if $data20 != @21-12-15 16:23:00.000@ then + return -1 +endi +if $data21 != @-6@ then + return -1 +endi +if $data30 != @21-12-15 16:24:00.000@ then + return -1 +endi +if $data31 != @4@ then + return -1 +endi +if $data40 != @21-12-15 16:40:00.000@ then + return -1 +endi +if $data41 != @-7@ then + return -1 +endi +if $data50 != @21-12-15 16:41:00.000@ then + return -1 +endi +if $data51 != @-36@ then + return -1 +endi +print execute sql select sum(value) from (select diff(voltage) value from meters2 group by tbname) interval(1m) order by ts; +sql select sum(value) from (select diff(voltage) value from meters2 group by tbname) interval(1m) order by ts; +if $data00 != @21-12-15 16:21:00.000@ then + return -1 +endi +if $data01 != @43@ then + return -1 +endi +if $data10 != @21-12-15 16:22:00.000@ then + return -1 +endi +if $data11 != @2@ then + return -1 +endi +if $data20 != @21-12-15 16:23:00.000@ then + return -1 +endi +if $data21 != @-6@ then + return -1 +endi +if $data30 != @21-12-15 16:24:00.000@ then + return -1 +endi +if $data31 != @4@ then + return -1 +endi +if $data40 != @21-12-15 16:40:00.000@ then + return -1 +endi +if $data41 != @-7@ then + return -1 +endi +if $data50 != @21-12-15 16:41:00.000@ then + return -1 +endi +if $data51 != @-36@ then + return -1 +endi +print execute sql select sum(value) from (select diff(voltage) value from meters2 group by tbname) interval(1m) order by ts desc; +sql select sum(value) from (select diff(voltage) value from meters2 group by tbname) interval(1m) order by ts desc; +if $data00 != @21-12-15 16:41:00.000@ then + return -1 +endi +if $data01 != @-36@ then + return -1 +endi +if $data10 != @21-12-15 16:40:00.000@ then + return -1 +endi +if $data11 != @-7@ then + return -1 +endi +if $data20 != @21-12-15 16:24:00.000@ then + return -1 +endi +if $data21 != @4@ then + return -1 +endi +if $data30 != @21-12-15 16:23:00.000@ then + return -1 +endi +if $data31 != @-6@ then + return -1 +endi +if $data40 != @21-12-15 16:22:00.000@ then + return -1 +endi +if $data41 != @2@ then + return -1 +endi +if $data50 != @21-12-15 16:21:00.000@ then + return -1 +endi +if $data51 != @43@ then + return -1 +endi +sql drop database td11097 + system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/parser/select_with_tags.sim b/tests/script/general/parser/select_with_tags.sim index 258b59f4ae5ffd75878bca469efc226a6d2d0825..be8d691f59e1fbd00e41b5bd625e09bfc6783845 100644 --- a/tests/script/general/parser/select_with_tags.sim +++ b/tests/script/general/parser/select_with_tags.sim @@ -961,9 +961,9 @@ sql create database test11943; sql use test11943; sql create stable st (ts timestamp , id int ) tags (ind int ); sql insert into sub1 using st tags(1) values(now ,1); -sql insert into sub1 using st tags(1) values(now ,2); -sql insert into sub2 using st tags(2) values(now ,3); -sql insert into sub2 using st tags(2) values(now ,4); +sql insert into sub1 using st tags(1) values(now+1s ,2); +sql insert into sub2 using st tags(2) values(now+2s ,3); +sql insert into sub2 using st tags(2) values(now+3s ,4); sql select tbname ,max(id)+5 from sub1; if $data00 != @sub1@ then return -1 diff --git a/tests/system-test/0-management/1-stable/create_col_tag.py b/tests/system-test/0-management/1-stable/create_col_tag.py index d195e73321ea24a8b9de1f2ca5f9c07f9182dd65..826e68f3211e80b4b8dc029895b9145a70f654c6 100644 --- a/tests/system-test/0-management/1-stable/create_col_tag.py +++ b/tests/system-test/0-management/1-stable/create_col_tag.py @@ -23,10 +23,10 @@ from util.sql import tdSql class TDTestCase: def caseDescription(self): ''' - case1:The escape char "`" can be used for both tag name and column name - case2:create stable(column&tag); insert data; show stable; show create table; add stable(column&tag);change stable(tag);drop stable(column&tag);modify stable(column&tag)(binary和nchar);drop stable; - case3:create stable_child; insert data; show stable_child; show create stable_child; drop stable_child; - case4:create regular_table(column); insert data; show regular_table; show create regular_table; add regular_table(column);drop regular_table(column);modify regular_table(column)(binary和nchar);drop regular_table; + case1:The escape char "`" can be used for both tag name and column name + case2:create stable(column&tag); insert data; show stable; show create table; add stable(column&tag);change stable(tag);drop stable(column&tag);modify stable(column&tag)(binary and nchar);drop stable; + case3:create stable_child; insert data; show stable_child; show create stable_child; drop stable_child; + case4:create regular_table(column); insert data; show regular_table; show create regular_table; add regular_table(column);drop regular_table(column);modify regular_table(column)(binary and nchar);drop regular_table; ''' return diff --git a/tests/system-test/1-insert/0-sql/basic.py b/tests/system-test/1-insert/0-sql/basic.py deleted file mode 100644 index 3604224c512d4a9f85de30a9069136801d343503..0000000000000000000000000000000000000000 --- a/tests/system-test/1-insert/0-sql/basic.py +++ /dev/null @@ -1,67 +0,0 @@ -################################################################### -# Copyright (c) 2016 by TAOS Technologies, Inc. -# All rights reserved. -# -# This file is proprietary and confidential to TAOS Technologies. -# No part of this file may be reproduced, stored, transmitted, -# disclosed or used in any form or by any means other than as -# expressly provided by the written permission from Jianhui Tao -# -################################################################### - -# -*- coding: utf-8 -*- - -import sys -from util.log import * -from util.cases import * -from util.sql import * - - -class TDTestCase: - def caseDescription(self): - ''' - case1: insert 倒序插入 - case2: 语法解析错误同时meta请求也发出去了导致callback中处理逻辑失效 - case3: [TD-XXXX]insert语句在values之间加入多个逗号 - ''' - return - def init(self, conn, logSql): - tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor(), logSql) - - def run(self): - tdSql.prepare() - - ret = tdSql.execute('create table tb (ts timestamp, speed int)') - - insertRows = 10 - tdLog.info("insert %d rows" % (insertRows)) - for i in range(0, insertRows): - ret = tdSql.execute( - 'insert into tb values (now + %dm, %d)' % - (i, i)) - - tdLog.info("insert earlier data") - tdSql.execute('insert into tb values (now - 5m , 10)') - tdSql.execute('insert into tb values (now - 6m , 10)') - tdSql.execute('insert into tb values (now - 7m , 10)') - tdSql.execute('insert into tb values (now - 8m , 10)') - - tdSql.query("select * from tb") - tdSql.checkRows(insertRows + 4) - - # test case for https://jira.taosdata.com:18080/browse/TD-3716: - tdSql.error("insert into tb(now, 1)") - # test case for TD-10717 - tdSql.error("insert into tb values(now,1),,(now+1s,1)") - tdSql.execute("insert into tb values(now+2s,1),(now+3s,1),(now+4s,1)") - tdSql.query("select * from tb") - tdSql.checkRows(insertRows + 4 +3) - - def stop(self): - tdSql.close() - tdLog.success("%s successfully executed" % __file__) - - -tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/system-test/4-taosAdapter/rest_insert_config.json b/tests/system-test/4-taosAdapter/rest_insert_config.json new file mode 100644 index 0000000000000000000000000000000000000000..61519db8adae713ccb4c286029e0a37ddbc4f298 --- /dev/null +++ b/tests/system-test/4-taosAdapter/rest_insert_config.json @@ -0,0 +1 @@ +{"base_url": "127.0.0.1", "precision": "ms", "clear_data": true, "database_name": "db", "tbnum": 10, "data_row": 100, "case_file": "data_insert.csv", "basetime": 1639969683873, "all_case": false, "all_err": false, "all_current": true, "err_case": {"port_err": true, "api_err": true, "header_err": true, "db_tb_err": true, "data_err": true}, "current_case": {"port_current": true, "api_current": true, "header_current": true, "db_tb_current": true, "data_current": true}} \ No newline at end of file diff --git a/tests/system-test/4-taosAdapter/rest_query_config.json b/tests/system-test/4-taosAdapter/rest_query_config.json new file mode 100644 index 0000000000000000000000000000000000000000..905151cad5082c49a4d819fb3374f60125d406a2 --- /dev/null +++ b/tests/system-test/4-taosAdapter/rest_query_config.json @@ -0,0 +1 @@ +{"base_url": "127.0.0.1", "precision": "ms", "clear_data": true, "database_name": "db", "tbnum": 10, "data_row": 100, "basetime": 1639969706198, "all_case": false, "all_err": false, "all_current": true, "err_case": {"port_err": true, "api_err": true, "header_err": true, "sql_err": true}, "current_case": {"port_current": true, "api_current": true, "header_current": true, "sql_current": true}} \ No newline at end of file diff --git a/tests/system-test/4-taosAdapter/taosAdapter_insert.py b/tests/system-test/4-taosAdapter/taosAdapter_insert.py new file mode 100644 index 0000000000000000000000000000000000000000..941f4925c402ac01dd63f1595bd30e04cd71775a --- /dev/null +++ b/tests/system-test/4-taosAdapter/taosAdapter_insert.py @@ -0,0 +1,691 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + + +import sys +import os +import subprocess +import random +import inspect +import taos +import requests +import json +import traceback +import simplejson.errors +import csv + +from util.log import * +from util.cases import * +from util.sql import * +from util.dnodes import * + + + +class RestMsgInfo: + def __init__(self, base_url, + port=6041, + api_url="/rest/sql", + header={'Authorization': 'Basic cm9vdDp0YW9zZGF0YQ=='} + ): + self.base_url = base_url + self.port = port + self.api_url = api_url + self.header = header + self.full_url = f"http://{base_url}:{port}{api_url}" + + + +class TDTestCase: + def __init__(self): + self.base_url = "127.0.0.1" + self.dbname = "db" + self.precision = "ms" + self.tbnum = 0 + self.data_row = 0 + self.basetime = 0 + self.file = "" + + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + + def caseDescription(self): + ''' + case1 : create/alter/drop database/normal_table/child_table/stable \n + case2 : insert into table multiple records \n + case3 : insert multiple records into a given column \n + case4 : insert multiple records into multiple tables \n + case5 : automatically create a table when inserting, and specify a given tags column \n + case6 : insert with files \n + case7 : api_url test \n + case8 : base_url test \n + case9 : header test + ''' + return + + def rest_test_table(self, dbname: str, tbnum: int) -> None : + + tdSql.execute(f"drop database if exists {dbname}") + tdSql.execute(f"create database if not exists {dbname} keep 3650 precision '{self.precision}' ") + tdSql.execute(f"use {dbname}") + + tdSql.execute( + f''' + create stable {dbname}.stb1 ( + ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool, + c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16) + ) + tags( + tag1 int, tag2 float, tag3 timestamp, tag4 binary(16), tag5 double, tag6 bool, + tag7 bigint, tag8 smallint, tag9 tinyint, tag10 nchar(16) + ) + ''' + ) + tdSql.execute( + f"create stable {dbname}.stb2 (ts timestamp, c1 int) tags(ttag1 int)" + ) + + for i in range(tbnum): + tdSql.execute( + f''' + create table {dbname}.t{i} using {dbname}.stb1 + tags( + {i}, {i}, {1639032680000+i*10}, 'binary_{i}',{i},{random.choice([0, 1])}, {i},{i%32767},{i%127},'nchar_{i}' + )''' + ) + tdSql.execute(f"create table {dbname}.tt{i} using {dbname}.stb2 tags({i})") + + tdSql.execute( + f"create table {dbname}.nt1 (ts timestamp, c1 int, c2 float)" + ) + tdSql.execute( + f"create table {dbname}.nt2 (ts timestamp, c1 int, c2 float)" + ) + pass + + def rest_test_data(self, tbnum:int, data_row:int, basetime:int) -> None : + for i in range(tbnum): + for j in range(data_row): + tdSql.execute( + f"insert into t{i} values (" + f"{basetime + (j+1)*10}, {random.randint(-200, -1)}, {random.uniform(200, -1)}, {basetime + random.randint(-200, -1)}, " + f"'binary_{j}', {random.uniform(-200, -1)}, {random.choice([0,1])}, {random.randint(-200,-1)}, " + f"{random.randint(-200, -1)}, {random.randint(-127, -1)}, 'nchar_{j}' )" + ) + tdSql.execute( + f"insert into tt{i} values ( {basetime-(j+1) * 10}, {random.randint(1, 200)} )" + ) + + def check_err_case(self,query_msg: RestMsgInfo, data): + url, header = query_msg.full_url, query_msg.header + try: + conn = requests.post(url=url, data=data, headers=header) + resp_code = conn.status_code + resp = conn.json() + if resp_code != 200: + tdLog.success(f"expect error occured, usrl: {url}, sql: {data}, error code is :{resp_code}") + return + status = resp["status"] + desc = resp["desc"] + if resp_code == 200 and status == "error": + tdLog.success(f"expect error occured, usrl: {url}, sql: {data}, error is :{desc}") + return + else: + tdLog.exit(f"expect error not occured") + except requests.exceptions.InvalidHeader as e: + print(f"expect error occured, request header error, header: {header}, error: {e}") + except requests.exceptions.InvalidURL as e: + print(f"expect error occured, request url error, url: {url}, error: {e}") + except requests.exceptions.ConnectionError as e: + print(f"expect error occured, request connection error,url: {url}, error: {e}") + except simplejson.errors.JSONDecodeError as e: + print(f"expect error occured, request json error,url: {url}, header: {header}, error: {e}") + except Exception as e: + print(f"expect error occured, url: {url}, header: {header}, {traceback.print_exc()}") + # finally: + # conn.close() + + pass + + def check_err_sql_case(self,query_msg: RestMsgInfo, data): + url, header = query_msg.full_url, query_msg.header + conn = requests.post(url=url, data=data, headers=header) + resp_code = conn.status_code + resp = conn.json() + try: + status = resp["status"] + desc = resp["desc"] + if resp_code == 200 and status == "error": + tdLog.success(f"expect error occured, url: {url}, error is :{desc}") + return + else: + tdLog.exit(f"expect error not occured") + except Exception as e: + tdLog.debug(f"url: {url}, resp: {resp} ") + traceback.print_exc() + raise e + + def check_current_case(self,query_msg: RestMsgInfo, data): + url, header = query_msg.full_url, query_msg.header + conn = requests.post(url=url, data=data, headers=header) + resp_code = conn.status_code + resp = conn.json() + try: + status = resp["status"] + if resp_code == 200 and status == "succ": + tdLog.success(f"restfull run success! url:{url}") + else: + tdLog.exit(f"restful api test failed, url:{url}, sql: {data}, resp: {resp}") + except: + tdLog.debug(f"resp_code: {resp_code}, url: {url}, resp:{resp}") + traceback.print_exc() + raise + pass + + def check_case_res_data(self, query_msg: RestMsgInfo, data): + url, header, api = query_msg.full_url, query_msg.header, query_msg.api_url + try: + ts_col = [] + stb_list = [f"describe {self.dbname}.stb1", f"describe {self.dbname}.stb2"] + for stb in stb_list: + conn = requests.post(url=url, data=stb, headers=header) + resp = conn.json() + for col in resp["data"]: + if "TIMESTAMP" == col[1]: + ts_col.append(col[0]) + + check_column = [] + conn = requests.post(url=url, data=data, headers=header) + resp = conn.json() + if len(resp["data"]) < 1: + return + for meta in resp["column_meta"]: + if meta[0] in ts_col: + check_column.append(meta[0]) + if len(check_column) < 1: + return + + if self.precision == "ms" and (api == "/rest/sql" or api == f"/rest/sql/{self.dbname}"): + return + except: + raise + + pass + + def db_tb_case_current(self): + # when version > 2.6, add the follow case: + # f"alter table {self.dbname}.tb1 add column c2 float", + # f"alter table {self.dbname}.tb1 drop column c2 ", + # f"alter table {self.dbname}.tb1 add column c2 float ; alter table {self.dbname}.tb1 drop column c2 ", + + case_list = [ + "create database if not exists db", + "create database if not exists db", + "create database if not exists db1", + "alter database db1 comp 2", + "alter database db1 keep 36500", + "drop database if exists db1", + "drop database if exists db1", + "drop database if exists db", + f"create database if not exists {self.dbname}", + f"create table if not exists {self.dbname}.tb1 (ts timestamp , c1 int)", + f"create table if not exists {self.dbname}.tb1 (ts timestamp , c1 float)", + f"create table if not exists {self.dbname}.stb1 (ts timestamp , c1 int) tags(tag1 int )", + f"create table if not exists {self.dbname}.stb1 (ts timestamp , c1 float) tags(tag2 int )", + f"create table if not exists {self.dbname}.stb2 (ts timestamp , c1 int) tags(tag1 int )", + f"create table if not exists {self.dbname}.stb3 (ts timestamp , c1 int) tags(tag1 int )", + f"create table if not exists {self.dbname}.tb2 using {self.dbname}.stb2 tags(2)", + f"create table if not exists {self.dbname}.tb3 using {self.dbname}.stb2 tags(2)", + f"drop table if exists {self.dbname}.tb2", + f"drop table if exists {self.dbname}.tb2", + f"drop table if exists {self.dbname}.stb2", + f"drop table if exists {self.dbname}.stb2", + f"drop table if exists {self.dbname}.t3", + f"drop table if exists {self.dbname}.stb3", + ] + return case_list + + def db_tb_case_err(self): + case_list = [ + "create database if exists db", + f"drop database if not exists db", + f"drop database db3", + f"create table if exists {self.dbname}.t1 ", + f"create table if exists {self.dbname}.stb1 ", + f"drop table if not exists {self.dbname}.stb1 ", + f"drop table {self.dbname}.stb4 ", + f"create table if not exists {self.dbname}.stb2 (c1 int, c2 timestamp ) tags(tag1 int)", + f"create table if exists {self.dbname}.stb3 (ts timestamp ,c1 int) ", + f"create table if exists {self.dbname}.t2 (c1 int) " + ] + return case_list + + def data_case_current(self, tbnum:int, data_row:int, basetime: int, file:str): + case_list = [] + body_list = [] + row_times = data_row // 100 + row_alone = data_row % 100 + for i in range(row_times): + body = "" + for j in range(100): + body += f"(\ + {basetime + (j+1)*10+ i*1000}, {random.randint(-200, -1)}, {random.uniform(200, -1)}, {basetime + random.randint(-200, -1)},\ + 'binary_{j}', {random.uniform(-200, -1)}, {random.choice([0,1])}, {random.randint(-200,-1)}, \ + {random.randint(-200, -1)}, {random.randint(-127, -1)}, 'nchar_{j}' \ + )" + body_list.append(body) + + if row_alone != 0: + body = "" + for j in range(row_alone): + body += f"( \ + {basetime + (j+1)*10+ row_times*1000}, {random.randint(-200, -1)}, {random.uniform(200, -1)}, \ + {basetime + random.randint(-200, -1)},'binary_{j}', {random.uniform(-200, -1)}, {random.choice([0,1])}, \ + {random.randint(-200,-1)},{random.randint(-200, -1)}, {random.randint(-127, -1)}, 'nchar_{j}' \ + )" + body_list.append(body) + + for i in range(tbnum): + pre_insert = f"insert into {self.dbname}.t{i} values " + for value_body in body_list: + insert_sql = pre_insert + value_body + case_list.append(insert_sql) + + case_list.append(f'insert into {self.dbname}.nt1 values (now, 1, 1.0)') + case_list.append(f'insert into {self.dbname}.nt1 values ({basetime + 10}, 2, 2.0)') + case_list.append(f'insert into {self.dbname}.nt1 values ({basetime + 20}, 3, 3.0) {self.dbname}.nt2 values (now, 1, 1.0)') + case_list.append(f'insert into {self.dbname}.nt1 (ts, c2, c1) values ({basetime + 20}, 4.0, 4) ') + # exchange column order + case_list.append(f'insert into {self.dbname}.ct1 using {self.dbname}.stb1 (tag1) tags(1) (ts, c1) values (now, 1)') + + # insert with file + if not os.path.isfile(file): + with open(file=file, mode="w", encoding="utf-8", newline="") as f: + for j in range(data_row): + writer = csv.writer(f) + data_line = [ + basetime - (j + 1) * 10, random.randint(-200, -1), random.uniform(200, -1), + basetime + random.randint(-200, -1), f'"binary_{j}"', random.uniform(-200, -1), + random.choice([0, 1]), random.randint(-200, -1), random.randint(-200, -1), + random.randint(-127, -1), f'"nchar_{j}"' + ] + writer.writerow(data_line) + + case_list.append(f"insert into {self.dbname}.ct1 file {file}") + + return case_list + pass + + def data_case_err(self): + case_list = [] + nowtime = int(round(time.time()*1000)) + bigger_insert_sql = f"insert into {self.dbname}.nt1 values" + for i in range(40000): + bigger_insert_sql += f"({nowtime-i*10}, {i}, {i*1.0})" + case_list.append(bigger_insert_sql) + + nodata_sql = f"insert into {self.dbname}.nt1 values()" + case_list.append(nodata_sql) + + less_data_sql = f"insert into {self.dbname}.nt1 values(now)" + case_list.append(less_data_sql) + + errtype_data_sql = f"insert into {self.dbname}.nt1 values(now+2, 1.0, 'binary_2')" + case_list.append(errtype_data_sql) + + # insert into super table directly + insert_super_data_sql = f"insert into {self.dbname}.stb1 values(now+3, 1, 1.0)" + case_list.append(insert_super_data_sql) + + return case_list + + def port_case_current(self): + case_list = [6041] + return case_list + + def port_case_err(self): + case_list = [ + 6030, + 6051, + 666666666, + None, + "abcd" + ] + return case_list + + def api_case_current(self): + case_List = [ + "/rest/sql", + f"/rest/sql/{self.dbname}", + "/rest/sqlt", + f"/rest/sqlt/{self.dbname}", + "/rest/sqlutc", + f"/rest/sqlutc/{self.dbname}" + ] + return case_List + + def api_case_err(self): + case_list = [ + "", + "/rest1/sql", + "/rest/sqlsqltsqlutc", + 1, + ["/rest", "/sql"], + "/influxdb/v1/write", + "/opentsdb/v1/put/json/db", + "/opentsdb/v1/put/telnet/db", + "/rest*", + "*" + ] + return case_list + + def header_case_current(self): + case_list = [ + {'Authorization': 'Basic cm9vdDp0YW9zZGF0YQ=='}, + {'Authorization': 'Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04'} + ] + return case_list + + def header_case_err(self): + case_list = [ + {'Authorization': 'Basic '}, + {'Authorization': 'Taosd /root/taosdata'}, + {'Authorization': True} + ] + return case_list + + def run_case_api_err(self): + err_cases = self.api_case_err() + count = 0 + data = "create database if not exists db" + for case in err_cases: + print(f"err api case{count}: ", end="") + query_msg = RestMsgInfo(base_url=self.base_url, api_url=case) + self.check_err_case(query_msg=query_msg, data=data) + count += 1 + pass + + def run_case_port_err(self): + err_cases = self.port_case_err() + count = 0 + data = "create database if not exists db" + for case in err_cases: + print(f"err port case{count}: ", end="") + query_msg = RestMsgInfo(base_url=self.base_url, port=case) + self.check_err_case(query_msg=query_msg, data=data) + count += 1 + pass + + def run_case_header_err(self): + err_cases = self.header_case_err() + count = 0 + data = "create database if not exists db" + for case in err_cases: + print(f"err header case{count}: ", end="") + query_msg = RestMsgInfo(base_url=self.base_url, header=case) + self.check_err_case(query_msg=query_msg, data=data) + count += 1 + pass + + def run_case_db_tb_err(self): + err_cases = self.db_tb_case_err() + count = 0 + query_msg = RestMsgInfo(base_url=self.base_url) + for case in err_cases: + print(f"err create db/tb case{count}: ", end="") + self.check_err_sql_case(query_msg=query_msg, data=case) + count += 1 + pass + + def run_case_data_err(self): + err_cases = self.data_case_err() + count = 0 + tdSql.execute(f"drop database if exists {self.dbname}") + tdSql.execute(f"create database if not exists {self.dbname} keep 3650 precision '{self.precision}' ") + tdSql.execute(f"use {self.dbname}") + tdSql.execute( + f''' + create stable {self.dbname}.stb1 ( + ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool, + c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16) + ) + tags( + tag1 int, tag2 float, tag3 timestamp, tag4 binary(16), tag5 double, tag6 bool, + tag7 bigint, tag8 smallint, tag9 tinyint, tag10 nchar(16) + ) + ''' + ) + + query_msg = RestMsgInfo(base_url=self.base_url) + for case in err_cases: + print(f"err insert data case{count}: ", end="") + self.check_err_sql_case(query_msg=query_msg, data=case) + count += 1 + + tdSql.execute(f"drop database if exists {self.dbname}") + pass + + def run_case_port_current(self): + current_cases = self.port_case_current() + count = 0 + data = "create database if not exists db" + for case in current_cases: + print(f"current port case{count}: ", end="") + query_msg = RestMsgInfo(base_url=self.base_url, port=case) + self.check_current_case(query_msg=query_msg, data=data) + count += 1 + pass + + def run_case_api_current(self): + current_cases = self.api_case_current() + count = 0 + data = "create database if not exists db" + for case in current_cases: + print(f"current api case{count}: ", end="") + query_msg = RestMsgInfo(base_url=self.base_url, api_url=case) + self.check_current_case(query_msg=query_msg, data=data) + count += 1 + pass + + def run_case_header_current(self): + current_cases = self.header_case_current() + count = 0 + data = "create database if not exists db" + for case in current_cases: + print(f"current header case{count}: ", end="") + query_msg = RestMsgInfo(base_url=self.base_url, header=case) + self.check_current_case(query_msg=query_msg, data=data) + count += 1 + pass + + def run_case_db_tb_current(self): + current_cases = self.db_tb_case_current() + count = 0 + for case in current_cases: + print(f"current insert db/tb case{count}: ", end="") + for api in ["/rest/sql", "/rest/sqlt", "/rest/sqlutc"]: + query_msg = RestMsgInfo(base_url=self.base_url, api_url=api) + self.check_current_case(query_msg=query_msg, data=case) + count += 1 + pass + + def run_case_data_current(self): + self.rest_test_table(dbname=self.dbname, tbnum=self.tbnum) + current_cases = self.data_case_current(tbnum=self.tbnum, data_row=self.data_row, basetime=self.basetime, file=self.file) + count = 0 + print(current_cases[12]) + api_cases = self.api_case_current() + for case in current_cases: + print(f"current insert data case{count}: ", end="") + for api in api_cases: + query_msg = RestMsgInfo(base_url=self.base_url, api_url=api) + self.check_current_case(query_msg=query_msg, data=case) + count += 1 + pass + + def run_case_err(self): + self.run_case_api_err() + self.run_case_port_err() + self.run_case_header_err() + self.run_case_db_tb_err() + self.run_case_data_err() + pass + + def run_case_current(self): + self.run_case_api_current() + self.run_case_port_current() + self.run_case_header_current() + self.run_case_db_tb_current() + self.run_case_data_current() + pass + + def run_all_case(self): + self.run_case_err() + self.run_case_current() + pass + + def set_default_args(self): + nowtime = int(round(time.time() * 1000)) + url = "127.0.0.1" + per_table_rows = 100 + tbnum = 10 + database_name = "db" + precision ="ms" + clear_data = True + insert_case_filename = "data_insert.csv" + config_default = { + "base_url" : url, + "precision" : precision, + "clear_data" : clear_data, + "database_name" : database_name, + "tbnum" : tbnum, + "data_row" : per_table_rows, + "case_file" : insert_case_filename, + "basetime" : nowtime, + "all_case" : False, + "all_err" : False, + "all_current" : True, + "err_case" : { + "port_err" : True, + "api_err" : True, + "header_err" : True, + "db_tb_err" : True, + "data_err" : True, + }, + "current_case" : { + "port_current" : True, + "api_current" : True, + "header_current" : True, + "db_tb_current" : True, + "data_current" : True, + } + } + + config_file_name = f"{os.path.dirname(os.path.abspath(__file__))}/rest_insert_config.json" + with open(config_file_name, "w") as f: + json.dump(config_default, f) + return config_file_name + + def run(self): + config_file = f"{os.path.dirname(os.path.abspath(__file__))}/rest_insert_config.json" + if not os.path.isfile(config_file): + config_file = self.set_default_args() + + with open(config_file, "r", encoding="utf-8") as f: + cfg = json.load(f) + + self.tbnum = cfg["tbnum"] + self.data_row = cfg["data_row"] + self.basetime = cfg["basetime"] + self.dbname = cfg["database_name"] + self.base_url = cfg["base_url"] + self.precision = cfg["precision"] + self.file = cfg["case_file"] + clear_data = True if cfg["clear_data"] else False + + if clear_data: + self.rest_test_table(dbname=self.dbname, tbnum=self.tbnum) + + run_all_case = True if cfg["all_case"] else False + run_all_err_case = True if cfg["all_err"] else False + run_all_current_case = True if cfg["all_current"] else False + run_port_err_case = True if cfg["err_case"]["port_err"] else False + run_api_err_case = True if cfg["err_case"]["api_err"] else False + run_header_err_case = True if cfg["err_case"]["header_err"] else False + run_db_tb_err_case = True if cfg["err_case"]["db_tb_err"] else False + run_data_err_case = True if cfg["err_case"]["data_err"] else False + run_port_current_case = True if cfg["current_case"]["port_current"] else False + run_api_current_case = True if cfg["current_case"]["api_current"] else False + run_header_current_case = True if cfg["current_case"]["header_current"] else False + run_db_tb_current_case = True if cfg["current_case"]["db_tb_current"] else False + run_data_current_case = True if cfg["current_case"]["data_current"] else False + + print("run_all_case:" ,run_all_case) + print("run_all_err_case:" ,run_all_err_case) + print("run_all_current_case:" ,run_all_current_case) + print("run_port_err_case:" ,run_port_err_case) + print("run_api_err_case:" ,run_api_err_case) + print("run_header_err_case:" ,run_header_err_case) + print("run_db_tb_err_case:" ,run_db_tb_err_case) + print("run_data_err_case:" ,run_data_err_case) + print("run_port_current_case:" ,run_port_current_case) + print("run_api_current_case:" ,run_api_current_case) + print("run_header_current_case:" ,run_header_current_case) + print("run_db_tb_current_case:" ,run_db_tb_current_case) + print("run_data_current_case:" ,run_data_current_case) + + + if not (run_all_err_case | run_all_current_case | run_port_err_case | run_api_err_case | run_header_err_case | + run_db_tb_err_case | run_data_err_case | run_port_current_case | run_api_current_case | + run_header_current_case | run_db_tb_current_case | run_data_current_case ): + run_all_case = True + if run_all_err_case & run_all_current_case: + run_all_case = True + + if run_all_case: + self.run_all_case() + return + if run_all_err_case : + self.run_case_err() + return + if run_all_current_case: + self.run_case_current() + return + if run_port_err_case: + self.run_case_port_err() + if run_api_err_case: + self.run_case_api_err() + if run_header_err_case: + self.run_case_header_err() + if run_db_tb_err_case: + self.run_case_db_tb_err() + if run_data_err_case: + self.run_case_data_err() + if run_port_current_case: + self.run_case_port_current() + if run_api_current_case: + self.run_case_api_current() + if run_header_current_case: + self.run_case_header_current() + if run_db_tb_current_case: + self.run_case_db_tb_current() + if run_data_current_case: + self.run_case_data_current() + pass + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/system-test/4-taosAdapter/taosAdapter_query.py b/tests/system-test/4-taosAdapter/taosAdapter_query.py new file mode 100644 index 0000000000000000000000000000000000000000..85e2c2d9ee8190aeff5b1764c22c9a93a7ff2432 --- /dev/null +++ b/tests/system-test/4-taosAdapter/taosAdapter_query.py @@ -0,0 +1,699 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + + +import sys +import os +import subprocess +import random +import inspect +import taos +import requests +import json +import traceback +import simplejson.errors +import math + +from util.log import * +from util.cases import * +from util.sql import * +from util.dnodes import * +from collections import defaultdict + + + +class RestMsgInfo: + def __init__(self, base_url, + port=6041, + api_url="/rest/sql", + header={'Authorization': 'Basic cm9vdDp0YW9zZGF0YQ=='} + ): + self.base_url = base_url + self.port = port + self.api_url = api_url + self.header = header + self.full_url = f"http://{base_url}:{port}{api_url}" + + +class TDTestCase: + def __init__(self): + self.base_url = "127.0.0.1" + self.dbname = "db" + self.precision = "ms" + + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + + def caseDescription(self): + ''' + case1 : specified SQL + case2 : select sql,include stable 、child table and normal table, include correct SQL and invalid SQL \n + case3 : port test \n + case4 : api_url test \n + case5 : base_url test \n + case6 : header test \n + case7 : big data test + ''' + return + + def rest_test_table(self, dbname: str, tbnum: int) -> None : + + tdSql.execute(f"drop database if exists {dbname}") + tdSql.execute(f"create database if not exists {dbname} keep 3650 precision '{self.precision}' ") + tdSql.execute(f"use {dbname}") + + tdSql.execute( + f''' + create stable {dbname}.stb1 ( + ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool, + c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16) + ) + tags( + tag1 int, tag2 float, tag3 timestamp, tag4 binary(16), tag5 double, tag6 bool, + tag7 bigint, tag8 smallint, tag9 tinyint, tag10 nchar(16) + ) + ''' + ) + tdSql.execute( + f"create stable {dbname}.stb2 (ts timestamp, c1 int) tags(ttag1 int)" + ) + for i in range(tbnum): + tdSql.execute( + f''' + create table {dbname}.t{i} using {dbname}.stb1 + tags({i}, {i}, {1639032680000+i*10}, 'binary_{i}',{i},{random.choice([0, 1])}, {i},{i%32767},{i%127},'nchar_{i}') + ''' + ) + tdSql.execute(f"create table {dbname}.tt{i} using {dbname}.stb2 tags({i})") + pass + + def rest_test_data(self, tbnum:int, data_row:int, basetime:int) -> None : + for i in range(tbnum): + for j in range(data_row): + tdSql.execute( + f"insert into t{i} values (" + f"{basetime + (j+1)*10}, {random.randint(-200, -1)}, {random.uniform(200, -1)}, {basetime + random.randint(-200, -1)}, " + f"'binary_{j}', {random.uniform(-200, -1)}, {random.choice([0,1])}, {random.randint(-200,-1)}, " + f"{random.randint(-200, -1)}, {random.randint(-127, -1)}, 'nchar_{j}' )" + ) + tdSql.execute( + f"insert into tt{i} values ( {basetime-(j+1) * 10}, {random.randint(1, 200)} )" + ) + + def check_err_case(self,query_msg: RestMsgInfo, data): + url, header = query_msg.full_url, query_msg.header + try: + conn = requests.post(url=url, data=data, headers=header) + resp_code = conn.status_code + resp = conn.json() + if resp_code != 200: + print(f"expect error occured, url: {url}, sql: {data}, error code is :{resp_code}") + return + status = resp["status"] + desc = resp["desc"] + if resp_code == 200 and status == "error": + print(f"expect error occured, url: {url}, sql: {data}, error is :{desc}") + return + else: + tdLog.exit(f"expect error not occured") + except requests.exceptions.InvalidHeader as e: + tdLog.success(f"expect error occured, request header error, header: {header}, error: {e}") + except requests.exceptions.InvalidURL as e: + tdLog.success(f"expect error occured, request url error, url: {url}, error: {e}") + except requests.exceptions.ConnectionError as e: + tdLog.success(f"expect error occured, request connection error,url: {url}, error: {e}") + except simplejson.errors.JSONDecodeError as e: + tdLog.success(f"expect error occured, request json error,url: {url}, header: {header}, error: {e}") + except Exception as e: + tdLog.success(f"expect error occured, url: {url}, header: {header}, {traceback.print_exc()}") + # finally: + # conn.close() + + pass + + def check_err_sql_case(self,query_msg: RestMsgInfo, data): + url, header = query_msg.full_url, query_msg.header + try: + conn = requests.post(url=url, data=data, headers=header) + resp_code = conn.status_code + resp = conn.json() + status = resp["status"] + desc = resp["desc"] + if resp_code == 200 and status == "error": + tdLog.success(f"expect error occured, url: {url}, sql: {data}, error is :{desc}") + return + else: + tdLog.exit(f"expect error not occured") + except Exception as e: + traceback.print_exc() + raise e + + def check_current_case(self,query_msg: RestMsgInfo, data): + url, header = query_msg.full_url, query_msg.header + conn = requests.post(url=url, data=data, headers=header) + try: + resp_code = conn.status_code + resp = conn.json() + status = resp["status"] + if resp_code == 200 and status == "succ": + tdLog.printNoPrefix(f"restfull run success! url:{url}, sql: {data}") + else: + tdLog.exit(f"restful api test failed, url:{url}, sql: {data}") + except: + tdLog.debug(f"resp_code: {resp_code}, url: {url}") + traceback.print_exc() + raise + pass + + def check_case_res_data(self, query_msg: RestMsgInfo, data): + url, header, api = query_msg.full_url, query_msg.header, query_msg.api_url + try: + ts_col = [] + stb_list = [f"describe {self.dbname}.stb1", f"describe {self.dbname}.stb2"] + for stb in stb_list: + conn = requests.post(url=url, data=stb, headers=header) + resp = conn.json() + for col in resp["data"]: + if "TIMESTAMP" == col[1]: + ts_col.append(col[0]) + + index_dict = defaultdict(int) + conn = requests.post(url=url, data=data, headers=header) + resp = conn.json() + if resp["data"] is None: + return + for index, meta in enumerate(resp["column_meta"]): + if meta[0] in ts_col: + index_dict[meta[0]] = index + if len(index_dict) < 1: + return + + if self.precision == "ms" and (api == "/rest/sql" or api == f"/rest/sql/{self.dbname}"): + for col_name, col_index in index_dict.items(): + for res_data in resp["data"]: + if len(res_data[col_index]) !=23: + print(res_data) + tdLog.exit(f"restful timestamp column err, url:{url}, sql: {data},result is: {res_data[col_index]}") + return + if self.precision == "ms" and (api == "/rest/sqlt" or api == f"/rest/sqlt/{self.dbname}"): + for col_name, col_index in index_dict.items(): + for res_data in resp["data"]: + if not isinstance(res_data[col_index], int) or round(math.log10(res_data[col_index])) != 12: + print(res_data) + tdLog.exit( + f"restful timestamp column err, url:{url}, sql: {data},result is: {res_data[col_index]}" + ) + return + if self.precision == "ms" and (api == "/rest/sqlutc" or api == f"/rest/sqlutc/{self.dbname}"): + for col_name, col_index in index_dict.items(): + for res_data in resp["data"]: + if len(res_data[col_index]) != 29 and len(res_data[col_index]) != 28 and len(res_data[col_index]) != 27 and len(res_data[col_index]) != 25: + print(res_data) + tdLog.exit( + f"restful timestamp column err, url:{url}, sql: {data},result is: {res_data[col_index]}, length is: {len(res_data[col_index])}" + ) + return + if self.precision == "us" and (api == "/rest/sql" or api == f"/rest/sql/{self.dbname}"): + for col_name, col_index in index_dict.items(): + for res_data in resp["data"]: + if len(res_data[col_index]) !=26: + print(res_data) + tdLog.exit(f"restful timestamp column err, url:{url}, sql: {data},result is: {res_data[col_index]}") + return + + if self.precision == "us" and (api == "/rest/sqlt" or api == f"/rest/sqlt/{self.dbname}"): + for col_name, col_index in index_dict.items(): + for res_data in resp["data"]: + if not isinstance(res_data[col_index], int) or round(math.log10(res_data[col_index])) != 15: + print(res_data) + tdLog.exit( + f"restful timestamp column err, url:{url}, sql: {data},result is: {res_data[col_index]}" + ) + return + + if self.precision == "us" and (api == "/rest/sqlutc" or api == f"/rest/sqlutc/{self.dbname}"): + for col_name, col_index in index_dict.items(): + for res_data in resp["data"]: + if len(res_data[col_index]) != 32 and len(res_data[col_index]) != 31 and len(res_data[col_index]) != 30 and len(res_data[col_index]) != 28: + print(res_data) + tdLog.exit( + f"restful timestamp column err, url:{url}, sql: {data},result is: {res_data[col_index]}" + ) + return + if self.precision == "ns" and (api == "/rest/sql" or api == f"/rest/sql/{self.dbname}"): + for col_name, col_index in index_dict.items(): + for res_data in resp["data"]: + if len(res_data[col_index]) !=29: + print(res_data) + tdLog.exit(f"restful timestamp column err, url:{url}, sql: {data},result is: {res_data[col_index]}") + return + + if self.precision == "ns" and (api == "/rest/sqlt" or api == f"/rest/sqlt/{self.dbname}"): + for col_name, col_index in index_dict.items(): + for res_data in resp["data"]: + if not isinstance(res_data[col_index], int) or round(math.log10(res_data[col_index])) != 18: + print(res_data) + tdLog.exit( + f"restful timestamp column err, url:{url}, sql: {data},result is: {res_data[col_index]}" + ) + return + + if self.precision == "ns" and (api == "/rest/sqlutc" or api == f"/rest/sqlutc/{self.dbname}"): + for col_name, col_index in index_dict.items(): + for res_data in resp["data"]: + if len(res_data[col_index]) != 35 and len(res_data[col_index]) != 34 and len(res_data[col_index]) != 33 and len(res_data[col_index]) != 31: + print(res_data) + tdLog.exit( + f"restful timestamp column err, url:{url}, sql: {data},result is: {res_data[col_index]}" + ) + return + + except: + traceback.print_exc() + raise + + pass + + def sql_case_current(self): + case_list = [ + "show databases", + f"show {self.dbname}.stables", + f"show {self.dbname}.tables", + "select server_status()", + "select client_version()", + "select server_version()", + "select database()", + f"show create database {self.dbname}", + f"show create stable {self.dbname}.stb1", + f"select * from {self.dbname}.stb1", + f"select ts from {self.dbname}.stb1", + f"select _c0 from {self.dbname}.stb1", + f"select c1 from {self.dbname}.stb1", + f"select c2 from {self.dbname}.stb1", + f"select c3 from {self.dbname}.stb1", + f"select c4 from {self.dbname}.stb1", + f"select c5 from {self.dbname}.stb1", + f"select c6 from {self.dbname}.stb1", + f"select c7 from {self.dbname}.stb1", + f"select c8 from {self.dbname}.stb1", + f"select c9 from {self.dbname}.stb1", + f"select c10 from {self.dbname}.stb1", + f"select tbname from {self.dbname}.stb1", + f"select tag1 from {self.dbname}.stb1", + f"select tag2 from {self.dbname}.stb1", + f"select tag3 from {self.dbname}.stb1", + f"select tag4 from {self.dbname}.stb1", + f"select tag5 from {self.dbname}.stb1", + f"select tag6 from {self.dbname}.stb1", + f"select tag7 from {self.dbname}.stb1", + f"select tag8 from {self.dbname}.stb1", + f"select tag9 from {self.dbname}.stb1", + f"select tag10 from {self.dbname}.stb1", + f"select count(*) from {self.dbname}.stb1", + f"select count(c1) from {self.dbname}.stb1", + f"select avg(c1) from {self.dbname}.stb1", + f"select twa(c1) from {self.dbname}.stb1 group by tbname", + f"select sum(c1) from {self.dbname}.stb1", + f"select stddev(c1) from {self.dbname}.stb1", + f"select min(c1) from {self.dbname}.stb1", + f"select max(c1) from {self.dbname}.stb1", + f"select first(c1) from {self.dbname}.stb1", + f"select first(*) from {self.dbname}.stb1", + f"select last(c1) from {self.dbname}.stb1", + f"select last(*) from {self.dbname}.stb1", + f"select top(c1, 3) from {self.dbname}.stb1", + f"select bottom(c1, 3) from {self.dbname}.stb1", + f"select apercentile(c1, 50, 't-digest') from {self.dbname}.stb1", + f"select last_row(c1) from {self.dbname}.stb1", + f"select last_row(*) from {self.dbname}.stb1", + f"select interp(c1) from {self.dbname}.stb1 where ts=0 group by tbname", + f"select interp(c1) from {self.dbname}.stb1 where ts=0 fill(next) group by tbname", + f"select interp(c1) from {self.dbname}.stb1 where ts>0 and ts <100000000 every(5s) group by tbname", + f"select diff(c1) from {self.dbname}.stb1 group by tbname", + f"select derivative(c1, 10m, 0) from {self.dbname}.stb1 group by tbname", + f"select derivative(c1, 10m, 1) from {self.dbname}.stb1 group by tbname", + f"select spread(c1) from {self.dbname}.stb1", + f"select ceil(c1) from {self.dbname}.stb1", + f"select floor(c1) from {self.dbname}.stb1", + f"select round(c1) from {self.dbname}.stb1", + f"select c1*2+2%c2-c2/2 from {self.dbname}.stb1", + f"select max(c1) from {self.dbname}.stb1 where ts>'2021-12-05 18:25:41.136' and ts<'2021-12-05 18:25:44.13' interval(1s) sliding(500a) fill(NULL) group by tbname", + f"select max(c1) from {self.dbname}.stb1 where (c1 >=0 and c1 <> 0 and c2 is not null or c1 < -1 or (c2 between 1 and 10) ) and tbname like 't_' ", + f"select max(c1) from {self.dbname}.stb1 group by tbname order by ts desc slimit 2 soffset 2 limit 1 offset 0", + f"select max(c1) from {self.dbname}.stb1 group by c6 order by ts desc slimit 1 soffset 1 limit 1 offset 0 ", + f"select * from {self.dbname}.t1", + f"select ts from {self.dbname}.t1", + f"select _c0 from {self.dbname}.t1", + f"select c1 from {self.dbname}.t1", + f"select c2 from {self.dbname}.t1", + f"select c3 from {self.dbname}.t1", + f"select c4 from {self.dbname}.t1", + f"select c5 from {self.dbname}.t1", + f"select c6 from {self.dbname}.t1", + f"select c7 from {self.dbname}.t1", + f"select c8 from {self.dbname}.t1", + f"select c9 from {self.dbname}.t1", + f"select c10 from {self.dbname}.t1", + f"select tbname from {self.dbname}.t1", + f"select tag1 from {self.dbname}.t1", + f"select tag2 from {self.dbname}.t1", + f"select tag3 from {self.dbname}.t1", + f"select tag4 from {self.dbname}.t1", + f"select tag5 from {self.dbname}.t1", + f"select tag6 from {self.dbname}.t1", + f"select tag7 from {self.dbname}.t1", + f"select tag8 from {self.dbname}.t1", + f"select tag9 from {self.dbname}.t1", + f"select tag10 from {self.dbname}.t1", + f"select count(*) from {self.dbname}.t1", + f"select count(c1) from {self.dbname}.t1", + f"select avg(c1) from {self.dbname}.t1", + f"select twa(c1) from {self.dbname}.t1", + f"select sum(c1) from {self.dbname}.t1", + f"select stddev(c1) from {self.dbname}.t1", + f"select leastsquares(c1, 1, 1) from {self.dbname}.t1", + f"select min(c1) from {self.dbname}.t1", + f"select max(c1) from {self.dbname}.t1", + f"select first(c1) from {self.dbname}.t1", + f"select first(*) from {self.dbname}.t1", + f"select last(c1) from {self.dbname}.t1", + f"select last(*) from {self.dbname}.t1", + f"select top(c1, 3) from {self.dbname}.t1", + f"select bottom(c1, 3) from {self.dbname}.t1", + f"select percentile(c1, 50) from {self.dbname}.t1", + f"select apercentile(c1, 50, 't-digest') from {self.dbname}.t1", + f"select last_row(c1) from {self.dbname}.t1", + f"select last_row(*) from {self.dbname}.t1", + f"select interp(c1) from {self.dbname}.t1 where ts=0 ", + f"select interp(c1) from {self.dbname}.t1 where ts=0 fill(next)", + f"select interp(c1) from {self.dbname}.t1 where ts>0 and ts <100000000 every(5s)", + f"select diff(c1) from {self.dbname}.t1", + f"select derivative(c1, 10m, 0) from {self.dbname}.t1", + f"select derivative(c1, 10m, 1) from {self.dbname}.t1", + f"select spread(c1) from {self.dbname}.t1", + f"select ceil(c1) from {self.dbname}.t1", + f"select floor(c1) from {self.dbname}.t1", + f"select round(c1) from {self.dbname}.t1", + f"select c1*2+2%c2-c2/2 from {self.dbname}.t1", + f"select max(c1) from {self.dbname}.t1 where ts>'2021-12-05 18:25:41.136' and ts<'2021-12-05 18:25:44.13' interval(1s) sliding(500a) fill(NULL)", + f"select max(c1) from {self.dbname}.t1 where (c1 >=0 and c1 <> 0 and c2 is not null or c1 < -1 or (c2 between 1 and 10) ) and c10 like 'nchar___1' ", + f"select max(c1) from {self.dbname}.t1 group by c6 order by ts desc ", + f"select stb1.c1, stb2.c1 from {self.dbname}.stb1 stb1, {self.dbname}.stb2 stb2 where stb1.ts=stb2.ts and stb1.tag1=stb2.ttag1", + f"select t1.c1, t2.c1 from {self.dbname}.t1 t1, {self.dbname}.t2 t2 where t1.ts=t2.ts", + f"select c1 from (select c2 c1 from {self.dbname}.stb1) ", + f"select c1 from {self.dbname}.t1 union all select c1 from {self.dbname}.t2" + ] + return case_list + + def sql_case_err(self): + case_list = [ + "show database", + f"select percentile(c1, 50) from {self.dbname}.stb1 group by tbname", + f"select leastsquares(c1, 1, 1) from {self.dbname}.stb1", + ] + return case_list + + def port_case_current(self): + case_list = [6041] + return case_list + + def port_case_err(self): + case_list = [ + 6030, + 6051, + 666666666, + None, + "abcd" + ] + return case_list + + def api_case_current(self): + case_List = [ + "/rest/sql", + f"/rest/sql/{self.dbname}", + "/rest/sqlt", + f"/rest/sqlt/{self.dbname}", + "/rest/sqlutc", + f"/rest/sqlutc/{self.dbname}" + ] + return case_List + + def api_case_err(self): + case_list = [ + "", + "/rest1/sql", + "/rest/sqlsqltsqlutc", + 1, + ["/rest", "/sql"], + "/influxdb/v1/write", + "/opentsdb/v1/put/json/db", + "/opentsdb/v1/put/telnet/db", + "/rest*", + "*" + ] + return case_list + + def header_case_current(self): + case_list = [ + {'Authorization': 'Basic cm9vdDp0YW9zZGF0YQ=='}, + {'Authorization': 'Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04'} + ] + return case_list + + def header_case_err(self): + case_list = [ + {'Authorization': 'Basic '}, + {'Authorization': 'Taosd /root/taosdata'}, + {'Authorization': True} + ] + return case_list + + def run_case_api_err(self): + err_cases = self.api_case_err() + count = 0 + data = "show databases" + for case in err_cases: + print(f"err api case{count}: ", end="") + query_msg = RestMsgInfo(base_url=self.base_url, api_url=case) + self.check_err_case(query_msg=query_msg, data=data) + count += 1 + pass + + def run_case_port_err(self): + err_cases = self.port_case_err() + count = 0 + data = "show databases" + for case in err_cases: + print(f"err port case{count}: ", end="") + query_msg = RestMsgInfo(base_url=self.base_url, port=case) + self.check_err_case(query_msg=query_msg, data=data) + count += 1 + pass + + def run_case_header_err(self): + err_cases = self.header_case_err() + count = 0 + data = "show databases" + for case in err_cases: + print(f"err header case{count}: ", end="") + query_msg = RestMsgInfo(base_url=self.base_url, header=case) + self.check_err_case(query_msg=query_msg, data=data) + count += 1 + pass + + def run_case_sql_err(self): + err_cases = self.sql_case_err() + count = 0 + for case in err_cases: + print(f"err sql case{count}: ", end="") + query_msg = RestMsgInfo(base_url=self.base_url) + self.check_err_sql_case(query_msg=query_msg, data=case) + count += 1 + pass + + def run_case_port_current(self): + current_cases = self.port_case_current() + count = 0 + data = "show databases" + for case in current_cases: + print(f"current port case{count}: ", end="") + query_msg = RestMsgInfo(base_url=self.base_url, port=case) + self.check_current_case(query_msg=query_msg, data=data) + count += 1 + pass + + def run_case_api_current(self): + current_cases = self.api_case_current() + count = 0 + data = "show databases" + for case in current_cases: + print(f"current api case{count}: ", end="") + query_msg = RestMsgInfo(base_url=self.base_url, api_url=case) + self.check_current_case(query_msg=query_msg, data=data) + count += 1 + pass + + def run_case_header_current(self): + current_cases = self.header_case_current() + count = 0 + data = "show databases" + for case in current_cases: + print(f"current header case{count}: ", end="") + query_msg = RestMsgInfo(base_url=self.base_url, header=case) + self.check_current_case(query_msg=query_msg, data=data) + count += 1 + pass + + def run_case_sql_current(self): + current_cases = self.sql_case_current() + count = 0 + api_cases = self.api_case_current() + for case in current_cases: + print(f"current sql case{count}: ", end="") + for api in api_cases: + query_msg = RestMsgInfo(base_url=self.base_url, api_url=api) + self.check_current_case(query_msg=query_msg, data=case) + self.check_case_res_data(query_msg=query_msg, data=case) + count += 1 + pass + + def run_case_err(self): + self.run_case_api_err() + self.run_case_port_err() + self.run_case_header_err() + self.run_case_sql_err() + pass + + def run_case_current(self): + self.run_case_api_current() + self.run_case_port_current() + self.run_case_header_current() + self.run_case_sql_current() + pass + + def run_all_case(self): + self.run_case_err() + self.run_case_current() + pass + + def set_default_args(self): + nowtime = int(round(time.time() * 1000)) + url = "127.0.0.1" + per_table_rows = 100 + tbnum = 10 + database_name = "db" + precision ="ms" + clear_data = True + config_default = { + "base_url" : url, + "precision" : precision, + "clear_data" : clear_data, + "database_name": database_name, + "tbnum" : tbnum, + "data_row" : per_table_rows, + "basetime" : nowtime, + "all_case" : False, + "all_err" : False, + "all_current" : True, + "err_case" : { + "port_err" : True, + "api_err" : True, + "header_err" : True, + "sql_err" : True, + }, + "current_case" : { + "port_current" : True, + "api_current" : True, + "header_current" : True, + "sql_current" : True, + } + } + + config_file_name = f"{os.path.dirname(os.path.abspath(__file__))}/rest_query_config.json" + with open(config_file_name, "w") as f: + json.dump(config_default, f) + return config_file_name + + def run(self): + config_file = f"{os.path.dirname(os.path.abspath(__file__))}/rest_query_config.json" + if not os.path.isfile(config_file): + config_file = self.set_default_args() + + with open(config_file, "r", encoding="utf-8") as f: + cfg = json.load(f) + + tbnum = cfg["tbnum"] + data_row = cfg["data_row"] + basetime = cfg["basetime"] + self.dbname = cfg["database_name"] + self.base_url = cfg["base_url"] + self.precision = cfg["precision"] + clear_data = True if cfg["clear_data"] else False + + if clear_data: + self.rest_test_table(dbname=self.dbname, tbnum=tbnum) + self.rest_test_data(tbnum=tbnum, data_row=data_row, basetime=basetime) + + run_all_case = True if cfg["all_case"] else False + run_all_err_case = True if cfg["all_err"] else False + run_all_current_case = True if cfg["all_current"] else False + run_port_err_case = True if cfg["err_case"]["port_err"] else False + run_api_err_case = True if cfg["err_case"]["api_err"] else False + run_header_err_case = True if cfg["err_case"]["header_err"] else False + run_sql_err_case = True if cfg["err_case"]["sql_err"] else False + run_port_current_case = True if cfg["current_case"]["port_current"] else False + run_api_current_case = True if cfg["current_case"]["api_current"] else False + run_header_current_case = True if cfg["current_case"]["header_current"] else False + run_sql_current_case = True if cfg["current_case"]["sql_current"] else False + + if not (run_all_err_case | run_all_current_case | run_port_err_case | run_api_err_case | + run_header_err_case | run_sql_err_case | run_port_current_case | run_api_current_case + | run_header_current_case | run_sql_current_case): + run_all_case = True + if run_all_err_case & run_all_current_case: + run_all_case = True + + if run_all_case: + self.run_all_case() + return + if run_all_err_case : + self.run_case_err() + return + if run_all_current_case: + self.run_case_current() + return + if run_port_err_case: + self.run_case_port_err() + if run_api_err_case: + self.run_case_api_err() + if run_header_err_case: + self.run_case_header_err() + if run_sql_err_case: + self.run_case_sql_err() + if run_port_current_case: + self.run_case_port_current() + if run_api_current_case: + self.run_case_api_current() + if run_header_current_case: + self.run_case_header_current() + if run_sql_current_case: + self.run_case_sql_current() + pass + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/system-test/fulltest.sh b/tests/system-test/fulltest.sh index d2fea19cb537e4cc196b06998059bcbf328d09a8..f9644fa1c867b028cdf038067322374aaf7832fc 100755 --- a/tests/system-test/fulltest.sh +++ b/tests/system-test/fulltest.sh @@ -1,4 +1,5 @@ -python3 test.py -f 1-insert/0-sql/basic.py python3 test.py -f 0-management/1-stable/create_col_tag.py +python3 test.py -f 4-taosAdapter/taosAdapter_query.py +python3 test.py -f 4-taosAdapter/taosAdapter_insert.py -#python3 test.py -f 2-query/9-others/TD-11389.py # this case will run when this bug fix TD-11389 \ No newline at end of file +#python3 test.py -f 2-query/9-others/TD-11389.py # this case will run when this bug fix TD-11389