FunServer
FunServer 是一个 Python 服务器管理框架,提供统一的接口来管理各种服务器应用程序。它支持跨平台安装、进程管理、日志记录和配置管理。
特性
- 🚀 统一的服务器管理接口 - 提供 start、stop、restart、update 等标准操作
- 🔧 跨平台支持 - 支持 Linux、macOS 和 Windows 系统
- 📊 进程管理 - 自动 PID 跟踪和进程生命周期管理
- 📝 日志管理 - 自动日志记录和日志文件管理
- 🎯 模块化架构 - 易于扩展和添加新的服务器实现
- 💻 命令行界面 - 基于 Typer 的友好命令行工具
安装
pip install funserver
快速开始
基本用法
FunServer 提供了统一的命令行接口来管理服务器:
# 启动服务器
funserver start
# 停止服务器
funserver stop
# 重启服务器
funserver restart
# 更新服务器
funserver update
# 运行服务器(前台运行)
funserver run
OneHub 服务器管理
FunServer 内置了对 OneHub(API 网关)的支持:
# 安装 OneHub
funonehub install
# 启动 OneHub 服务
funonehub start
# 停止 OneHub 服务
funonehub stop
# 重启 OneHub 服务
funonehub restart
# 更新 OneHub
funonehub update
架构设计
核心组件
- BaseServer - 服务器基类,提供标准的服务器管理功能
- BaseInstall - 安装管理基类,支持跨平台安装
- BaseStart - 启动管理基类,定义服务器启动接口
目录结构
src/funserver/
├── servers/
│ ├── base/ # 基础框架
│ │ ├── base.py # 服务器基类
│ │ ├── install.py # 安装管理
│ │ └── start.py # 启动管理
│ ├── funjupyter/ # Jupyter 服务器支持
│ └── onehub.py # OneHub 服务器实现
└── __init__.py
开发自定义服务器
创建自定义服务器
继承 BaseServer 类来创建自定义服务器:
from funserver.servers.base.base import BaseServer, server_parser
class MyCustomServer(BaseServer):
def __init__(self):
super().__init__(server_name="mycustomserver")
def run_cmd(self, *args, **kwargs):
# 返回启动服务器的命令
return "my-server --config config.yaml"
def install_linux(self, *args, **kwargs):
# Linux 安装逻辑
return True
def install_macos(self, *args, **kwargs):
# macOS 安装逻辑
return True
def install_windows(self, *args, **kwargs):
# Windows 安装逻辑
return True
def update(self, *args, **kwargs):
# 更新逻辑
pass
def mycustomserver():
app = server_parser(MyCustomServer())
app()
注册命令行工具
在 pyproject.toml 中添加脚本入口:
[project.scripts]
mycustomserver = "mypackage.servers.custom:mycustomserver"
API 参考
BaseServer
主要方法:
start()- 启动服务器(后台运行)stop()- 停止服务器restart()- 重启服务器run()- 运行服务器(前台运行)update()- 更新服务器install()- 安装服务器run_cmd()- 返回启动命令(需要子类实现)
配置
服务器配置和日志文件默认存储在:
- 配置目录:
~/.cache/servers/{server_name}/ - 日志目录:
~/.cache/servers/{server_name}/logs/ - PID 文件:
~/.cache/servers/{server_name}/run.pid
依赖项
click>=8.1.8- 命令行界面funbuild>=1.5.11- 构建工具funutil>=1.0.50- 实用工具psutil>=7.0.0- 进程管理typer>=0.15.3- 现代命令行界面
贡献
欢迎贡献代码!请遵循以下步骤:
- Fork 项目
- 创建特性分支 (
git checkout -b feature/AmazingFeature) - 提交更改 (
git commit -m 'Add some AmazingFeature') - 推送到分支 (
git push origin feature/AmazingFeature) - 打开 Pull Request
许可证
本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情。
作者
- 牛哥 - 初始工作 - niuliangtao@qq.com
- farfarfun - 维护者 - farfarfun@qq.com
链接
更新日志
v1.0.52
- 当前版本
- 支持 OneHub 服务器管理
- 完善的跨平台安装支持
- 改进的日志管理系统
Metadata
Release files for funserver 1.0.70
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| funserver-1.0.70-py3-none-any.whl | Python 3 | none | any | Details for funserver-1.0.70-py3-none-any.whl |
Release files / funserver-1.0.70-py3-none-any.whl
| Download URL | funserver-1.0.70-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a6f57ea9d5a2dea6372f6b8a42a09414d45ee7a0cbf558179f4844413cbd4227
|
|
BLAKE2b-256 checksum How to use checksums |
636fb2c8fa664f43bcbb3743b33c24f6a24b24c22e6dda852248533e8541cafa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for funserver 1.0.70
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.