Skip to main content

Python Linux Service Manager - 专注于Linux系统服务管理的Python库

Project description

Python Linux Service Manager (plsm)

介绍

Python Linux Service Manager (plsm):专注于Linux系统服务管理的Python库,提供完整的服务配置管理、状态监控和操作功能。

软件架构

plsm采用模块化设计,将功能拆分为三个核心模块:

  • 配置管理模块 (ServiceConfigManager): 负责服务的配置文件读取、解析和管理
  • 状态管理模块 (ServiceStatusManager): 负责服务的状态监控、查询和管理
  • 主服务管理模块 (ServiceManager): 整合配置和状态管理,提供完整的服务管理功能

特性

🚀 分离架构: 配置管理和状态管理分离,职责清晰
🔍 自动检测: 自动识别系统服务状态和配置信息
💻 Python 3.8+ 兼容: 支持现代Python版本
📦 完整功能: 支持服务的启动、停止、重启、重载等操作
🛡️ 错误处理: 完善的错误处理和异常管理
🧪 完整测试: 全面的单元测试覆盖

安装教程

  1. 从源码安装
git clone https://gitee.com/your-username/plsm.git
cd plsm
pip install .
  1. 从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) - 验证服务状态

参与贡献

  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 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

plsm-0.1.0.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

plsm-0.1.0-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file plsm-0.1.0.tar.gz.

File metadata

  • Download URL: plsm-0.1.0.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for plsm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7635bb8c0541a091819bae89e49877c1829dc9673c8a60c72b2c7ffdc9bf4f3b
MD5 b541eddc77bf7e74549267d7058f2124
BLAKE2b-256 a8bd849e0a825267f3ab8e8dff97315689b214c5346486efead8736e451be46e

See more details on using hashes here.

File details

Details for the file plsm-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: plsm-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for plsm-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3b6232f18b7db70099ddadf2acbbb3da48a8ce751d9f99d5137ecd3689ed98c4
MD5 04db2afa080bc48841d7c26842578a43
BLAKE2b-256 699804e6800467fe304de39b4fd1ea282033d77304a3428f0a30f8bb889074f3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page