Compare commits

..

No commits in common. "22feee38eeb678f9f81822937d341a6ad39b50c7" and "c271378c712d4e05051280a93725be29f522ad8c" have entirely different histories.

4 changed files with 64 additions and 164 deletions

21
LICENSE
View File

@ -1,21 +0,0 @@
MIT License
Copyright (c) 2024 Snowykami
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -19,39 +19,30 @@ _✨ 服务器状态 - 客户端 ✨_
服务器状态的客户端命令行工具 服务器状态的客户端命令行工具
- 跨平台支持
- 自动上报服务器状态
- 支持自定义标签、地域、链接等信息
## 💿 安装 ## 💿 安装
- 先决条件:`curl` `python3` `pip` `venv` `git`
- Linux 可使用脚本安装,带自动部署和自启动 - Linux 可使用脚本安装,带自动部署和自启动
```shell ```shell
sudo bash -c "$(curl -sSL https://raw.githubusercontent.com/snowykami/server-status-client/refs/heads/main/deploy.sh)" curl -sSL https://raw.githubusercontent.com/snowykami/server-status-client/refs/heads/main/deploy.sh | sudo bash
``` ```
如果位于中国大陆,可使用国内镜像
```shell
sudo bash -c "$(curl -sSL https://git.liteyuki.icu/snowykami/server-status-client/raw/branch/main/deploy-cn.sh)"
```
- 或手动部署 - 或手动部署
```shell ```shell
# 克隆仓库 # 克隆仓库
git clone https://github.com/snowykami/server-status-client git clone https://github.com/snowykami/server-status-client
cd server-status-client cd server-status-client
# 配置环境 # 配置环境
python3 -m venv venv python3 -m venv venv
source venv/bin/activate source venv/bin/activate
# 安装依赖 # 安装依赖
pip install pdm pip install pdm
pdm install pdm install
# 如需自启动请自行添加到系统服务 # 如需自启动请自行添加到系统服务
``` ```
## 🎉 使用 ## 🎉 使用
@ -78,13 +69,40 @@ server_status https://status.liteyuki.icu 114514 myhost run -n "MyHost" --labels
### 开机启动 ### 开机启动
- 安装脚本已自动添加到系统服务 执行以下命令
```shell
sudo pipx ensurepath # 确保pipx路径在环境变量下
sudo touch /etc/systemd/system/server-status-client.service
sudo bash -c 'cat <<EOF > /etc/systemd/system/server-status-client.service
[Unit]
Description=Server Status Client
After=network-online.target
[Service]
Type=simple
ExecStart=server-status <server> <token> <id> run # 请替换为实际参数
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF'
sudo systemctl enable server-status-client
sudo systemctl start server-status-client
```
### 更新 ### 更新
```shell ```shell
git pull git pull
sudo systemctl restart server-status-client sudo systemctl restart server-status-client
#
git pull
systemctl restart server-status-client
``` ```
### 服务端 ### 服务端

View File

@ -1,100 +0,0 @@
#!/bin/bash
# 部署脚本中国大陆可用版本
# check if sudo is used
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit 1
fi
# check install dir
install_dir="/opt"
echo -n "Install directory? (default: $install_dir/server-status-client): " && read -r install_dir_input
if [ -n "$install_dir_input" ]; then
install_dir="$install_dir_input"
fi
# check server
echo -n "Server? (required): " && read -r server
if [ -z "$server" ]; then
echo "Server is required"
exit 1
fi
# check token
echo -n "Token? (required): " && read -r token
if [ -z "$token" ]; then
echo "Token is required"
exit 1
fi
# check hostname
hostname=$(hostname)
echo -n "Hostname? (default: $hostname): " && read -r hostname_input
if [ -n "$hostname_input" ]; then
hostname="$hostname_input"
fi
# labels
echo -n "Labels? (space separated): " && read -r labels_input
if [ -n "$labels_input" ]; then
labels="$labels_input"
fi
# location
echo -n "Location? (optional): " && read -r location_input
if [ -n "$location_input" ]; then
location="$location_input"
fi
repo2="https://git.liteyuki.icu/snowykami/server-status-client"
# try 1 if failed try 2
git clone "$repo2" "$install_dir/server-status-client"
cd "$install_dir/server-status-client" || { echo "Failed to clone repo"; exit 1; }
# create venv
python3 -m venv venv
python_exe="./venv/bin/python"
# check if venv is created
if [ ! -f "$python_exe" ]; then
echo "Failed to create venv"
exit 1
fi
echo "venv created successfully"
# install the required packages
echo "Installing the required packages"
$python_exe -m pip install pdm -i https://pypi.tuna.tsinghua.edu.cn/simple
$python_exe -m pdm install
# create the systemd service
echo "Creating the systemd service"
# generate random id
# shellcheck disable=SC2002
id=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
bash -c "cat <<EOF > /etc/systemd/system/server-status-client.service
[Unit]
Description=Server Status Client
After=network-online.target
[Service]
Type=simple
ExecStart=$install_dir/server-status-client/venv/bin/python main.py $server $token $id run -n $hostname --labels $labels --location $location
WorkingDirectory=$install_dir/server-status-client
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF"
# enable and start the service
systemctl enable server-status-client
systemctl start server-status-client
echo "server-status-client installed successfully"

View File

@ -64,6 +64,9 @@ if [ ! -f "$python_exe" ]; then
fi fi
echo "venv created successfully" echo "venv created successfully"
# activate the virtual environment
# install the required packages # install the required packages
echo "Installing the required packages" echo "Installing the required packages"
$python_exe -m pip install pdm $python_exe -m pip install pdm
@ -76,21 +79,21 @@ echo "Creating the systemd service"
# shellcheck disable=SC2002 # shellcheck disable=SC2002
id=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) id=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
bash -c "cat <<EOF > /etc/systemd/system/server-status-client.service #bash -c "cat <<EOF > /etc/systemd/system/server-status-client.service
[Unit] #[Unit]
Description=Server Status Client #Description=Server Status Client
After=network-online.target #After=network-online.target
#
[Service] #[Service]
Type=simple #Type=simple
ExecStart=$install_dir/server-status-client/venv/bin/python main.py $server $token $id run -n $hostname --labels $labels --location $location #ExecStart=$install_dir/server-status-client/venv/bin/python main.py $server $token $id run -n $hostname --labels $labels --location $location
WorkingDirectory=$install_dir/server-status-client #WorkingDirectory=$install_dir/server-status-client
Restart=on-failure #Restart=on-failure
RestartSec=10 #RestartSec=10
#
[Install] #[Install]
WantedBy=multi-user.target #WantedBy=multi-user.target
EOF" #EOF"
# enable and start the service # enable and start the service
systemctl enable server-status-client systemctl enable server-status-client