Skip to main content

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

Project description

Python Linux Service Manager (plsm)

PyPI Version Python Versions Downloads License Gitee Stars

介绍

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

项目统计

  • 最新版本: v0.1.0
  • PyPI 下载量: 查看统计
  • 支持Python版本: 3.8+
  • 许可证: MIT

软件架构

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

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

特性

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

安装教程

  1. 从源码安装
git clone https://gitee.com/liumou_site/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-1.0.0.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

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

plsm-1.0.0-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for plsm-1.0.0.tar.gz
Algorithm Hash digest
SHA256 47194854075e34f594cf530a57ec8ed7b618847f338771690fbf79e771b9ffb8
MD5 ad80962aa3e1c413482cf96183624d2c
BLAKE2b-256 2c5784c627d6edcd425640747da1247e9850dc84bcd8ff4596752b0196f67deb

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for plsm-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0bc1567d06fab9c4ff3145924a8bedad68b7c452380d3cab8bde6fff24625248
MD5 ce13d6dac1d5d67cfe65a27c4699f006
BLAKE2b-256 8dfd1d724eec4b529ffd2216cf8a721d7a7337ca633f6a76cb3dacdccccec8a0

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