Python Linux Service Manager - 专注于Linux系统服务管理的Python库
Project description
Python Linux Service Manager (plsm)
介绍
Python Linux Service Manager (plsm):专注于Linux系统服务管理的Python库,提供完整的服务配置管理、状态监控和操作功能。
项目统计
- 最新版本: v0.1.0
- PyPI 下载量: 查看统计
- 支持Python版本: 3.8+
- 许可证: MIT
软件架构
plsm采用模块化设计,将功能拆分为三个核心模块:
- 配置管理模块 (
ServiceConfigManager): 负责服务的配置文件读取、解析和管理 - 状态管理模块 (
ServiceStatusManager): 负责服务的状态监控、查询和管理 - 主服务管理模块 (
ServiceManager): 整合配置和状态管理,提供完整的服务管理功能
特性
🚀 分离架构: 配置管理和状态管理分离,职责清晰
🔍 自动检测: 自动识别系统服务状态和配置信息
💻 Python 3.8+ 兼容: 支持现代Python版本
📦 完整功能: 支持服务的启动、停止、重启、重载等操作
🛡️ 错误处理: 完善的错误处理和异常管理
🧪 完整测试: 全面的单元测试覆盖
安装教程
- 从源码安装
git clone https://gitee.com/liumou_site/plsm.git
cd plsm
pip install .
- 从PyPI安装 (待发布)
pip install plsm
快速开始
from plsm import ServiceManager, ServiceConfig
# 创建服务管理器
manager = ServiceManager(sudo=True)
# 列出所有服务
services = manager.list_all_services()
for service in services[:5]:
print(f"{service.name}: {service.status.value}")
# 检查特定服务状态
nginx_info = manager.get_service_info("nginx")
if nginx_info:
print(f"nginx状态: {nginx_info.status.value}")
# 创建自定义服务
config = ServiceConfig(
name="my-service",
description="My Custom Service",
exec_start="/usr/bin/python3 -m http.server 8080",
working_directory="/tmp"
)
# 创建并启动服务
manager.create_service(config, start_after_create=True)
API 参考
ServiceConfigManager 类
list_services()- 列出所有服务service_exists(name)- 检查服务是否存在read_config(name)- 读取服务配置create_config(config)- 创建服务配置remove_config(name)- 删除服务配置
ServiceStatusManager 类
get_status(name)- 获取服务状态is_running(name)- 检查服务是否运行is_active(name)- 检查服务是否激活list_services()- 列出所有服务状态
ServiceManager 类
start_service(name)- 启动服务stop_service(name)- 停止服务restart_service(name)- 重启服务enable_service(name)- 启用服务create_service(config)- 创建服务validate_service(name)- 验证服务状态
参与贡献
- Fork 本仓库
- 新建 Feat_xxx 分支
- 提交代码
- 新建 Pull Request
许可证
本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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 plsm-1.0.1.tar.gz.
File metadata
- Download URL: plsm-1.0.1.tar.gz
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ef0b52d504310b15717c75c302a5d79038468a84e710f2640b10a6350734ed0
|
|
| MD5 |
ad2c78265478d3c743453ecf1b7e0e51
|
|
| BLAKE2b-256 |
15eb6e045df68b5df991bec735d38492d637768e9e51c817f481dddf661172da
|
File details
Details for the file plsm-1.0.1-py3-none-any.whl.
File metadata
- Download URL: plsm-1.0.1-py3-none-any.whl
- Upload date:
- Size: 15.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16bedb9f13284901c7fd6d866e7bb29590beb36c435bbf3640413c510211999f
|
|
| MD5 |
8c846a75d30dfa6e7a45d1d64bff4e5e
|
|
| BLAKE2b-256 |
790ec20af664d5cd534dcc0af95c4e8d3d9c44b33c81074c979c381b2845d7b2
|