From 31e02db3bfaad0b2d9f0fcc9b58fc6d227b05476 Mon Sep 17 00:00:00 2001 From: Lifei Chen Date: Mon, 13 Dec 2021 15:34:58 +0800 Subject: [PATCH] feat: release for v0.1.14. (#8) Main feature includes: - Update license for v0.1.14. - Fix warnings, update README & some scripts. - Reduce lock holding time. --- .gitignore | 3 +++ CHANGELOG.md | 7 +++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- Makefile | 11 ++++++----- README.md | 42 ++++++++++++++++++++++++++++++++++-------- install/build.bat | 3 ++- install/release.bat | 3 ++- install/release.sh | 20 ++++++++++++++------ install/stop.bat | 1 + src/common/consts.rs | 12 ++++++------ src/http/thread.rs | 6 ++++++ 12 files changed, 83 insertions(+), 29 deletions(-) create mode 100644 install/stop.bat diff --git a/.gitignore b/.gitignore index ed53866..bff0853 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,10 @@ .idea/ log install/tat_agent +install/tat_agent32 +install/tat_agent64 tat_agent +tat_agent32 install/tat_agent_*.zip install/tat_agent_*.tar.gz install/tat_agent_*install* diff --git a/CHANGELOG.md b/CHANGELOG.md index 596a1d7..f5df41f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ # Changelog All notable changes to this project will be documented in this file. +## [0.1.14] - 2021-12-02 + +### Changed + +- Reduce lock holding time. +- Fix macro warnings. +- Optimize documents. ## [0.1.13] - 2021-11-18 diff --git a/Cargo.lock b/Cargo.lock index e9398da..4a0e311 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2427,7 +2427,7 @@ dependencies = [ [[package]] name = "tat_agent" -version = "0.1.13" +version = "0.1.14" dependencies = [ "async-attributes", "async-std", diff --git a/Cargo.toml b/Cargo.toml index d964f2f..cb3dc01 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tat_agent" -version = "0.1.13" +version = "0.1.14" edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/Makefile b/Makefile index ba4371e..e2b9ced 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ $(info "cross not found, install it now.") $(shell cargo install cross) endif -# build a pure static binary +# build a pure static binary in debug mode static: ifeq ($(rust_target), ) $(error `$(arch)` not exists or not supported yet.) @@ -59,13 +59,14 @@ endif ln -f target/i686-unknown-linux-musl/release/tat_agent tat_agent32 install/release.sh -# stop the daemon by pid +# stop the daemon via systemctl, or kill directly by pid stop: - kill -9 `cat /var/run/tat_agent.pid` + systemctl stop tat_agent || kill -9 `cat /var/run/tat_agent.pid` -# run a binary for debugging +# build via make release and then install it run: - cargo run + make release + install/install.sh # build a pure static binary for debugging build: diff --git a/README.md b/README.md index 10d1521..d74a37b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ [简体中文](./README-ZH.md) | English # TAT Agent -TAT agent is an agent written in Rust, which run in CVM or Lighthouse instances. + +TAT agent is an agent written in Rust, which run in CVM, Lighthouse or CPM 2.0 instances. Its role is to run commands remotely without ssh login, invoked from TencentCloud Console/API. Commands include but not limited to: shell, python, php, you can provide any script interpreter at first line, such as: #!/bin/bash, #!/usr/bin/env python3.8. @@ -13,31 +14,56 @@ See more info at https://cloud.tencent.com/product/tat . - Rust environment, such as cargo, rustc, rustup. See more info at https://www.rust-lang.org/learn/get-started . - Docker, some binary need to be compiled in docker. -## run ``` -make run +# some dependencies +yum install -y gcc docker +# install Rust +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh +# reload your PATH environment variable to include Cargo +source $HOME/.cargo/env +# add target +rustup target add x86_64-unknown-linux-musl +rustup target add i686-unknown-linux-musl +# start docker daemon +systemctl start docker +# install tool to cross-compile Rust +cargo install cross ``` -Run directly by cargo in debug mode with the test domain. -## build + +## build & install + + - Linux ``` -make release # on linux +make run ``` Build a pure static binary in release mode with the real domain, need docker installed. + + - Windows ``` -.\install\build.bat # on windows +.\install\build.bat +.\install\install.bat ``` ## stop + + - Linux ``` make stop ``` -Stop the daemon by pid which was written in a pidfile. +Stop the daemon via systemctl, or kill by pid which was written in a pidfile. + + - Windows +``` +.\install\stop.bat +``` ## other + See more details at Makefile. ## supported OS + Binary can run at both Linux & Windows Distributions, including but not limited to: - Tencent Linux - CentOS diff --git a/install/build.bat b/install/build.bat index be88b0e..94fef02 100644 --- a/install/build.bat +++ b/install/build.bat @@ -1,3 +1,4 @@ SET RUSTFLAGS=-C target-feature=+crt-static rustup target add i686-pc-windows-msvc -cargo build --release --target i686-pc-windows-msvc \ No newline at end of file +cargo build --release --target i686-pc-windows-msvc +copy /Y target\i686-pc-windows-msvc\release\tat_agent.exe install\tat_agent.exe \ No newline at end of file diff --git a/install/release.bat b/install/release.bat index 4731693..5bdc9ea 100644 --- a/install/release.bat +++ b/install/release.bat @@ -12,7 +12,8 @@ if not exist "C:\Program Files\7-Zip\7z.exe" ( set COMPRESS_PROC="C:\Program Files\7-Zip\7z.exe" :: generate self update file for release -SET FILE="tat_agent_windows_update_%VERSION%.zip" +:: .zip file is used for self-update but can also be used to install agent +SET FILE="tat_agent_windows_install_%VERSION%.zip" %COMPRESS_PROC% a %FILE% %SIGNED_AGENT% install.bat uninstall.bat self_update.bat test.bat :: generate install file for release diff --git a/install/release.sh b/install/release.sh index 409dd0a..8de779a 100755 --- a/install/release.sh +++ b/install/release.sh @@ -3,7 +3,10 @@ cd `dirname $0` ARCH=$1 TAT_AGENT="tat_agent" TAT_AGENT_32="tat_agent32" +TAT_AGENT_64="tat_agent64" ln -f ../${TAT_AGENT} ../${TAT_AGENT_32} . +# save to 64 +cp -f ${TAT_AGENT} ${TAT_AGENT_64} VERSION=`./${TAT_AGENT} --version | awk '{print $2}'` if [ -z "${VERSION}" ]; then @@ -17,7 +20,7 @@ INSTALL_FILE=${TAT_AGENT}_linux_install_${VERSION}${FILE_SUFFIX} UNINSTALL_FILE=${TAT_AGENT}_linux_uninstall_${VERSION}${FILE_SUFFIX} # clean old files. -rm -rf "${INSTALL_FILE}" "${UNINSTALL_FILE}" "${UPDATE_FILE}" "${UPDATE_FILE_32}" +rm -rf "${INSTALL_FILE}" "${UNINSTALL_FILE}" # NOTE: mac tar do not support `--transform`, use gtar instead. # generate install file for release @@ -28,20 +31,25 @@ tat_agent.service tat_agent_service.conf --transform "s,^,${TAT_AGENT}_linux_ins tar czf "${UNINSTALL_FILE}" uninstall.sh test.sh --transform "s,^,${TAT_AGENT}_linux_uninstall_${VERSION}/," # generate self update file for release (64bit) +# .zip file is used for self-update but can also be used to install agent ARCH=x86_64 -UPDATE_FILE="${TAT_AGENT}_linux_update_${ARCH}_${VERSION}.zip" +UPDATE_FILE="${TAT_AGENT}_linux_install_${ARCH}_${VERSION}.zip" +rm -rf "${UPDATE_FILE}" zip "${UPDATE_FILE}" install.sh ${TAT_AGENT} uninstall.sh tat_agent_service tat_agent.service tat_agent_service.conf \ self_update.sh # generate self update file for release (32bit) +# .zip file is used for self-update but can also be used to install agent ARCH=i686 -UPDATE_FILE_32="${TAT_AGENT}_linux_update_${ARCH}_${VERSION}.zip" +UPDATE_FILE_32="${TAT_AGENT}_linux_install_${ARCH}_${VERSION}.zip" +rm -rf "${UPDATE_FILE_32}" # rename tat_agent_32 to tat_agent. -mv -f ${TAT_AGENT_32} ${TAT_AGENT} +cp -f ${TAT_AGENT_32} ${TAT_AGENT} zip "${UPDATE_FILE_32}" install.sh ${TAT_AGENT} uninstall.sh tat_agent_service tat_agent.service tat_agent_service.conf self_update.sh -# clean -rm -rf ${TAT_AGENT} ${TAT_AGENT_32} +# restore 64bit as default +cp -f ${TAT_AGENT_64} ${TAT_AGENT} + echo "release file generated: ${INSTALL_FILE} ${UNINSTALL_FILE} diff --git a/install/stop.bat b/install/stop.bat new file mode 100644 index 0000000..1f676fe --- /dev/null +++ b/install/stop.bat @@ -0,0 +1 @@ +sc stop tatsvc \ No newline at end of file diff --git a/src/common/consts.rs b/src/common/consts.rs index b47fb32..20b5d27 100644 --- a/src/common/consts.rs +++ b/src/common/consts.rs @@ -78,25 +78,25 @@ pub const AGENT_VERSION: &str = env!("CARGO_PKG_VERSION"); #[macro_export] macro_rules! start_failed_err_info { (ERR_WORKING_DIRECTORY_NOT_EXISTS, $working_directory:expr) => { - format!("DirectoryNotExists: working_directory `{}` not exists", $working_directory); + format!("DirectoryNotExists: working_directory `{}` not exists", $working_directory) }; (ERR_USER_NOT_EXISTS, $user:expr) => { - format!("UserNotExists: user `{}` not exists", $user); + format!("UserNotExists: user `{}` not exists", $user) }; (ERR_USER_NO_PERMISSION_OF_WORKING_DIRECTORY, $user:expr, $working_directory:expr) => { format!("DirectoryPermissionDeny: user `{}` has no permission of working_directory `{}`", - $user, $working_directory); + $user, $working_directory) }; (ERR_SUDO_NOT_EXISTS) => { - format!("SudoNotExists: command sudo not exists"); + format!("SudoNotExists: command sudo not exists") }; (ERR_SCRIPT_FILE_STORE_FAILED, $store_path:expr) => { format!("ScriptStoreFailed: script file store failed at `{}`, please check disk space or permission", - $store_path); + $store_path) }; (ERR_LOG_FILE_STORE_FAILED, $store_path:expr) => { format!("LogStoreFailed: log file store failed at `{}`, please check disk space or permission", - $store_path); + $store_path) }; } diff --git a/src/http/thread.rs b/src/http/thread.rs index 149cf82..46f5653 100644 --- a/src/http/thread.rs +++ b/src/http/thread.rs @@ -214,6 +214,9 @@ impl HttpWorker { let finish_time = cmd.finish_time(); let output_url = cmd.output_url(); let output_err_info = cmd.output_err_info(); + //remove lock, important + std::mem::drop(cmd); + self.adapter .report_task_finish( &task_id, @@ -249,6 +252,9 @@ impl HttpWorker { let tasks = self.running_tasks.lock().await; let task = tasks.get(cancel_task_id.as_str()); if let Some(cmd_arc) = task { + let cmd_arc = cmd_arc.clone(); + //drop lock + std::mem::drop(tasks); let cmd = cmd_arc.lock().await; cmd.cancel() .map(|_| {