aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md201
1 files changed, 21 insertions, 180 deletions
diff --git a/README.md b/README.md
index 53698ff..8bec765 100644
--- a/README.md
+++ b/README.md
@@ -1,15 +1,19 @@
1# Demon - Background Process Manager 1# demon - Background Process Manager
2 2
3A lightweight, intuitive CLI tool for spawning, managing, and monitoring background processes on Linux systems. Perfect for development servers, long-running tasks, and automation workflows. 3This tool helps AI agents control long-running processes and view their logs easily. For example, when running `npm run dev`, Claude often runs problematic commands like `npm run dev &` which makes it unable to see the logs or properly kill the process afterward. When it tries to run `npm run dev` again, the new instance binds to a different port and it ends up getting kind of lost.
4 4
5## Features 5Using demon with a justfile like this:
6```Justfile
7start: stop
8 demon run server -- npm run dev
6 9
7- **Simple Process Management**: Start, stop, and monitor background processes with ease 10stop:
8- **Persistent Logging**: Automatic stdout/stderr capture to files 11 demon stop server
9- **Real-time Monitoring**: Tail logs in real-time with file watching 12
10- **Process Lifecycle**: Graceful termination with SIGTERM/SIGKILL fallback 13logs:
11- **Machine-readable Output**: Perfect for scripting and LLM agent integration 14 demon cat server
12- **Zero Configuration**: Works out of the box, no setup required 15```
16allows Claude to check errors, manage the running server without getting stuck, and be more autonomous overall.
13 17
14## Installation 18## Installation
15 19
@@ -89,13 +93,13 @@ Follow log files in real-time (like `tail -f`).
89 93
90```bash 94```bash
91# Follow both stdout and stderr 95# Follow both stdout and stderr
92demon tail web-server 96demon tail -f web-server
93 97
94# Follow only stdout 98# Follow only stdout
95demon tail web-server --stdout 99demon tail -f web-server --stdout
96 100
97# Follow only stderr 101# Follow only stderr
98demon tail web-server --stderr 102demon tail =f web-server --stderr
99``` 103```
100 104
101### `demon cat <id> [--stdout] [--stderr]` 105### `demon cat <id> [--stdout] [--stderr]`
@@ -130,178 +134,15 @@ Remove orphaned files from processes that are no longer running.
130demon clean 134demon clean
131``` 135```
132 136
133### `demon llm`
134Output comprehensive usage guide optimized for LLM consumption.
135
136```bash
137demon llm
138```
139
140## Use Cases
141
142### Development Workflows
143Perfect for managing development servers and build processes:
144
145```bash
146# Start multiple development services
147demon run api-server npm run dev
148demon run frontend yarn start
149demon run db-server docker run -p 5432:5432 postgres
150
151# Monitor everything
152demon list
153demon tail api-server --stderr # Watch for errors
154
155# Wait for a specific service to finish
156demon wait api-server
157```
158
159### LLM Agent Integration
160Designed for seamless automation and LLM agent workflows:
161
162```bash
163# Agents can start long-running processes
164demon run data-processor python process_large_dataset.py
165
166# Wait for the process to complete
167demon wait data-processor --timeout 3600 # 1 hour timeout
168
169# Check status programmatically
170if demon status data-processor | grep -q "RUNNING"; then
171 echo "Processing is still running"
172fi
173
174# Get machine-readable process list
175demon list --quiet | while IFS=: read id pid status; do
176 echo "Process $id ($pid) is $status"
177done
178```
179
180### Background Tasks & Scripts
181Ideal for CI/CD, backups, and system maintenance:
182
183```bash
184# Database backup
185demon run nightly-backup -- pg_dump mydb > backup.sql
186
187# Log file processing
188demon run log-analyzer tail -f /var/log/app.log | grep ERROR
189
190# System monitoring
191demon run monitor -- iostat -x 1
192```
193
194### DevOps & System Administration
195Manage services without complex init systems:
196
197```bash
198# Application deployment
199demon run app-server ./deploy.sh production
200
201# Health monitoring
202demon run health-check -- while true; do curl -f http://localhost:8080/health || exit 1; sleep 30; done
203
204# Resource monitoring
205demon run resource-monitor -- top -b -n1 | head -20
206```
207
208## How It Works 137## How It Works
209 138
210When you run `demon run web-server python -m http.server 8080`: 139When you run `demon run web-server python -m http.server 8080`:
211 140
2121. **Process Creation**: Spawns the process detached from your terminal 1411. **Root Directory Discovery**: Finds the git root directory and creates a `.demon` subdirectory for all daemon files (or uses `--root-dir` if specified, or `DEMON_ROOT_DIR` environment variable)
2132. **File Management**: Creates three files: 1422. **Process Creation**: Spawns the process detached from your terminal
1433. **File Management**: Creates three files in the root directory:
214 - `web-server.pid` - Contains the process ID and command 144 - `web-server.pid` - Contains the process ID and command
215 - `web-server.stdout` - Captures standard output 145 - `web-server.stdout` - Captures standard output
216 - `web-server.stderr` - Captures error output 146 - `web-server.stderr` - Captures error output
2173. **Process Monitoring**: Tracks process lifecycle independently 1474. **Process Monitoring**: Tracks process lifecycle independently
2184. **Log Management**: Files persist after process termination for inspection 1485. **Log Management**: Files persist after process termination for inspection
219
220## LLM Agent Integration
221
222Demon is specifically designed to work seamlessly with LLM agents and automation tools:
223
224### Machine-Readable Output
225```bash
226# Get process status in parseable format
227demon list --quiet
228# Output: web-server:12345:RUNNING
229# backup-job:12346:DEAD
230```
231
232### Scripting Examples
233```bash
234# Start service if not running
235demon list --quiet | grep -q "web-server:" || demon run web-server python -m http.server
236
237# Wait for process to finish
238demon wait backup-job --timeout 0 # Wait indefinitely
239
240# Get all running processes
241demon list --quiet | grep ":RUNNING" | cut -d: -f1
242```
243
244### Error Handling
245```bash
246# Check if process started successfully
247if demon run api-server ./start-api.sh; then
248 echo "API server started successfully"
249 demon tail api-server & # Monitor in background
250else
251 echo "Failed to start API server"
252 exit 1
253fi
254```
255
256## File Management
257
258### File Locations
259All files are created in the current working directory:
260- `<id>.pid` - Process ID and command information
261- `<id>.stdout` - Standard output log
262- `<id>.stderr` - Standard error log
263
264### Cleanup
265- Files persist after process termination for inspection
266- Use `demon clean` to remove files from dead processes
267- Consider adding `*.pid`, `*.stdout`, `*.stderr` to `.gitignore`
268
269### Log Rotation
270- Demon doesn't handle log rotation internally
271- For long-running processes, implement rotation in your application
272- Or use external tools like `logrotate`
273
274## Advanced Usage
275
276### Process Management
277```bash
278# Graceful shutdown with custom timeout
279demon stop long-running-task --timeout 60
280
281# Force kill if process is stuck
282demon stop stuck-process --timeout 1
283```
284
285### Monitoring & Debugging
286```bash
287# Monitor multiple processes
288for id in web-server api-server worker; do
289 demon tail $id --stderr &
290done
291
292# Check resource usage
293demon run monitor -- ps aux | grep my-app
294demon cat monitor
295```
296
297### Integration with System Tools
298```bash
299# Use with systemd
300demon run my-service systemctl --user start my-app
301
302# Use with Docker
303demon run container -- docker run -d --name myapp nginx
304
305# Use with tmux/screen for complex setups
306demon run dev-env -- tmux new-session -d 'npm run dev'
307```