Skip to main content

Python win32 service similar to supervisor for Unix-based systems.

Project description

๐Ÿš€ pywin32supervisor

A Python-based Windows service for process supervision, inspired by the Unix supervisor tool.
This package leverages pywin32 to manage subprocesses on Windows, providing features like autostart, autorestart, logging, and remote control via an XML-RPC interface.


๐ŸŒŸ Features

  • โš™๏ธ Service Management: Install, start, stop, and debug as a Windows service.
  • ๐Ÿ”„ Process Supervision: Manage multiple programs with configurable autostart and autorestart policies.
  • ๐Ÿ“œ Logging: Redirect stdout/stderr to files or combine them as needed.
  • ๐ŸŒ Remote Control: Use an XML-RPC server to monitor and control programs.
  • ๐ŸŒฑ Environment Variables: Substitute variables in the config file with command-line provided values.

๐Ÿ“Œ Requirements

  • ๐Ÿ Python 3.10+
  • ๐Ÿ–ฅ๏ธ Windows OS
  • ๐Ÿ“ฆ pywin32 (version 308 or higher)

๐Ÿ“ฅ Installation

๐Ÿ“ฆ From PyPI (Not Yet Published)

Once published, install using pip:

pip install pywin32supervisor

๐Ÿ”ง From Source

  1. Clone the repository:
    git clone https://github.com/Artillence/pywin32supervisor.git
    cd pywin32supervisor
    
  2. Install dependencies and the package:
    pip install .
    

๐Ÿš€ Usage

๐Ÿ–ฅ๏ธ Running as a Script

Run the supervisor directly from the source file:

python pywin32supervisor/supervisor.py --service install --config "C:\path\to\supervisord.conf" --env PYTHON_PATH=C:\venv\Scripts\python.exe
python pywin32supervisor/supervisor.py --service start
python pywin32supervisor/supervisor.py status

๐Ÿ“ฆ Running as an Installed Package

After installation, use the pywin32supervisor command:

pywin32supervisor --service install --config "C:\path\to\supervisord.conf" --env PYTHON_PATH=C:\venv\Scripts\python.exe --env MY_VAR=C:\some_path
pywin32supervisor --service start
pywin32supervisor status

๐Ÿ› ๏ธ Commands

  • ๐Ÿ”น --service install โž Installs the service with the specified config and environment variables.
  • โ–ถ๏ธ --service start โž Starts the installed service.
  • โน๏ธ --service stop โž Stops the running service.
  • โŒ --service remove โž Uninstalls the service.
  • ๐Ÿž --service debug โž Runs the service in debug mode (foreground).
  • ๐Ÿ“Š status โž Displays the status of all managed programs.
  • โ–ถ๏ธ start <program> โž Starts a specific program (or all).
  • โน๏ธ stop <program> โž Stops a specific program (or all).
  • ๐Ÿ”„ restart <program> โž Restarts a specific program (or all).

๐ŸŒฑ Environment Variables

Use --env to pass environment variables (e.g., --env KEY=VALUE).
These are prefixed with ENV_ in the environment and can be referenced in the config file as %(ENV_KEY)s.

๐Ÿ”น Example:

pywin32supervisor --service install --config "C:\supervisord.conf" --env PYTHON_PATH=C:\venv\Scripts\python.exe

๐Ÿ“ In supervisord.conf:

[program:myapp]
command=%(ENV_PYTHON_PATH)s my_script.py

โš™๏ธ Configuration File

The service uses an INI-style configuration file (e.g., supervisord.conf).
Each managed program is defined in a [program:<name>] section.

๐Ÿ“ Example supervisord.conf

[program:worker]
command=C:\venv\Scripts\python.exe C:\app\worker.py
autostart=true
autorestart=true
stdout_logfile=C:\logs\worker\stdout.log
stderr_logfile=C:\logs\worker\stderr.log
redirect_stderr=false

[program:server]
command=%(PYTHON_PATH)s C:\app\server.py
autostart=true
autorestart=false
stdout_logfile=C:\logs\server\stdout.log

๐Ÿ”ง Configuration Options

  • ๐Ÿ—๏ธ command: The command to execute (required).
  • โ–ถ๏ธ autostart: Start the program when the service starts (true/false, default: false).
  • ๐Ÿ”„ autorestart: Restart the program if it exits unexpectedly (true/false, default: false).
  • ๐Ÿ“œ stdout_logfile: Path to redirect stdout (optional).
  • ๐Ÿ“œ stderr_logfile: Path to redirect stderr (optional).
  • ๐Ÿ”„ redirect_stderr: Combine stderr with stdout (true/false, default: false).

๐Ÿ› ๏ธ Development

๐Ÿ“ Directory Structure

pywin32supervisor/
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ ruff.toml
โ”œโ”€โ”€ .pre-commit-config.yaml
โ””โ”€โ”€ pywin32supervisor/
    โ”œโ”€โ”€ __init__.py
    โ””โ”€โ”€ supervisor.py

โš™๏ธ Setup

  1. Install development dependencies:

    pip install -e ".[dev]"
    
  2. Install pre-commit hooks:

    pre-commit install
    

๐Ÿ” Linting and Formatting

  • ๐Ÿงน Linting is configured with ruff (see ruff.toml).
  • Run ruff check . to lint or ruff check . --fix to auto-fix issues.
  • ๐Ÿ–Œ Formatting is handled by ruff format.

โš ๏ธ Known Limitations

  • โš ๏ธ Requires administrative privileges to install/start/stop the service.
  • ๐ŸŒ XML-RPC server binds to 127.0.0.1:9001 with no authentication (local access only).
  • ๐Ÿ“ Config file must be trusted; no sanitization of commands.

๐Ÿค Contributing

Contributions are welcome! ๐ŸŽ‰ Please:

  1. ๐Ÿด Fork the repository.
  2. ๐ŸŒฟ Create a feature branch.
  3. ๐Ÿ“ฉ Submit a pull request with a clear description.

See GitHub Issues for current tasks or to report bugs.


๐Ÿ“œ License

This project is licensed under the terms specified in the LICENSE file.


๐Ÿ“ž Contact

For questions or support, contact Greg Karz ๐Ÿ“ฉ or visit the project homepage.

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

pywin32supervisor-0.0.1.tar.gz (17.8 kB view details)

Uploaded Source

Built Distribution

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

pywin32supervisor-0.0.1-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file pywin32supervisor-0.0.1.tar.gz.

File metadata

  • Download URL: pywin32supervisor-0.0.1.tar.gz
  • Upload date:
  • Size: 17.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pywin32supervisor-0.0.1.tar.gz
Algorithm Hash digest
SHA256 6d41b6ea5ecb36424a275cd6f6bf732eac46f254bb4717fee6aaf04ae830c1d4
MD5 93fd40844218e251341695d6377f081f
BLAKE2b-256 5147633aca1708cbe3d0e331cc52a7f49988e58a679329f74c2396db21573772

See more details on using hashes here.

Provenance

The following attestation bundles were made for pywin32supervisor-0.0.1.tar.gz:

Publisher: python-publish.yml on Artillence/pywin32supervisor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pywin32supervisor-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pywin32supervisor-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 514404b48edf3a126e1808dad57c900abd190bd6d28e8e388dc44b0bf1693dde
MD5 87e1a1bdaf32db9b423861bdfaa234be
BLAKE2b-256 2f2b135cfaca119d208dd0fa555850765b3516f20444b651f0ff7bef9074474e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pywin32supervisor-0.0.1-py3-none-any.whl:

Publisher: python-publish.yml on Artillence/pywin32supervisor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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