A lightweight, cross-platform daemon manager that runs any command as a background process.
Project description
python-dmon
A lightweight, cross-platform daemon manager that runs any command — called a task — as a background process. It also supports logging and log rotation out of the box. No Docker or extra dependencies required.
Shipped as the CLI tool dmon.
It is a Python-based and more powerful successor to the handy-backend shell scripts.
Features
- 🖥️ Cross-platform: Works on Linux, macOS, and Windows.
- ⚡ Lightweight: Pure Python, no Docker or external dependencies needed.
- 🧩 Flexible tasks: Tasks can be configured in
pyproject.tomlordmon.yaml; or run ad-hoc commands directly. - 🪵 Logging & log rotation: Automatically manage log files to prevent uncontrolled growth.
Installation
pip install python-dmon
To get the latest features, install from source:
pip install git+https://github.com/atomiechen/python-dmon.git
Getting Started
Prepare Configuration
Create a dmon.yaml file:
tasks:
app: ["python", "-u", "server.py"]
Or add to your pyproject.toml:
[tool.dmon.tasks]
app = ["python", "-u", "server.py"]
Commands can be a single string (run in shell), or list of strings (exec form). See Example Task Configuration for more configuration options.
Run tasks
Run a configured task by its name:
# Start a task
dmon start app
# Stop a running task
dmon stop app
# Check task status
dmon status app
If only one task is defined in the config file, you can omit the task name:
dmon start
dmon stop
dmon status
Run an ad-hoc command
# Run a command with arguments in the background
dmon run --name myserver python -u server.py
# Run a shell command in the background
dmon run --shell echo "Hello World"
# Run a shell script in the background
dmon run --cwd /path/to/script bash myscript.sh
[!NOTE] If no name is provided,
dmonautomatically assigns a fixed task namedefault_runto prevent duplicate runs.
List all running tasks
dmon list
Example Task Configuration
A task can be a string, list, or dictionary.
Here is a more complete example with default values:
tasks:
your_task_name:
# Command to run; can be a string (run in shell) or list of strings (exec form)
cmd: ["python", "server.py"] # required
cwd: "/path/to/working/dir" # (default: current dir)
env: # (default: inherit from parent process)
PYTHONUNBUFFERED: "1"
override_env: false # override parent env and only use env defined here
log_path: "logs/<task>.log" # path to log file
log_rotate: false # enable log rotation
log_max_size: 5 # max log file size before rotation in MB
rotate_log_path: "logs/<task>.rotate.log" # path to rotation log
rotate_log_max_size: 5 # max rotation log file size in MB
meta_path: ".dmon/<task>.meta.json" # path to meta file
Under the Hood
Each task is associated with a meta file (e.g. .dmon/<task>.meta.json) stored in the current working directory.
The file contains details such as the command, PID, log path, and more.
Do not modify or delete these files manually.
License
python-dmon © 2025 by Atomie CHEN is licensed under the 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
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 python_dmon-0.2.1.tar.gz.
File metadata
- Download URL: python_dmon-0.2.1.tar.gz
- Upload date:
- Size: 13.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3cab4de4eba5b05b572d34eaac17b04c510ed7cbeca103c056321c44caeb69b9
|
|
| MD5 |
e81e49a8e848aec6f2c6563dd3f315e9
|
|
| BLAKE2b-256 |
61067c90a88b7264a555c3334eb8228ecf0f5678ebd8d6713d2df240c16c560c
|
File details
Details for the file python_dmon-0.2.1-py3-none-any.whl.
File metadata
- Download URL: python_dmon-0.2.1-py3-none-any.whl
- Upload date:
- Size: 16.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
67a506042ef42664b9769fc0eafdeb0cb9c1ed997e41ff915b1b01f58f32338c
|
|
| MD5 |
7cb2c3e32f4b596ec71fa6a70ae5e46a
|
|
| BLAKE2b-256 |
3af2be4979617d7a6ad9649378b051ec79402463724bbd4dce56fc1e2c092336
|