diff options
| -rw-r--r-- | README.md | 201 |
1 files changed, 21 insertions, 180 deletions
| @@ -1,15 +1,19 @@ | |||
| 1 | # Demon - Background Process Manager | 1 | # demon - Background Process Manager |
| 2 | 2 | ||
| 3 | A lightweight, intuitive CLI tool for spawning, managing, and monitoring background processes on Linux systems. Perfect for development servers, long-running tasks, and automation workflows. | 3 | This 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 | 5 | Using demon with a justfile like this: |
| 6 | ```Justfile | ||
| 7 | start: stop | ||
| 8 | demon run server -- npm run dev | ||
| 6 | 9 | ||
| 7 | - **Simple Process Management**: Start, stop, and monitor background processes with ease | 10 | stop: |
| 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 | 13 | logs: |
| 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 | ``` |
| 16 | allows 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 |
| 92 | demon tail web-server | 96 | demon tail -f web-server |
| 93 | 97 | ||
| 94 | # Follow only stdout | 98 | # Follow only stdout |
| 95 | demon tail web-server --stdout | 99 | demon tail -f web-server --stdout |
| 96 | 100 | ||
| 97 | # Follow only stderr | 101 | # Follow only stderr |
| 98 | demon tail web-server --stderr | 102 | demon 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. | |||
| 130 | demon clean | 134 | demon clean |
| 131 | ``` | 135 | ``` |
| 132 | 136 | ||
| 133 | ### `demon llm` | ||
| 134 | Output comprehensive usage guide optimized for LLM consumption. | ||
| 135 | |||
| 136 | ```bash | ||
| 137 | demon llm | ||
| 138 | ``` | ||
| 139 | |||
| 140 | ## Use Cases | ||
| 141 | |||
| 142 | ### Development Workflows | ||
| 143 | Perfect for managing development servers and build processes: | ||
| 144 | |||
| 145 | ```bash | ||
| 146 | # Start multiple development services | ||
| 147 | demon run api-server npm run dev | ||
| 148 | demon run frontend yarn start | ||
| 149 | demon run db-server docker run -p 5432:5432 postgres | ||
| 150 | |||
| 151 | # Monitor everything | ||
| 152 | demon list | ||
| 153 | demon tail api-server --stderr # Watch for errors | ||
| 154 | |||
| 155 | # Wait for a specific service to finish | ||
| 156 | demon wait api-server | ||
| 157 | ``` | ||
| 158 | |||
| 159 | ### LLM Agent Integration | ||
| 160 | Designed for seamless automation and LLM agent workflows: | ||
| 161 | |||
| 162 | ```bash | ||
| 163 | # Agents can start long-running processes | ||
| 164 | demon run data-processor python process_large_dataset.py | ||
| 165 | |||
| 166 | # Wait for the process to complete | ||
| 167 | demon wait data-processor --timeout 3600 # 1 hour timeout | ||
| 168 | |||
| 169 | # Check status programmatically | ||
| 170 | if demon status data-processor | grep -q "RUNNING"; then | ||
| 171 | echo "Processing is still running" | ||
| 172 | fi | ||
| 173 | |||
| 174 | # Get machine-readable process list | ||
| 175 | demon list --quiet | while IFS=: read id pid status; do | ||
| 176 | echo "Process $id ($pid) is $status" | ||
| 177 | done | ||
| 178 | ``` | ||
| 179 | |||
| 180 | ### Background Tasks & Scripts | ||
| 181 | Ideal for CI/CD, backups, and system maintenance: | ||
| 182 | |||
| 183 | ```bash | ||
| 184 | # Database backup | ||
| 185 | demon run nightly-backup -- pg_dump mydb > backup.sql | ||
| 186 | |||
| 187 | # Log file processing | ||
| 188 | demon run log-analyzer tail -f /var/log/app.log | grep ERROR | ||
| 189 | |||
| 190 | # System monitoring | ||
| 191 | demon run monitor -- iostat -x 1 | ||
| 192 | ``` | ||
| 193 | |||
| 194 | ### DevOps & System Administration | ||
| 195 | Manage services without complex init systems: | ||
| 196 | |||
| 197 | ```bash | ||
| 198 | # Application deployment | ||
| 199 | demon run app-server ./deploy.sh production | ||
| 200 | |||
| 201 | # Health monitoring | ||
| 202 | demon run health-check -- while true; do curl -f http://localhost:8080/health || exit 1; sleep 30; done | ||
| 203 | |||
| 204 | # Resource monitoring | ||
| 205 | demon run resource-monitor -- top -b -n1 | head -20 | ||
| 206 | ``` | ||
| 207 | |||
| 208 | ## How It Works | 137 | ## How It Works |
| 209 | 138 | ||
| 210 | When you run `demon run web-server python -m http.server 8080`: | 139 | When you run `demon run web-server python -m http.server 8080`: |
| 211 | 140 | ||
| 212 | 1. **Process Creation**: Spawns the process detached from your terminal | 141 | 1. **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) |
| 213 | 2. **File Management**: Creates three files: | 142 | 2. **Process Creation**: Spawns the process detached from your terminal |
| 143 | 3. **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 |
| 217 | 3. **Process Monitoring**: Tracks process lifecycle independently | 147 | 4. **Process Monitoring**: Tracks process lifecycle independently |
| 218 | 4. **Log Management**: Files persist after process termination for inspection | 148 | 5. **Log Management**: Files persist after process termination for inspection |
| 219 | |||
| 220 | ## LLM Agent Integration | ||
| 221 | |||
| 222 | Demon 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 | ||
| 227 | demon 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 | ||
| 235 | demon list --quiet | grep -q "web-server:" || demon run web-server python -m http.server | ||
| 236 | |||
| 237 | # Wait for process to finish | ||
| 238 | demon wait backup-job --timeout 0 # Wait indefinitely | ||
| 239 | |||
| 240 | # Get all running processes | ||
| 241 | demon list --quiet | grep ":RUNNING" | cut -d: -f1 | ||
| 242 | ``` | ||
| 243 | |||
| 244 | ### Error Handling | ||
| 245 | ```bash | ||
| 246 | # Check if process started successfully | ||
| 247 | if demon run api-server ./start-api.sh; then | ||
| 248 | echo "API server started successfully" | ||
| 249 | demon tail api-server & # Monitor in background | ||
| 250 | else | ||
| 251 | echo "Failed to start API server" | ||
| 252 | exit 1 | ||
| 253 | fi | ||
| 254 | ``` | ||
| 255 | |||
| 256 | ## File Management | ||
| 257 | |||
| 258 | ### File Locations | ||
| 259 | All 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 | ||
| 279 | demon stop long-running-task --timeout 60 | ||
| 280 | |||
| 281 | # Force kill if process is stuck | ||
| 282 | demon stop stuck-process --timeout 1 | ||
| 283 | ``` | ||
| 284 | |||
| 285 | ### Monitoring & Debugging | ||
| 286 | ```bash | ||
| 287 | # Monitor multiple processes | ||
| 288 | for id in web-server api-server worker; do | ||
| 289 | demon tail $id --stderr & | ||
| 290 | done | ||
| 291 | |||
| 292 | # Check resource usage | ||
| 293 | demon run monitor -- ps aux | grep my-app | ||
| 294 | demon cat monitor | ||
| 295 | ``` | ||
| 296 | |||
| 297 | ### Integration with System Tools | ||
| 298 | ```bash | ||
| 299 | # Use with systemd | ||
| 300 | demon run my-service systemctl --user start my-app | ||
| 301 | |||
| 302 | # Use with Docker | ||
| 303 | demon run container -- docker run -d --name myapp nginx | ||
| 304 | |||
| 305 | # Use with tmux/screen for complex setups | ||
| 306 | demon run dev-env -- tmux new-session -d 'npm run dev' | ||
| 307 | ``` | ||
