servherd 0.0.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +250 -0
- package/LICENSE +21 -0
- package/README.md +653 -29
- package/dist/cli/commands/config.d.ts +35 -0
- package/dist/cli/commands/config.js +336 -0
- package/dist/cli/commands/info.d.ts +37 -0
- package/dist/cli/commands/info.js +98 -0
- package/dist/cli/commands/list.d.ts +26 -0
- package/dist/cli/commands/list.js +86 -0
- package/dist/cli/commands/logs.d.ts +46 -0
- package/dist/cli/commands/logs.js +292 -0
- package/dist/cli/commands/mcp.d.ts +5 -0
- package/dist/cli/commands/mcp.js +17 -0
- package/dist/cli/commands/refresh.d.ts +20 -0
- package/dist/cli/commands/refresh.js +139 -0
- package/dist/cli/commands/remove.d.ts +20 -0
- package/dist/cli/commands/remove.js +144 -0
- package/dist/cli/commands/restart.d.ts +25 -0
- package/dist/cli/commands/restart.js +177 -0
- package/dist/cli/commands/start.d.ts +37 -0
- package/dist/cli/commands/start.js +293 -0
- package/dist/cli/commands/stop.d.ts +20 -0
- package/dist/cli/commands/stop.js +108 -0
- package/dist/cli/index.d.ts +9 -0
- package/dist/cli/index.js +160 -0
- package/dist/cli/output/formatters.d.ts +117 -0
- package/dist/cli/output/formatters.js +454 -0
- package/dist/cli/output/json-formatter.d.ts +22 -0
- package/dist/cli/output/json-formatter.js +40 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +25 -0
- package/dist/mcp/index.d.ts +14 -0
- package/dist/mcp/index.js +352 -0
- package/dist/mcp/resources/servers.d.ts +14 -0
- package/dist/mcp/resources/servers.js +128 -0
- package/dist/mcp/tools/config.d.ts +33 -0
- package/dist/mcp/tools/config.js +88 -0
- package/dist/mcp/tools/info.d.ts +36 -0
- package/dist/mcp/tools/info.js +65 -0
- package/dist/mcp/tools/list.d.ts +36 -0
- package/dist/mcp/tools/list.js +49 -0
- package/dist/mcp/tools/logs.d.ts +44 -0
- package/dist/mcp/tools/logs.js +55 -0
- package/dist/mcp/tools/refresh.d.ts +33 -0
- package/dist/mcp/tools/refresh.js +54 -0
- package/dist/mcp/tools/remove.d.ts +23 -0
- package/dist/mcp/tools/remove.js +43 -0
- package/dist/mcp/tools/restart.d.ts +23 -0
- package/dist/mcp/tools/restart.js +42 -0
- package/dist/mcp/tools/start.d.ts +38 -0
- package/dist/mcp/tools/start.js +73 -0
- package/dist/mcp/tools/stop.d.ts +23 -0
- package/dist/mcp/tools/stop.js +40 -0
- package/dist/services/config.service.d.ts +80 -0
- package/dist/services/config.service.js +227 -0
- package/dist/services/port.service.d.ts +82 -0
- package/dist/services/port.service.js +151 -0
- package/dist/services/process.service.d.ts +61 -0
- package/dist/services/process.service.js +220 -0
- package/dist/services/registry.service.d.ts +50 -0
- package/dist/services/registry.service.js +157 -0
- package/dist/types/config.d.ts +107 -0
- package/dist/types/config.js +44 -0
- package/dist/types/errors.d.ts +102 -0
- package/dist/types/errors.js +197 -0
- package/dist/types/pm2.d.ts +50 -0
- package/dist/types/pm2.js +4 -0
- package/dist/types/registry.d.ts +230 -0
- package/dist/types/registry.js +33 -0
- package/dist/utils/ci-detector.d.ts +31 -0
- package/dist/utils/ci-detector.js +68 -0
- package/dist/utils/config-drift.d.ts +71 -0
- package/dist/utils/config-drift.js +128 -0
- package/dist/utils/error-handler.d.ts +21 -0
- package/dist/utils/error-handler.js +38 -0
- package/dist/utils/log-follower.d.ts +10 -0
- package/dist/utils/log-follower.js +98 -0
- package/dist/utils/logger.d.ts +11 -0
- package/dist/utils/logger.js +24 -0
- package/dist/utils/names.d.ts +7 -0
- package/dist/utils/names.js +20 -0
- package/dist/utils/template.d.ts +88 -0
- package/dist/utils/template.js +180 -0
- package/dist/utils/time-parser.d.ts +19 -0
- package/dist/utils/time-parser.js +54 -0
- package/docs/ci-cd.md +408 -0
- package/docs/configuration.md +325 -0
- package/docs/mcp-integration.md +411 -0
- package/examples/basic-usage/README.md +187 -0
- package/examples/ci-github-actions/workflow.yml +195 -0
- package/examples/mcp-claude-code/README.md +213 -0
- package/examples/multi-server/README.md +270 -0
- package/examples/storybook/README.md +187 -0
- package/examples/vite-project/README.md +251 -0
- package/package.json +123 -6
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# THIS FILE IS AUTO GENERATED: DO NOT EDIT THIS FILE
|
|
2
|
+
# Example GitHub Actions workflow using servherd
|
|
3
|
+
# Copy this to .github/workflows/e2e.yml in your project
|
|
4
|
+
|
|
5
|
+
name: E2E Tests with servherd
|
|
6
|
+
|
|
7
|
+
on:
|
|
8
|
+
push:
|
|
9
|
+
branches: [main, master]
|
|
10
|
+
pull_request:
|
|
11
|
+
branches: [main, master]
|
|
12
|
+
|
|
13
|
+
env:
|
|
14
|
+
CI: true
|
|
15
|
+
SERVHERD_PORT_MIN: 8000
|
|
16
|
+
SERVHERD_PORT_MAX: 8100
|
|
17
|
+
|
|
18
|
+
jobs:
|
|
19
|
+
e2e-tests:
|
|
20
|
+
name: E2E Tests
|
|
21
|
+
runs-on: ubuntu-latest
|
|
22
|
+
|
|
23
|
+
steps:
|
|
24
|
+
- name: Checkout
|
|
25
|
+
uses: actions/checkout@v4
|
|
26
|
+
|
|
27
|
+
- name: Setup Node.js
|
|
28
|
+
uses: actions/setup-node@v4
|
|
29
|
+
with:
|
|
30
|
+
node-version: 20
|
|
31
|
+
cache: 'npm'
|
|
32
|
+
|
|
33
|
+
- name: Install dependencies
|
|
34
|
+
run: npm ci
|
|
35
|
+
|
|
36
|
+
- name: Install servherd
|
|
37
|
+
run: npm install -g servherd
|
|
38
|
+
|
|
39
|
+
- name: Install Playwright
|
|
40
|
+
run: npx playwright install --with-deps chromium
|
|
41
|
+
|
|
42
|
+
- name: Start development server
|
|
43
|
+
run: |
|
|
44
|
+
servherd start --name app -- npm run dev --port {{port}}
|
|
45
|
+
|
|
46
|
+
# Wait for server to be ready
|
|
47
|
+
echo "Waiting for server to start..."
|
|
48
|
+
sleep 10
|
|
49
|
+
|
|
50
|
+
# Get the assigned port
|
|
51
|
+
APP_PORT=$(servherd info app --json | jq -r '.port')
|
|
52
|
+
echo "Server running on port $APP_PORT"
|
|
53
|
+
echo "APP_URL=http://localhost:$APP_PORT" >> $GITHUB_ENV
|
|
54
|
+
|
|
55
|
+
- name: Run E2E tests
|
|
56
|
+
run: npx playwright test
|
|
57
|
+
env:
|
|
58
|
+
BASE_URL: ${{ env.APP_URL }}
|
|
59
|
+
|
|
60
|
+
- name: Upload test results
|
|
61
|
+
uses: actions/upload-artifact@v4
|
|
62
|
+
if: always()
|
|
63
|
+
with:
|
|
64
|
+
name: playwright-report
|
|
65
|
+
path: playwright-report/
|
|
66
|
+
retention-days: 7
|
|
67
|
+
|
|
68
|
+
- name: Show server logs on failure
|
|
69
|
+
if: failure()
|
|
70
|
+
run: |
|
|
71
|
+
echo "=== Server Logs ==="
|
|
72
|
+
servherd logs app --lines 100
|
|
73
|
+
echo "=== Error Logs ==="
|
|
74
|
+
servherd logs app --error --lines 100
|
|
75
|
+
|
|
76
|
+
- name: Cleanup
|
|
77
|
+
if: always()
|
|
78
|
+
run: servherd stop --all
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
# Full-stack example with multiple servers
|
|
82
|
+
fullstack-e2e:
|
|
83
|
+
name: Full-Stack E2E Tests
|
|
84
|
+
runs-on: ubuntu-latest
|
|
85
|
+
|
|
86
|
+
services:
|
|
87
|
+
postgres:
|
|
88
|
+
image: postgres:15
|
|
89
|
+
env:
|
|
90
|
+
POSTGRES_USER: test
|
|
91
|
+
POSTGRES_PASSWORD: test
|
|
92
|
+
POSTGRES_DB: testdb
|
|
93
|
+
ports:
|
|
94
|
+
- 5432:5432
|
|
95
|
+
options: >-
|
|
96
|
+
--health-cmd pg_isready
|
|
97
|
+
--health-interval 10s
|
|
98
|
+
--health-timeout 5s
|
|
99
|
+
--health-retries 5
|
|
100
|
+
|
|
101
|
+
steps:
|
|
102
|
+
- name: Checkout
|
|
103
|
+
uses: actions/checkout@v4
|
|
104
|
+
|
|
105
|
+
- name: Setup Node.js
|
|
106
|
+
uses: actions/setup-node@v4
|
|
107
|
+
with:
|
|
108
|
+
node-version: 20
|
|
109
|
+
cache: 'npm'
|
|
110
|
+
|
|
111
|
+
- name: Install dependencies
|
|
112
|
+
run: npm ci
|
|
113
|
+
|
|
114
|
+
- name: Install servherd
|
|
115
|
+
run: npm install -g servherd
|
|
116
|
+
|
|
117
|
+
- name: Start backend API
|
|
118
|
+
run: |
|
|
119
|
+
servherd start --name api --tag e2e \
|
|
120
|
+
-- npm run api --port {{port}}
|
|
121
|
+
env:
|
|
122
|
+
DATABASE_URL: postgres://test:test@localhost:5432/testdb
|
|
123
|
+
|
|
124
|
+
- name: Start frontend
|
|
125
|
+
run: |
|
|
126
|
+
# Wait for API to be ready
|
|
127
|
+
sleep 5
|
|
128
|
+
API_PORT=$(servherd info api --json | jq -r '.port')
|
|
129
|
+
|
|
130
|
+
servherd start --name frontend --tag e2e \
|
|
131
|
+
-- npm run dev --port {{port}}
|
|
132
|
+
env:
|
|
133
|
+
VITE_API_URL: http://localhost:${{ env.API_PORT }}
|
|
134
|
+
|
|
135
|
+
- name: Wait for servers
|
|
136
|
+
run: |
|
|
137
|
+
sleep 10
|
|
138
|
+
servherd list --tag e2e
|
|
139
|
+
|
|
140
|
+
# Health check
|
|
141
|
+
FRONTEND_PORT=$(servherd info frontend --json | jq -r '.port')
|
|
142
|
+
curl -f http://localhost:$FRONTEND_PORT || exit 1
|
|
143
|
+
|
|
144
|
+
- name: Run E2E tests
|
|
145
|
+
run: |
|
|
146
|
+
FRONTEND_PORT=$(servherd info frontend --json | jq -r '.port')
|
|
147
|
+
BASE_URL=http://localhost:$FRONTEND_PORT npm run test:e2e
|
|
148
|
+
|
|
149
|
+
- name: Cleanup
|
|
150
|
+
if: always()
|
|
151
|
+
run: servherd stop --tag e2e
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
# Matrix testing example
|
|
155
|
+
cross-browser:
|
|
156
|
+
name: Cross-Browser Tests
|
|
157
|
+
runs-on: ubuntu-latest
|
|
158
|
+
strategy:
|
|
159
|
+
fail-fast: false
|
|
160
|
+
matrix:
|
|
161
|
+
browser: [chromium, firefox, webkit]
|
|
162
|
+
|
|
163
|
+
steps:
|
|
164
|
+
- name: Checkout
|
|
165
|
+
uses: actions/checkout@v4
|
|
166
|
+
|
|
167
|
+
- name: Setup Node.js
|
|
168
|
+
uses: actions/setup-node@v4
|
|
169
|
+
with:
|
|
170
|
+
node-version: 20
|
|
171
|
+
cache: 'npm'
|
|
172
|
+
|
|
173
|
+
- name: Install dependencies
|
|
174
|
+
run: npm ci
|
|
175
|
+
|
|
176
|
+
- name: Install servherd
|
|
177
|
+
run: npm install -g servherd
|
|
178
|
+
|
|
179
|
+
- name: Install Playwright
|
|
180
|
+
run: npx playwright install --with-deps ${{ matrix.browser }}
|
|
181
|
+
|
|
182
|
+
- name: Start server
|
|
183
|
+
run: |
|
|
184
|
+
servherd start --name app -- npm run dev --port {{port}}
|
|
185
|
+
sleep 10
|
|
186
|
+
|
|
187
|
+
- name: Run tests on ${{ matrix.browser }}
|
|
188
|
+
run: |
|
|
189
|
+
APP_PORT=$(servherd info app --json | jq -r '.port')
|
|
190
|
+
BASE_URL=http://localhost:$APP_PORT \
|
|
191
|
+
npx playwright test --project=${{ matrix.browser }}
|
|
192
|
+
|
|
193
|
+
- name: Cleanup
|
|
194
|
+
if: always()
|
|
195
|
+
run: servherd stop app
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# Claude Code MCP Integration
|
|
2
|
+
|
|
3
|
+
This guide shows how to use servherd with Claude Code through the Model Context Protocol (MCP).
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
### 1. Install servherd
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g servherd
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### 2. Configure Claude Code
|
|
14
|
+
|
|
15
|
+
Add servherd to your Claude Code MCP configuration:
|
|
16
|
+
|
|
17
|
+
**Location:** `~/.claude/claude_desktop_config.json`
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
"mcpServers": {
|
|
22
|
+
"servherd": {
|
|
23
|
+
"command": "npx",
|
|
24
|
+
"args": ["servherd", "mcp"]
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### 3. Restart Claude Code
|
|
31
|
+
|
|
32
|
+
After updating the configuration, restart Claude Code to load the new MCP server.
|
|
33
|
+
|
|
34
|
+
## Using with Claude
|
|
35
|
+
|
|
36
|
+
Once configured, you can ask Claude to manage your development servers naturally:
|
|
37
|
+
|
|
38
|
+
### Starting Servers
|
|
39
|
+
|
|
40
|
+
> **You:** Start a Vite dev server for my React project
|
|
41
|
+
|
|
42
|
+
Claude will use `servherd_start` to start the server and tell you the assigned port:
|
|
43
|
+
|
|
44
|
+
> **Claude:** I've started your Vite development server. It's running at http://localhost:5173
|
|
45
|
+
|
|
46
|
+
### Listing Servers
|
|
47
|
+
|
|
48
|
+
> **You:** What servers are running?
|
|
49
|
+
|
|
50
|
+
> **Claude:** You have 2 servers running:
|
|
51
|
+
> - `frontend` (online) - http://localhost:5173 - /home/user/my-project
|
|
52
|
+
> - `api` (online) - http://localhost:3000 - /home/user/my-project/api
|
|
53
|
+
|
|
54
|
+
### Viewing Server Info
|
|
55
|
+
|
|
56
|
+
> **You:** Tell me about the frontend server
|
|
57
|
+
|
|
58
|
+
> **Claude:** Here's the status of your frontend server:
|
|
59
|
+
> - **Name:** frontend
|
|
60
|
+
> - **Status:** online
|
|
61
|
+
> - **URL:** http://localhost:5173
|
|
62
|
+
> - **Uptime:** 2 hours 15 minutes
|
|
63
|
+
> - **Memory:** 125 MB
|
|
64
|
+
> - **CPU:** 0.5%
|
|
65
|
+
|
|
66
|
+
### Checking Logs
|
|
67
|
+
|
|
68
|
+
> **You:** Show me the last few log lines from the api server
|
|
69
|
+
|
|
70
|
+
> **Claude:** Here are the recent logs from your api server:
|
|
71
|
+
> ```
|
|
72
|
+
> [12:34:56] Server listening on port 3000
|
|
73
|
+
> [12:35:01] GET /api/users - 200 (15ms)
|
|
74
|
+
> [12:35:03] POST /api/login - 200 (45ms)
|
|
75
|
+
> ```
|
|
76
|
+
|
|
77
|
+
### Stopping Servers
|
|
78
|
+
|
|
79
|
+
> **You:** Stop all the development servers
|
|
80
|
+
|
|
81
|
+
> **Claude:** I've stopped all your development servers:
|
|
82
|
+
> - frontend - stopped
|
|
83
|
+
> - api - stopped
|
|
84
|
+
|
|
85
|
+
## Practical Examples
|
|
86
|
+
|
|
87
|
+
### Full-Stack Development
|
|
88
|
+
|
|
89
|
+
> **You:** I'm working on a full-stack app with a React frontend and Express backend. Start both servers for me.
|
|
90
|
+
|
|
91
|
+
> **Claude:** I'll start both servers for you.
|
|
92
|
+
>
|
|
93
|
+
> Started:
|
|
94
|
+
> - Frontend (React/Vite): http://localhost:5173
|
|
95
|
+
> - Backend (Express): http://localhost:3001
|
|
96
|
+
>
|
|
97
|
+
> Both servers are now running and ready for development.
|
|
98
|
+
|
|
99
|
+
### Debugging
|
|
100
|
+
|
|
101
|
+
> **You:** The API is returning errors. Can you check the logs?
|
|
102
|
+
|
|
103
|
+
> **Claude:** Let me check the error logs for your API server...
|
|
104
|
+
>
|
|
105
|
+
> I found some errors in the logs:
|
|
106
|
+
> ```
|
|
107
|
+
> [ERROR] TypeError: Cannot read property 'id' of undefined
|
|
108
|
+
> at /src/routes/users.js:45:23
|
|
109
|
+
> ```
|
|
110
|
+
>
|
|
111
|
+
> It looks like there's an issue in your users route where it's trying to access an undefined object's `id` property.
|
|
112
|
+
|
|
113
|
+
### Resource Monitoring
|
|
114
|
+
|
|
115
|
+
> **You:** Is anything using too much memory?
|
|
116
|
+
|
|
117
|
+
> **Claude:** Let me check your servers' resource usage...
|
|
118
|
+
>
|
|
119
|
+
> | Server | Memory | CPU |
|
|
120
|
+
> |--------|--------|-----|
|
|
121
|
+
> | frontend | 125 MB | 0.5% |
|
|
122
|
+
> | api | 89 MB | 0.2% |
|
|
123
|
+
> | worker | 256 MB | 5.1% |
|
|
124
|
+
>
|
|
125
|
+
> The worker process is using the most memory at 256 MB and has higher CPU usage. This might be worth investigating if performance is a concern.
|
|
126
|
+
|
|
127
|
+
### Cleanup
|
|
128
|
+
|
|
129
|
+
> **You:** I'm done for the day. Clean up all my dev servers.
|
|
130
|
+
|
|
131
|
+
> **Claude:** I've cleaned up your development environment:
|
|
132
|
+
>
|
|
133
|
+
> Stopped and removed:
|
|
134
|
+
> - frontend
|
|
135
|
+
> - api
|
|
136
|
+
> - worker
|
|
137
|
+
>
|
|
138
|
+
> All servers have been stopped and removed from the registry.
|
|
139
|
+
|
|
140
|
+
## Available MCP Tools
|
|
141
|
+
|
|
142
|
+
| Tool | Description |
|
|
143
|
+
|------|-------------|
|
|
144
|
+
| `servherd_start` | Start a new development server |
|
|
145
|
+
| `servherd_stop` | Stop running servers |
|
|
146
|
+
| `servherd_restart` | Restart servers |
|
|
147
|
+
| `servherd_list` | List all managed servers |
|
|
148
|
+
| `servherd_info` | Get detailed server information |
|
|
149
|
+
| `servherd_logs` | View server logs |
|
|
150
|
+
| `servherd_remove` | Remove servers from registry |
|
|
151
|
+
| `servherd_config` | View/modify configuration |
|
|
152
|
+
|
|
153
|
+
## MCP Resources
|
|
154
|
+
|
|
155
|
+
Claude can also access these resources directly:
|
|
156
|
+
|
|
157
|
+
- `servherd://servers` - List of all servers
|
|
158
|
+
- `servherd://servers/{name}` - Details for a specific server
|
|
159
|
+
- `servherd://servers/{name}/logs` - Logs for a specific server
|
|
160
|
+
|
|
161
|
+
## Tips
|
|
162
|
+
|
|
163
|
+
### Natural Language
|
|
164
|
+
|
|
165
|
+
You don't need to know the exact commands. Just describe what you want:
|
|
166
|
+
|
|
167
|
+
- "Start my development server"
|
|
168
|
+
- "What's running right now?"
|
|
169
|
+
- "Stop the frontend but keep the API running"
|
|
170
|
+
- "Is the server healthy?"
|
|
171
|
+
|
|
172
|
+
### Context Awareness
|
|
173
|
+
|
|
174
|
+
Claude remembers previous actions in the conversation:
|
|
175
|
+
|
|
176
|
+
> **You:** Start a Vite server
|
|
177
|
+
> **Claude:** Started at http://localhost:5173
|
|
178
|
+
>
|
|
179
|
+
> **You:** What port is it on?
|
|
180
|
+
> **Claude:** Your Vite server is running on port 5173
|
|
181
|
+
|
|
182
|
+
### Error Handling
|
|
183
|
+
|
|
184
|
+
Claude will explain errors clearly:
|
|
185
|
+
|
|
186
|
+
> **You:** Start another server with the same name
|
|
187
|
+
> **Claude:** There's already a server named "frontend" running. Would you like me to:
|
|
188
|
+
> 1. Restart the existing server
|
|
189
|
+
> 2. Stop it and start a new one
|
|
190
|
+
> 3. Use a different name for the new server
|
|
191
|
+
|
|
192
|
+
## Troubleshooting
|
|
193
|
+
|
|
194
|
+
### MCP Server Not Connecting
|
|
195
|
+
|
|
196
|
+
1. Check configuration file syntax
|
|
197
|
+
2. Ensure servherd is installed: `npx servherd --version`
|
|
198
|
+
3. Try running manually: `npx servherd mcp`
|
|
199
|
+
4. Restart Claude Code
|
|
200
|
+
|
|
201
|
+
### Commands Not Working
|
|
202
|
+
|
|
203
|
+
1. Check if PM2 is installed: `pm2 --version`
|
|
204
|
+
2. Verify permissions on ~/.servherd directory
|
|
205
|
+
3. Check servherd logs for errors
|
|
206
|
+
|
|
207
|
+
### Getting Help
|
|
208
|
+
|
|
209
|
+
Ask Claude:
|
|
210
|
+
|
|
211
|
+
> **You:** What servherd commands are available?
|
|
212
|
+
|
|
213
|
+
Claude will list all available server management capabilities.
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
# Managing Multiple Servers
|
|
2
|
+
|
|
3
|
+
This example shows how to manage multiple development servers across projects using tags and naming conventions.
|
|
4
|
+
|
|
5
|
+
## Scenario: Full-Stack Application
|
|
6
|
+
|
|
7
|
+
A typical full-stack setup with frontend, backend, and background workers:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# Frontend (React/Vite)
|
|
11
|
+
servherd start --name frontend --tag web --tag dev -- npx vite --port {{port}}
|
|
12
|
+
|
|
13
|
+
# Backend API (Node/Express)
|
|
14
|
+
servherd start --name api --tag backend --tag dev -- npm run api --port {{port}}
|
|
15
|
+
|
|
16
|
+
# Background worker
|
|
17
|
+
servherd start --name worker --tag background --tag dev -- npm run worker
|
|
18
|
+
|
|
19
|
+
# Database admin (pgAdmin, etc.)
|
|
20
|
+
servherd start --name db-admin --tag tools --tag dev -- npm run db-admin --port {{port}}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Organizing with Tags
|
|
24
|
+
|
|
25
|
+
### By Layer
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# Frontend services
|
|
29
|
+
servherd start --name web --tag frontend -- npm run web --port {{port}}
|
|
30
|
+
servherd start --name mobile-api --tag frontend -- npm run mobile --port {{port}}
|
|
31
|
+
|
|
32
|
+
# Backend services
|
|
33
|
+
servherd start --name api --tag backend -- npm run api --port {{port}}
|
|
34
|
+
servherd start --name auth --tag backend -- npm run auth --port {{port}}
|
|
35
|
+
|
|
36
|
+
# Infrastructure
|
|
37
|
+
servherd start --name redis-ui --tag infra -- npm run redis-ui --port {{port}}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### By Environment
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
# Development
|
|
44
|
+
servherd start --name api --tag dev -- npm run dev --port {{port}}
|
|
45
|
+
|
|
46
|
+
# Staging
|
|
47
|
+
servherd start --name api-staging --tag staging -- npm run staging --port {{port}}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### By Project
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
# Project A
|
|
54
|
+
servherd start --name projecta-web --tag projecta -- npm run web --port {{port}}
|
|
55
|
+
servherd start --name projecta-api --tag projecta -- npm run api --port {{port}}
|
|
56
|
+
|
|
57
|
+
# Project B
|
|
58
|
+
servherd start --name projectb-web --tag projectb -- npm run web --port {{port}}
|
|
59
|
+
servherd start --name projectb-api --tag projectb -- npm run api --port {{port}}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Bulk Operations
|
|
63
|
+
|
|
64
|
+
### Stop by Tag
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
# Stop all frontend servers
|
|
68
|
+
servherd stop --tag frontend
|
|
69
|
+
|
|
70
|
+
# Stop all Project A servers
|
|
71
|
+
servherd stop --tag projecta
|
|
72
|
+
|
|
73
|
+
# Stop all dev servers
|
|
74
|
+
servherd stop --tag dev
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### List by Tag
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
# List all backend servers
|
|
81
|
+
servherd list --tag backend
|
|
82
|
+
|
|
83
|
+
# List running dev servers only
|
|
84
|
+
servherd list --tag dev --running
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Restart by Tag
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
# Restart all backend servers after config change
|
|
91
|
+
servherd restart --tag backend
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Remove by Tag
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
# Clean up staging servers
|
|
98
|
+
servherd remove --tag staging --force
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Microservices Example
|
|
102
|
+
|
|
103
|
+
Managing a microservices architecture:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
# API Gateway
|
|
107
|
+
servherd start --name gateway --tag core --tag api \
|
|
108
|
+
-- npm run gateway --port {{port}}
|
|
109
|
+
|
|
110
|
+
# User Service
|
|
111
|
+
servherd start --name users --tag core --tag api \
|
|
112
|
+
-- npm run users --port {{port}}
|
|
113
|
+
|
|
114
|
+
# Order Service
|
|
115
|
+
servherd start --name orders --tag core --tag api \
|
|
116
|
+
-- npm run orders --port {{port}}
|
|
117
|
+
|
|
118
|
+
# Payment Service
|
|
119
|
+
servherd start --name payments --tag core --tag api \
|
|
120
|
+
-- npm run payments --port {{port}}
|
|
121
|
+
|
|
122
|
+
# Notification Service
|
|
123
|
+
servherd start --name notifications --tag async --tag api \
|
|
124
|
+
-- npm run notifications --port {{port}}
|
|
125
|
+
|
|
126
|
+
# Email Worker
|
|
127
|
+
servherd start --name email-worker --tag async --tag worker \
|
|
128
|
+
-- npm run email-worker
|
|
129
|
+
|
|
130
|
+
# Report Generator
|
|
131
|
+
servherd start --name reports --tag async --tag worker \
|
|
132
|
+
-- npm run reports
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Managing the Stack
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
# View entire stack
|
|
139
|
+
servherd list
|
|
140
|
+
|
|
141
|
+
# View core services only
|
|
142
|
+
servherd list --tag core
|
|
143
|
+
|
|
144
|
+
# View async services
|
|
145
|
+
servherd list --tag async
|
|
146
|
+
|
|
147
|
+
# Restart all API services
|
|
148
|
+
servherd restart --tag api
|
|
149
|
+
|
|
150
|
+
# Stop workers only
|
|
151
|
+
servherd stop --tag worker
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Scripts for Common Operations
|
|
155
|
+
|
|
156
|
+
Create shell scripts for common tasks:
|
|
157
|
+
|
|
158
|
+
### start-all.sh
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
#!/bin/bash
|
|
162
|
+
set -e
|
|
163
|
+
|
|
164
|
+
echo "Starting development stack..."
|
|
165
|
+
|
|
166
|
+
# Core services
|
|
167
|
+
servherd start --name frontend --tag dev -- npm run frontend --port {{port}}
|
|
168
|
+
servherd start --name api --tag dev -- npm run api --port {{port}}
|
|
169
|
+
servherd start --name worker --tag dev -- npm run worker
|
|
170
|
+
|
|
171
|
+
# Wait for services to be ready
|
|
172
|
+
sleep 5
|
|
173
|
+
|
|
174
|
+
# Show status
|
|
175
|
+
servherd list --tag dev
|
|
176
|
+
|
|
177
|
+
echo "Development stack is running!"
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### stop-all.sh
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
#!/bin/bash
|
|
184
|
+
|
|
185
|
+
echo "Stopping development stack..."
|
|
186
|
+
servherd stop --tag dev
|
|
187
|
+
|
|
188
|
+
echo "Development stack stopped."
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### status.sh
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
#!/bin/bash
|
|
195
|
+
|
|
196
|
+
echo "=== Development Stack Status ==="
|
|
197
|
+
servherd list --tag dev
|
|
198
|
+
|
|
199
|
+
echo ""
|
|
200
|
+
echo "=== Resource Usage ==="
|
|
201
|
+
for server in $(servherd list --tag dev --json | jq -r '.[].name'); do
|
|
202
|
+
echo "--- $server ---"
|
|
203
|
+
servherd info $server | grep -E "(Memory|CPU|Uptime)"
|
|
204
|
+
done
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Monorepo Pattern
|
|
208
|
+
|
|
209
|
+
For monorepos with multiple packages:
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
# From repo root
|
|
213
|
+
PROJECT_ROOT=$(pwd)
|
|
214
|
+
|
|
215
|
+
# Start each package's dev server
|
|
216
|
+
cd $PROJECT_ROOT/packages/web
|
|
217
|
+
servherd start --name web --tag monorepo -- npm run dev --port {{port}}
|
|
218
|
+
|
|
219
|
+
cd $PROJECT_ROOT/packages/admin
|
|
220
|
+
servherd start --name admin --tag monorepo -- npm run dev --port {{port}}
|
|
221
|
+
|
|
222
|
+
cd $PROJECT_ROOT/packages/api
|
|
223
|
+
servherd start --name api --tag monorepo -- npm run dev --port {{port}}
|
|
224
|
+
|
|
225
|
+
cd $PROJECT_ROOT
|
|
226
|
+
servherd list --tag monorepo
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Tips
|
|
230
|
+
|
|
231
|
+
### Consistent Naming
|
|
232
|
+
|
|
233
|
+
Use consistent naming conventions:
|
|
234
|
+
|
|
235
|
+
```
|
|
236
|
+
{project}-{service} e.g., myapp-frontend, myapp-api
|
|
237
|
+
{service}-{env} e.g., api-dev, api-staging
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### Tag Hierarchy
|
|
241
|
+
|
|
242
|
+
Use multiple tags for flexible filtering:
|
|
243
|
+
|
|
244
|
+
```bash
|
|
245
|
+
# Tag by layer, project, and environment
|
|
246
|
+
--tag frontend --tag projecta --tag dev
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Quick Status Check
|
|
250
|
+
|
|
251
|
+
```bash
|
|
252
|
+
# See what's running
|
|
253
|
+
servherd list --running
|
|
254
|
+
|
|
255
|
+
# Count servers by tag
|
|
256
|
+
servherd list --tag dev | wc -l
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Resource Monitoring
|
|
260
|
+
|
|
261
|
+
```bash
|
|
262
|
+
# Check a specific server
|
|
263
|
+
servherd info api
|
|
264
|
+
|
|
265
|
+
# Quick memory check across all servers
|
|
266
|
+
for s in $(servherd list --json | jq -r '.[].name'); do
|
|
267
|
+
echo -n "$s: "
|
|
268
|
+
servherd info $s --json | jq -r '.memory // "not running"'
|
|
269
|
+
done
|
|
270
|
+
```
|