Compare commits

...

8 Commits

Author SHA1 Message Date
22feee38ee 修复脚本执行错误
Some checks failed
Compile / build (x64, windows-latest) (push) Failing after 13s
Compile / build (x64, ubuntu-latest) (push) Failing after 3m6s
2024-10-05 22:50:41 +08:00
e0aa6adbeb 修复脚本执行错误 2024-10-05 22:48:40 +08:00
87859a58f8 修复脚本执行错误 2024-10-05 22:46:31 +08:00
d1098cf735 Merge remote-tracking branch 'origin/main' 2024-10-05 22:25:32 +08:00
62096e5f4d 修复脚本执行错误 2024-10-05 22:25:17 +08:00
26db6fe7d0
Create LICENSE 2024-10-05 22:04:50 +08:00
3b09c0650d 修复脚本执行错误 2024-10-05 22:02:53 +08:00
fb7e3144d3 修复脚本执行错误 2024-10-05 21:57:48 +08:00
4 changed files with 164 additions and 64 deletions

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
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,30 +19,39 @@ _✨ 服务器状态 - 客户端 ✨_
服务器状态的客户端命令行工具
- 跨平台支持
- 自动上报服务器状态
- 支持自定义标签、地域、链接等信息
## 💿 安装
- 先决条件:`curl` `python3` `pip` `venv` `git`
- Linux 可使用脚本安装,带自动部署和自启动
```shell
curl -sSL https://raw.githubusercontent.com/snowykami/server-status-client/refs/heads/main/deploy.sh | sudo bash
```
```shell
sudo bash -c "$(curl -sSL https://raw.githubusercontent.com/snowykami/server-status-client/refs/heads/main/deploy.sh)"
```
如果位于中国大陆,可使用国内镜像
```shell
sudo bash -c "$(curl -sSL https://git.liteyuki.icu/snowykami/server-status-client/raw/branch/main/deploy-cn.sh)"
```
- 或手动部署
```shell
# 克隆仓库
git clone https://github.com/snowykami/server-status-client
cd server-status-client
# 配置环境
python3 -m venv venv
source venv/bin/activate
# 安装依赖
pip install pdm
pdm install
# 如需自启动请自行添加到系统服务
```
```shell
# 克隆仓库
git clone https://github.com/snowykami/server-status-client
cd server-status-client
# 配置环境
python3 -m venv venv
source venv/bin/activate
# 安装依赖
pip install pdm
pdm install
# 如需自启动请自行添加到系统服务
```
## 🎉 使用
@ -69,40 +78,13 @@ 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
git pull
sudo systemctl restart server-status-client
#
git pull
systemctl restart server-status-client
```
### 服务端

100
deploy-cn.sh Executable file
View File

@ -0,0 +1,100 @@
#!/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,9 +64,6 @@ if [ ! -f "$python_exe" ]; then
fi
echo "venv created successfully"
# activate the virtual environment
# install the required packages
echo "Installing the required packages"
$python_exe -m pip install pdm
@ -79,24 +76,24 @@ echo "Creating the systemd service"
# 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"
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"
echo "server-status-client installed successfully"