a little improve

main
AhFei 2023-11-22 00:28:23 +08:00
parent 2bf749b955
commit 3749e5d7e7
1 changed files with 21 additions and 21 deletions

View File

@ -1,16 +1,15 @@
#!/bin/bash
# set rust_serverstatus
# set up rust_serverstatus and
set -ex
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
apt-get install -y curl wget unzip
apt-get install -y curl unzip
# get_architecture
arch=$(uname -m)
# 设置 ARCHITECTURE 变量
if [[ $arch == "aarch64" ]]; then
ARCHITECTURE="arm64"
@ -23,26 +22,28 @@ fi
# step 0: prepare
OS_ARCH=$ARCHITECTURE
WORKSPACE=${1}
passwd=${2}
uid=${3}
server_address=${4}
user_name=${5}
test_or_not=${6}
WORKDIR=${1} # 安装目录
ssr_uid=${2} # rust_serverstatus 配置文件里用户名对应的密码
passwd=${3} # rust_serverstatus 配置文件里的用户名
server_address=${4} # rust_serverstatus 服务端网址
user_name=${5} # 本机运行这个 rust_serverstatus 的用户
install_server_or_not=${6} # 空着就不安装服务端
mkdir -p ${WORKSPACE}
cd ${WORKSPACE}
mkdir -p ${WORKDIR}
cd ${WORKDIR}
latest_version=$(curl -m 10 -sL "https://api.github.com/repos/zdz/ServerStatus-Rust/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g')
github_project="zdz/ServerStatus-Rust"
tag=$(curl -m 10 -sL "https://api.github.com/repos/$github_project/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g')
# step 1: 下载和解压客户端
wget --no-check-certificate -qO "client-${OS_ARCH}-unknown-linux-musl.zip" "https://github.com/zdz/ServerStatus-Rust/releases/download/${latest_version}/client-${OS_ARCH}-unknown-linux-musl.zip"
curl -L -O https://github.com/zdz/ServerStatus-Rust/releases/download/${tag}/client-${OS_ARCH}-unknown-linux-musl.zip
unzip -o "client-${OS_ARCH}-unknown-linux-musl.zip"
rm "client-${OS_ARCH}-unknown-linux-musl.zip"
# client systemd service
cat > /etc/systemd/system/stat_client.service <<EOF
# /etc/systemd/system/stat_client.service
[Unit]
Description=ServerStatus-Rust Client
After=network.target
@ -51,16 +52,15 @@ After=network.target
User=${user_name}
Group=${user_name}
Environment="RUST_BACKTRACE=1"
WorkingDirectory=${WORKSPACE}
WorkingDirectory=${WORKDIR}
# EnvironmentFile=~/myserve/serverstatus/.env
ExecStart=${WORKSPACE}/stat_client -a "${server_address}" -u ${uid} -p ${passwd}
ExecStart=${WORKDIR}/stat_client -a "${server_address}" -u ${ssr_uid} -p ${passwd}
ExecReload=/bin/kill -HUP \$MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
# /etc/systemd/system/stat_client.service
# journalctl -u stat_client -f -n 100
EOF
@ -70,17 +70,18 @@ systemctl status stat_client
# 判断是否部署服务端,不部署就直接退出
if [[ -z ${test_or_not} ]]; then
if [[ -z ${install_server_or_not} ]]; then
exit 1
fi
# 下载和解压服务端
wget --no-check-certificate -qO "server-${OS_ARCH}-unknown-linux-musl.zip" "https://github.com/zdz/ServerStatus-Rust/releases/download/${latest_version}/server-${OS_ARCH}-unknown-linux-musl.zip"
curl -L -O https://github.com/zdz/ServerStatus-Rust/releases/download/${tag}/server-${OS_ARCH}-unknown-linux-musl.zip
unzip -o "server-${OS_ARCH}-unknown-linux-musl.zip"
rm "server-${OS_ARCH}-unknown-linux-musl.zip"
# server systemd service
cat > /etc/systemd/system/stat_server.service <<EOF
# /etc/systemd/system/stat_server.service
[Unit]
Description=ServerStatus-Rust Server
After=network.target
@ -89,15 +90,14 @@ After=network.target
User=${user_name}
Group=${user_name}
Environment="RUST_BACKTRACE=1"
WorkingDirectory=${WORKSPACE}
ExecStart=${WORKSPACE}/stat_server -c ${WORKSPACE}/config.toml
WorkingDirectory=${WORKDIR}
ExecStart=${WORKDIR}/stat_server -c ${WORKDIR}/config.toml
ExecReload=/bin/kill -HUP \$MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
# /etc/systemd/system/stat_server.service
EOF