Skip to content

Commit

Permalink
feat: release for v0.1.14. (#8)
Browse files Browse the repository at this point in the history
Main feature includes:
  - Update license for v0.1.14.
  - Fix warnings, update README & some scripts.
  - Reduce lock holding time.
  • Loading branch information
hustclf authored Dec 13, 2021
1 parent 8257295 commit 31e02db
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 29 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 6 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand Down Expand Up @@ -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:
Expand Down
42 changes: 34 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion install/build.bat
Original file line number Diff line number Diff line change
@@ -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
cargo build --release --target i686-pc-windows-msvc
copy /Y target\i686-pc-windows-msvc\release\tat_agent.exe install\tat_agent.exe
3 changes: 2 additions & 1 deletion install/release.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 14 additions & 6 deletions install/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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}
Expand Down
1 change: 1 addition & 0 deletions install/stop.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sc stop tatsvc
12 changes: 6 additions & 6 deletions src/common/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};
}

Expand Down
6 changes: 6 additions & 0 deletions src/http/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(|_| {
Expand Down

0 comments on commit 31e02db

Please sign in to comment.