更新 'one-touch.sh'

可选是否安装服务端,等等
main
AhFei 2023-06-08 19:48:29 +08:00
parent c97f9b0227
commit acf29b3eec
1 changed files with 74 additions and 15 deletions

View File

@ -1,30 +1,89 @@
#!/bin/bash #!/bin/bash
set -ex # set rust_serverstatus
set -ex
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
# step 0: prepare
OS_ARCH=${1}
WORKSPACE=${2}
passwd=${3}
uid=${4}
server_address=${5}
test_or_not=${6}
WORKSPACE=~/myserve/serverstatus
mkdir -p ${WORKSPACE} mkdir -p ${WORKSPACE}
cd ${WORKSPACE} cd ${WORKSPACE}
# 下载, arm 机器替换 x86_64 为 aarch64
OS_ARCH="x86_64"
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') 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')
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"
# 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" 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 "server-${OS_ARCH}-unknown-linux-musl.zip"
unzip -o "client-${OS_ARCH}-unknown-linux-musl.zip" unzip -o "client-${OS_ARCH}-unknown-linux-musl.zip"
# systemd service # client systemd service
mv -v stat_server.service /etc/systemd/system/stat_server.service cat > /etc/systemd/system/stat_client.service <<EOF
mv -v stat_client.service /etc/systemd/system/stat_client.service [Unit]
Description=ServerStatus-Rust Client
After=network.target
[Service]
User=1000
Group=1000
Environment="RUST_BACKTRACE=1"
WorkingDirectory=${WORKSPACE}
# EnvironmentFile=~/myserve/serverstatus/.env
ExecStart=${WORKSPACE}/stat_client -a "${server_address}" -u ${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
systemctl daemon-reload systemctl daemon-reload
systemctl enable --now stat_client
systemctl status stat_client
# 启动
systemctl start stat_server
systemctl start stat_client
# 状态查看 # 判断是否部署服务端,不部署就直接退出
systemctl status stat_server if [[ -z ${test_or_not} ]]; then
systemctl status stat_client 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"
# server systemd service
cat > /etc/systemd/system/stat_server.service <<EOF
[Unit]
Description=ServerStatus-Rust Server
After=network.target
[Service]
User=1000
Group=1000
Environment="RUST_BACKTRACE=1"
WorkingDirectory=${WORKSPACE}
ExecStart=${WORKSPACE}/stat_server -c ${WORKSPACE}/config.toml
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