funserver
Project description
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 服务器管理
- 完善的跨平台安装支持
- 改进的日志管理系统
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file funserver-1.0.59-py3-none-any.whl.
File metadata
- Download URL: funserver-1.0.59-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.5 {"installer":{"name":"uv","version":"0.10.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09f733190bb1d7a4fb7da79764caf05bd5c7ef90c2152bc63a0eb89b870da91b
|
|
| MD5 |
1d15919b2bb5671db5e4ce9cd71b7665
|
|
| BLAKE2b-256 |
2e3bcb21d005941c35d1fd4d2e9c998380091db3528dd17bc2587bc446bca0eb
|