Skip to main content

Cross-Platform Service Management

Project description

DaemonCrafter Logo

A cross-platform Python library for managing system services and daemons with a unified interface.

Overview

DaemonCrafter simplifies the process of creating, managing, and controlling system services across different operating systems. It automatically detects your platform and uses the appropriate service management backend:

  • Linux: systemd
  • Windows: Service Control Manager (SCM)

Features

  • 🔄 Cross-platform compatibility - Works seamlessly on Linux and Windows
  • 🚀 Easy service installation - Install any Python script or executable as a system service
  • 🎛️ Complete lifecycle management - Install, uninstall, start, stop, enable, disable services
  • 📊 Log management - Retrieve and monitor service logs
  • 🔧 Automatic backend selection - No need to worry about platform-specific implementations
  • 🐍 Python 3.8+ support - Compatible with modern Python versions

Installation

pip install DaemonCrafter

Quick Start

from pathlib import Path
from daemon_crafter import DaemonCrafter

# Create a daemon manager for your application
daemon = DaemonCrafter(
    name="my-app-service",
    executable=Path("/path/to/your/application")
)

# Install the service
daemon.install()

# Enable auto-start at boot
daemon.enable()

# Start the service
daemon.start()

# Check if it's running
if daemon.is_running():
    print("Service is running!")

# View recent logs
logs = daemon.get_logs(lines=20)
for log_line in logs:
    print(log_line)

API Reference

DaemonCrafter Class

Constructor

DaemonCrafter(name: str, executable: Path, backend: Optional[type[DaemonProvider]] = None)
  • name: The name of the service
  • executable: Path to the executable or script
  • backend: Optional custom backend provider (auto-detected if not specified)

Methods

Method Description
install() Install the application as a system service
uninstall() Remove the service (keeps application files)
start() Start the service
stop() Stop the service
restart() Restart the service
enable() Enable auto-start at boot
disable() Disable auto-start at boot
is_installed() Check if service is installed
is_running() Check if service is currently running
is_enabled() Check if service is enabled for auto-start
get_logs(lines, since, until) Retrieve service logs

Advanced Usage

Custom Backend

from daemon_crafter import DaemonCrafter
from daemon_crafter.linux import SystemdProvider

# Force use of systemd even on other platforms
daemon = DaemonCrafter(
    name="my-service",
    executable=Path("/usr/local/bin/myapp"),
    backend=SystemdProvider
)

Log Management

# Get last 100 lines
logs = daemon.get_logs(lines=100)

# Get logs from specific time period
logs = daemon.get_logs(since="2024-01-01", until="2024-01-02")

Platform Support

Linux

  • Uses systemd for service management
  • Requires systemd-enabled distribution
  • Services installed in /etc/systemd/system/

Windows

  • Uses Windows Service Control Manager (SCM)
  • Includes winsw.exe for service wrapper functionality
  • Services registered in Windows Services

Mac

  • Not yet supported (PRs welcome!)

Requirements

  • Python 3.8 or higher
  • str-case-util dependency
  • Platform-specific requirements:
    • Linux: systemd
    • Windows: Administrative privileges for service installation

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

daemoncrafter-0.1.1b0.tar.gz (7.7 MB view details)

Uploaded Source

Built Distribution

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

daemoncrafter-0.1.1b0-py3-none-any.whl (7.8 MB view details)

Uploaded Python 3

File details

Details for the file daemoncrafter-0.1.1b0.tar.gz.

File metadata

  • Download URL: daemoncrafter-0.1.1b0.tar.gz
  • Upload date:
  • Size: 7.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.26.6 CPython/3.14.3 Linux/6.14.0-1017-azure

File hashes

Hashes for daemoncrafter-0.1.1b0.tar.gz
Algorithm Hash digest
SHA256 aee1392e0a1f0b5b127e42bc4e7a7667eb2c30d7c17e9688d1338aae939e5d06
MD5 c429f4741270d62f3a1b6e0ceac6c2e0
BLAKE2b-256 38a5233d3bdfe846a7165db1fe6c67ae355bb6d104087dd59f5afb88bf2ca410

See more details on using hashes here.

File details

Details for the file daemoncrafter-0.1.1b0-py3-none-any.whl.

File metadata

  • Download URL: daemoncrafter-0.1.1b0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.26.6 CPython/3.14.3 Linux/6.14.0-1017-azure

File hashes

Hashes for daemoncrafter-0.1.1b0-py3-none-any.whl
Algorithm Hash digest
SHA256 9c55503157553a9a9b920cc6f24f1633de47c6c4c6a5ad20ac633c1ab218e98e
MD5 a7fec4600dc4807e265f819c9f3d6ac3
BLAKE2b-256 a74bc38bc92607b3396ac4fb7355b317183a4623c6186b071363c5434a40f928

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