Metadata-Version: 2.4
Name: dnd-daemon
Version: 0.0.1
Summary: Do-Not-Disturb process enforcer — kill processes from unauthorized users on shared machines
License-Expression: MIT
Project-URL: Homepage, https://github.com/AgrawalAmey/dnd-daemon
Project-URL: Bug Tracker, https://github.com/AgrawalAmey/dnd-daemon/issues
Keywords: process,enforcer,daemon,shared,machine,reservation
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: No Input/Output (Daemon)
Classifier: Intended Audience :: System Administrators
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: System :: Systems Administration
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Provides-Extra: dev
Requires-Dist: pytest>=7.4.0; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: black>=23.0.0; extra == "dev"
Requires-Dist: isort>=5.12.0; extra == "dev"
Requires-Dist: autoflake; extra == "dev"
Requires-Dist: codespell; extra == "dev"
Requires-Dist: pyright>=1.1.300; extra == "dev"
Requires-Dist: build>=1.0.0; extra == "dev"

# dnd — Do Not Disturb

Process enforcer for shared machines. Monitors running processes and kills
anything owned by users who aren't on the allowed list. Designed for
honor-code reservation systems where some users don't follow the rules.

## Quick start

No install needed — run directly with [`uvx`](https://docs.astral.sh/uv/):

```bash
# Allow everyone by default, block specific users:
uvx dnd-daemon allow '*'
uvx dnd-daemon block debopman

# Start the daemon (foreground, for testing):
uvx dnd-daemon run --dry-run

# Start for real:
uvx dnd-daemon run
```

## Install

For persistent use, install globally with `uv`:

```bash
uv tool install dnd-daemon
```

Then use `dnd` directly:

```bash
dnd allow '*'
dnd block debopman
dnd run
```

Alternatively, install with pip:

```bash
pip install dnd-daemon
```

## Commands

| Command | Description |
|---------|-------------|
| `dnd run` | Start the enforcement daemon |
| `dnd allow <users...>` | Add users to the allowed list (also unblocks them) |
| `dnd block <users...>` | Add users to the blocked list (also removes from allowed) |
| `dnd list` | Show current allowed and blocked users |
| `dnd install` | Install as a systemd service (requires `sudo`) |
| `dnd uninstall` | Remove the systemd service (requires `sudo`) |
| `dnd status` | Show systemd service status |

### `dnd run` options

- `--dry-run` — log what would be killed without actually killing
- `--daemon` — fork into background
- `--interval N` — seconds between scans (default: 10)
- `--verbose` — debug-level logging

### Wildcards

Use `*` in the allowed list to allow everyone by default. The blocked list
always takes priority over the wildcard:

```bash
dnd allow '*'       # everyone is allowed
dnd block baduser   # ...except baduser
```

## Configuration

User lists are stored in `~/.cache/dnd/`:

```
~/.cache/dnd/
  allowed_users.txt
  blocked_users.txt
  dnd.log
```

Override with `--allow-config` and `--block-config`:

```bash
dnd --allow-config /path/to/allowed.txt list
```

## Systemd service

```bash
sudo dnd install    # creates, enables, and starts the service
sudo dnd uninstall  # stops, disables, and removes the service
dnd status          # show service status
```

The service runs as the installing user with `CAP_KILL` for permission to
terminate other users' processes. Config changes via `dnd allow` / `dnd block`
are automatically picked up (the daemon reloads on SIGHUP).

## How it works

1. Scans `/proc` every 10 seconds for all running processes
2. Skips system/service accounts (UID <= 999, known service names)
3. Checks each remaining process owner against the allowed/blocked lists
4. Sends SIGTERM, waits 5 seconds, then SIGKILL if still alive
