Rust_ServerStatus/one-touch.sh

106 lines
2.6 KiB
Bash
Raw Normal View History

2023-06-08 16:51:24 +08:00
#!/bin/bash
# set rust_serverstatus
2023-06-08 16:51:24 +08:00
set -ex
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
2023-09-08 20:31:12 +08:00
apt-get install -y curl wget unzip
# get_architecture
arch=$(uname -m)
# 设置 ARCHITECTURE 变量
if [[ $arch == "aarch64" ]]; then
ARCHITECTURE="arm64"
elif [[ $arch == "x86_64" ]]; then
ARCHITECTURE="x86_64"
else
ARCHITECTURE="unknown"
fi
# step 0: prepare
2023-09-08 20:31:12 +08:00
OS_ARCH=$ARCHITECTURE
WORKSPACE=${1}
passwd=${2}
uid=${3}
server_address=${4}
user_name=${5}
test_or_not=${6}
2023-06-08 16:51:24 +08:00
mkdir -p ${WORKSPACE}
cd ${WORKSPACE}
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')
# step 1: 下载和解压客户端
2023-06-08 16:51:24 +08:00
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"
unzip -o "client-${OS_ARCH}-unknown-linux-musl.zip"
2023-06-08 19:59:00 +08:00
rm "client-${OS_ARCH}-unknown-linux-musl.zip"
2023-06-08 16:51:24 +08:00
# client systemd service
cat > /etc/systemd/system/stat_client.service <<EOF
[Unit]
Description=ServerStatus-Rust Client
After=network.target
[Service]
User=${user_name}
Group=${user_name}
Environment="RUST_BACKTRACE=1"
WorkingDirectory=${WORKSPACE}
# EnvironmentFile=~/myserve/serverstatus/.env
ExecStart=${WORKSPACE}/stat_client -a "${server_address}" -u ${uid} -p ${passwd}
2023-08-18 01:04:52 +08:00
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
2023-06-08 16:51:24 +08:00
systemctl daemon-reload
systemctl enable --now stat_client
systemctl status stat_client
2023-06-08 16:51:24 +08:00
# 判断是否部署服务端,不部署就直接退出
if [[ -z ${test_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"
unzip -o "server-${OS_ARCH}-unknown-linux-musl.zip"
2023-06-08 19:59:00 +08:00
rm "server-${OS_ARCH}-unknown-linux-musl.zip"
# server systemd service
cat > /etc/systemd/system/stat_server.service <<EOF
[Unit]
Description=ServerStatus-Rust Server
After=network.target
[Service]
User=${user_name}
Group=${user_name}
Environment="RUST_BACKTRACE=1"
WorkingDirectory=${WORKSPACE}
ExecStart=${WORKSPACE}/stat_server -c ${WORKSPACE}/config.toml
2023-08-18 01:04:52 +08:00
ExecReload=/bin/kill -HUP \$MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
# /etc/systemd/system/stat_server.service
EOF
systemctl daemon-reload
systemctl enable --now stat_server
systemctl status stat_server