parent
c97f9b0227
commit
acf29b3eec
91
one-touch.sh
91
one-touch.sh
|
@ -1,30 +1,89 @@
|
|||
#!/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}
|
||||
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')
|
||||
|
||||
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"
|
||||
|
||||
unzip -o "server-${OS_ARCH}-unknown-linux-musl.zip"
|
||||
unzip -o "client-${OS_ARCH}-unknown-linux-musl.zip"
|
||||
|
||||
# systemd service
|
||||
mv -v stat_server.service /etc/systemd/system/stat_server.service
|
||||
mv -v stat_client.service /etc/systemd/system/stat_client.service
|
||||
# client systemd service
|
||||
cat > /etc/systemd/system/stat_client.service <<EOF
|
||||
[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 start stat_server
|
||||
systemctl start stat_client
|
||||
|
||||
# 状态查看
|
||||
systemctl status stat_server
|
||||
systemctl enable --now stat_client
|
||||
systemctl status stat_client
|
||||
|
||||
|
||||
# 判断是否部署服务端,不部署就直接退出
|
||||
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"
|
||||
|
||||
# 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
|
Loading…
Reference in New Issue