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
- Clone the repository:
git clone https://github.com/Artillence/pywin32supervisor.git cd pywin32supervisor
- 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 (orall). - โน๏ธ
stop <program>โ Stops a specific program (orall). - ๐
restart <program>โ Restarts a specific program (orall).
๐ฑ 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
-
Install development dependencies:
pip install -e ".[dev]"
-
Install pre-commit hooks:
pre-commit install
๐ Linting and Formatting
- ๐งน Linting is configured with
ruff(seeruff.toml). - Run
ruff check .to lint orruff check . --fixto 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:9001with no authentication (local access only). - ๐ Config file must be trusted; no sanitization of commands.
๐ค Contributing
Contributions are welcome! ๐ Please:
- ๐ด Fork the repository.
- ๐ฟ Create a feature branch.
- ๐ฉ 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
Release history Release notifications | RSS feed
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d41b6ea5ecb36424a275cd6f6bf732eac46f254bb4717fee6aaf04ae830c1d4
|
|
| MD5 |
93fd40844218e251341695d6377f081f
|
|
| BLAKE2b-256 |
5147633aca1708cbe3d0e331cc52a7f49988e58a679329f74c2396db21573772
|
Provenance
The following attestation bundles were made for pywin32supervisor-0.0.1.tar.gz:
Publisher:
python-publish.yml on Artillence/pywin32supervisor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pywin32supervisor-0.0.1.tar.gz -
Subject digest:
6d41b6ea5ecb36424a275cd6f6bf732eac46f254bb4717fee6aaf04ae830c1d4 - Sigstore transparency entry: 203200615
- Sigstore integration time:
-
Permalink:
Artillence/pywin32supervisor@0b22a037cd86e6f35f5fb7e7b001b6a7e2a427c0 -
Branch / Tag:
refs/tags/v0.0.0 - Owner: https://github.com/Artillence
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@0b22a037cd86e6f35f5fb7e7b001b6a7e2a427c0 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pywin32supervisor-0.0.1-py3-none-any.whl.
File metadata
- Download URL: pywin32supervisor-0.0.1-py3-none-any.whl
- Upload date:
- Size: 17.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
514404b48edf3a126e1808dad57c900abd190bd6d28e8e388dc44b0bf1693dde
|
|
| MD5 |
87e1a1bdaf32db9b423861bdfaa234be
|
|
| BLAKE2b-256 |
2f2b135cfaca119d208dd0fa555850765b3516f20444b651f0ff7bef9074474e
|
Provenance
The following attestation bundles were made for pywin32supervisor-0.0.1-py3-none-any.whl:
Publisher:
python-publish.yml on Artillence/pywin32supervisor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pywin32supervisor-0.0.1-py3-none-any.whl -
Subject digest:
514404b48edf3a126e1808dad57c900abd190bd6d28e8e388dc44b0bf1693dde - Sigstore transparency entry: 203200616
- Sigstore integration time:
-
Permalink:
Artillence/pywin32supervisor@0b22a037cd86e6f35f5fb7e7b001b6a7e2a427c0 -
Branch / Tag:
refs/tags/v0.0.0 - Owner: https://github.com/Artillence
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@0b22a037cd86e6f35f5fb7e7b001b6a7e2a427c0 -
Trigger Event:
release
-
Statement type: