Skip to content

Commit c02505f

Browse files
justin808claude
andcommitted
Add documentation for service dependency checking
- Updated bin/dev --help with SERVICE DEPENDENCIES section - Added comprehensive documentation in docs/building-features/process-managers.md - Includes configuration examples, field descriptions, and sample output - Added security note about command execution - Documents zero-impact behavior when .dev-services.yml doesn't exist 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent df8e2ee commit c02505f

File tree

2 files changed

+111
-5
lines changed

2 files changed

+111
-5
lines changed

docs/building-features/process-managers.md

Lines changed: 94 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ React on Rails includes `bin/dev` which automatically uses Overmind or Foreman:
1616

1717
This script will:
1818

19-
1. Run Shakapacker's `precompile_hook` once (if configured in `config/shakapacker.yml`)
20-
2. Set `SHAKAPACKER_SKIP_PRECOMPILE_HOOK=true` to prevent duplicate execution
21-
3. Try to use Overmind (if installed)
22-
4. Fall back to Foreman (if installed)
23-
5. Show installation instructions if neither is found
19+
1. Check required external services (if `.dev-services.yml` exists)
20+
2. Run Shakapacker's `precompile_hook` once (if configured in `config/shakapacker.yml`)
21+
3. Set `SHAKAPACKER_SKIP_PRECOMPILE_HOOK=true` to prevent duplicate execution
22+
4. Try to use Overmind (if installed)
23+
5. Fall back to Foreman (if installed)
24+
6. Show installation instructions if neither is found
2425

2526
### Precompile Hook Integration
2627

@@ -57,6 +58,94 @@ default: &default
5758
5859
See the [i18n documentation](./i18n.md#internationalization) for more details on configuring the precompile hook.
5960
61+
### Service Dependency Checking
62+
63+
`bin/dev` can automatically verify that required external services (like Redis, PostgreSQL, Elasticsearch) are running before starting your development server. This prevents cryptic error messages and provides clear instructions on how to start missing services.
64+
65+
#### Configuration
66+
67+
Create a `.dev-services.yml` file in your project root:
68+
69+
```yaml
70+
services:
71+
redis:
72+
check_command: 'redis-cli ping'
73+
expected_output: 'PONG'
74+
start_command: 'redis-server'
75+
install_hint: 'brew install redis (macOS) or apt-get install redis-server (Linux)'
76+
description: 'Redis (for caching and background jobs)'
77+
78+
postgresql:
79+
check_command: 'pg_isready'
80+
expected_output: 'accepting connections'
81+
start_command: 'pg_ctl -D /usr/local/var/postgres start'
82+
install_hint: 'brew install postgresql (macOS)'
83+
description: 'PostgreSQL database'
84+
```
85+
86+
A `.dev-services.yml.example` file with common service configurations is created when you run the React on Rails generator.
87+
88+
#### Configuration Fields
89+
90+
- **check_command** (required): Shell command to check if the service is running
91+
- **expected_output** (optional): String that must appear in the command output
92+
- **start_command** (optional): Command to start the service (shown in error messages)
93+
- **install_hint** (optional): How to install the service if not found
94+
- **description** (optional): Human-readable description of the service
95+
96+
#### Behavior
97+
98+
If `.dev-services.yml` exists, `bin/dev` will:
99+
100+
1. Check each configured service before starting
101+
2. Show a success message if all services are running
102+
3. Show helpful error messages with start commands if any service is missing
103+
4. Exit before starting the Procfile if services are unavailable
104+
105+
If `.dev-services.yml` doesn't exist, `bin/dev` works exactly as before (zero impact on existing installations).
106+
107+
#### Example Output
108+
109+
**When services are running:**
110+
111+
```
112+
🔍 Checking required services (.dev-services.yml)...
113+
114+
✓ redis - Redis (for caching and background jobs)
115+
✓ postgresql - PostgreSQL database
116+
117+
✅ All services are running
118+
```
119+
120+
**When services are missing:**
121+
122+
```
123+
🔍 Checking required services (.dev-services.yml)...
124+
125+
✗ redis - Redis (for caching and background jobs)
126+
127+
❌ Some services are not running
128+
129+
Please start these services before running bin/dev:
130+
131+
redis
132+
Redis (for caching and background jobs)
133+
134+
To start:
135+
redis-server
136+
137+
Not installed? brew install redis (macOS) or apt-get install redis-server (Linux)
138+
139+
💡 Tips:
140+
• Start services manually, then run bin/dev again
141+
• Or remove service from .dev-services.yml if not needed
142+
• Or add service to Procfile.dev to start automatically
143+
```
144+
145+
#### Security Note
146+
147+
⚠️ Commands in `.dev-services.yml` are executed during `bin/dev` startup. Only add commands from trusted sources. Consider adding `.dev-services.yml` to `.gitignore` if it contains machine-specific paths or sensitive information.
148+
60149
## Installing a Process Manager
61150
62151
### Overmind (Recommended)

lib/react_on_rails/dev/server_manager.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ def help_options
331331
end
332332
# rubocop:enable Metrics/AbcSize
333333

334+
# rubocop:disable Metrics/AbcSize
334335
def help_customization
335336
<<~CUSTOMIZATION
336337
#{Rainbow('🔧 CUSTOMIZATION:').cyan.bold}
@@ -341,8 +342,24 @@ def help_customization
341342
#{Rainbow('•').yellow} #{Rainbow('Procfile.dev-prod-assets').green.bold} - Production-optimized assets (port 3001)
342343
343344
#{Rainbow('Edit these files to customize the development environment for your needs.').white}
345+
346+
#{Rainbow('🔍 SERVICE DEPENDENCIES:').cyan.bold}
347+
#{Rainbow('Configure required external services in').white} #{Rainbow('.dev-services.yml').green.bold}#{Rainbow(':').white}
348+
349+
#{Rainbow('•').yellow} #{Rainbow('bin/dev').white} #{Rainbow('checks services before starting (optional)').white}
350+
#{Rainbow('•').yellow} #{Rainbow('Copy from').white} #{Rainbow('.dev-services.yml.example').green.bold} #{Rainbow('to get started').white}
351+
#{Rainbow('•').yellow} #{Rainbow('Supports Redis, PostgreSQL, Elasticsearch, and custom services').white}
352+
#{Rainbow('•').yellow} #{Rainbow('Shows helpful errors with start commands if services are missing').white}
353+
354+
#{Rainbow('Example .dev-services.yml:').white}
355+
#{Rainbow(' services:').cyan}
356+
#{Rainbow(' redis:').cyan}
357+
#{Rainbow(' check_command: "redis-cli ping"').cyan}
358+
#{Rainbow(' expected_output: "PONG"').cyan}
359+
#{Rainbow(' start_command: "redis-server"').cyan}
344360
CUSTOMIZATION
345361
end
362+
# rubocop:enable Metrics/AbcSize
346363

347364
# rubocop:disable Metrics/AbcSize
348365
def help_mode_details

0 commit comments

Comments
 (0)