|
1 | | -## Pitchfork |
| 1 | +<div align="center"> |
2 | 2 |
|
3 | | -A tool for wrangling daemons. [See docs](https://pitchfork.jdx.dev). |
| 3 | +<h1 align="center"> |
| 4 | + <a href="https://pitchfork.jdx.dev"> |
| 5 | + <img src="logo.png" alt="pitchfork" width="256" height="256" /> |
| 6 | + <br> |
| 7 | + pitchfork |
| 8 | + </a> |
| 9 | +</h1> |
4 | 10 |
|
5 | | - |
| 11 | +<p> |
| 12 | + <a href="https://crates.io/crates/pitchfork-cli"><img alt="Crates.io" src="https://img.shields.io/crates/v/pitchfork-cli?style=for-the-badge&color=00d9ff"></a> |
| 13 | + <a href="https://github.com/jdx/pitchfork/blob/main/LICENSE"><img alt="GitHub" src="https://img.shields.io/github/license/jdx/pitchfork?style=for-the-badge&color=52e892"></a> |
| 14 | + <a href="https://github.com/jdx/pitchfork/actions/workflows/ci.yml"><img alt="GitHub Workflow Status" src="https://img.shields.io/github/actions/workflow/status/jdx/pitchfork/ci.yml?style=for-the-badge&color=ff9100"></a> |
| 15 | +</p> |
| 16 | + |
| 17 | +<p><b>Daemons with DX</b></p> |
| 18 | + |
| 19 | +<p align="center"> |
| 20 | + <a href="https://pitchfork.jdx.dev/getting-started.html">Getting Started</a> • |
| 21 | + <a href="https://pitchfork.jdx.dev">Documentation</a> • |
| 22 | + <a href="https://pitchfork.jdx.dev/cli">CLI Reference</a> |
| 23 | +</p> |
| 24 | + |
| 25 | +<hr /> |
| 26 | + |
| 27 | +</div> |
| 28 | + |
| 29 | +## What is it? |
| 30 | + |
| 31 | +Pitchfork is a CLI for managing daemons with a focus on developer experience. |
| 32 | + |
| 33 | +- **Start services once** - Only start daemons if they have not already been started |
| 34 | +- **Auto start/stop** - Automatically start daemons when entering a project directory, stop when leaving |
| 35 | +- **Ready checks** - Based on delay, output or HTTP response |
| 36 | +- **Restart on failure** - Automatically restart daemons when they crash |
| 37 | +- **Cron jobs** - Schedule recurring tasks |
| 38 | +- **Start on boot** - Automatically start daemons when your system boots |
| 39 | +- **Project configuration** - Define all your project's daemons in `pitchfork.toml` |
| 40 | + |
| 41 | +> [!WARNING] |
| 42 | +> This project is experimental. It works in basic situations but you'll undoubtedly encounter bugs. |
| 43 | +
|
| 44 | +## Use Cases |
| 45 | + |
| 46 | +- Launching development services like web APIs and databases |
| 47 | +- Running rsync/unison to synchronize directories with a remote machine |
| 48 | +- Managing background processes for your project |
| 49 | + |
| 50 | +## Quickstart |
| 51 | + |
| 52 | +### Install pitchfork |
| 53 | + |
| 54 | +[mise-en-place](https://mise.jdx.dev) is the recommended way to install pitchfork: |
| 55 | + |
| 56 | +```sh-session |
| 57 | +$ mise use -g pitchfork |
| 58 | +``` |
| 59 | + |
| 60 | +Or install via cargo: |
| 61 | + |
| 62 | +```sh-session |
| 63 | +$ cargo install pitchfork-cli |
| 64 | +``` |
| 65 | + |
| 66 | +Or download from [GitHub releases](https://github.com/jdx/pitchfork/releases). |
| 67 | + |
| 68 | +### Launch a one-off daemon |
| 69 | + |
| 70 | +Run a process in the background—an alternative to shell jobs (`mytask &`): |
| 71 | + |
| 72 | +```sh-session |
| 73 | +$ pitchfork run docs -- npm start docs-dev-server |
| 74 | +``` |
| 75 | + |
| 76 | +### Add daemons to your project |
| 77 | + |
| 78 | +Create a `pitchfork.toml` in your project root: |
| 79 | + |
| 80 | +```toml |
| 81 | +[daemons.redis] |
| 82 | +run = "redis-server" |
| 83 | + |
| 84 | +[daemons.api] |
| 85 | +run = "npm run server:api" |
| 86 | + |
| 87 | +[daemons.docs] |
| 88 | +run = "npm run server:docs" |
| 89 | +``` |
| 90 | + |
| 91 | +Start all daemons: |
| 92 | + |
| 93 | +```sh-session |
| 94 | +$ pitchfork start --all |
| 95 | +``` |
| 96 | + |
| 97 | +Or start individual ones: |
| 98 | + |
| 99 | +```sh-session |
| 100 | +$ pitchfork start redis |
| 101 | +``` |
| 102 | + |
| 103 | +### Shell hook (auto start/stop) |
| 104 | + |
| 105 | +Enable automatic daemon management when entering/leaving project directories: |
| 106 | + |
| 107 | +```sh-session |
| 108 | +echo '$(pitchfork activate bash)' >> ~/.bashrc |
| 109 | +echo '$(pitchfork activate zsh)' >> ~/.zshrc |
| 110 | +echo 'pitchfork activate fish | source' >> ~/.config/fish/config.fish |
| 111 | +``` |
| 112 | + |
| 113 | +Configure daemons with auto start/stop: |
| 114 | + |
| 115 | +```toml |
| 116 | +[daemons.api] |
| 117 | +run = "npm run server:api" |
| 118 | +auto = ["start", "stop"] |
| 119 | +``` |
| 120 | + |
| 121 | +### View logs |
| 122 | + |
| 123 | +View daemon logs: |
| 124 | + |
| 125 | +```sh-session |
| 126 | +$ pitchfork logs api |
| 127 | +[2021-08-01T12:00:00Z] api: starting |
| 128 | +[2021-08-01T12:00:01Z] api: listening on |
| 129 | +``` |
| 130 | + |
| 131 | +Logs will be saved to `~/.local/state/pitchfork/logs`. |
| 132 | + |
| 133 | +## Example Project |
| 134 | + |
| 135 | +Here's a complete example showing how to use pitchfork for a development environment: |
| 136 | + |
| 137 | +```toml |
| 138 | +# pitchfork.toml |
| 139 | +[daemons.postgres] |
| 140 | +run = "docker run --rm -p 5432:5432 -e POSTGRES_PASSWORD=dev postgres:16" |
| 141 | +auto = ["start", "stop"] |
| 142 | +ready.http = { url = "http://localhost:5432" } |
| 143 | + |
| 144 | +[daemons.redis] |
| 145 | +run = "redis-server --port 6379" |
| 146 | +auto = ["start", "stop"] |
| 147 | +ready.delay = "2s" |
| 148 | + |
| 149 | +[daemons.api] |
| 150 | +run = "npm run dev:api" |
| 151 | +auto = ["start", "stop"] |
| 152 | +ready.http = { url = "http://localhost:3000/health" } |
| 153 | +depends = ["postgres", "redis"] |
| 154 | + |
| 155 | +[daemons.worker] |
| 156 | +run = "npm run dev:worker" |
| 157 | +auto = ["start"] |
| 158 | +depends = ["postgres", "redis"] |
| 159 | + |
| 160 | +[daemons.sync] |
| 161 | +run = "rsync -avz --delete remote:/data/ ./local-data/" |
| 162 | +cron = "0 */5 * * * *" # Run every 5 minutes |
| 163 | +``` |
| 164 | + |
| 165 | +Start everything: |
| 166 | + |
| 167 | +```sh-session |
| 168 | +$ pitchfork start --all |
| 169 | +``` |
| 170 | + |
| 171 | +## Full Documentation |
| 172 | + |
| 173 | +See [pitchfork.jdx.dev](https://pitchfork.jdx.dev) |
| 174 | + |
| 175 | +## Contributors |
| 176 | + |
| 177 | +[](https://github.com/jdx/pitchfork/graphs/contributors) |
0 commit comments