1---2name: server-management3description: ALWAYS use this when the request matches Server Management: Server management principles and decision-making.4---56# Server Management78## Selective Reading Rule910Start with:1112- `references/senior-master-standard.md`13- `references/usage-routing.md`14- `references/quality-checklist.md`1516Then load only the inherited docs, scripts, assets, or examples that match the user's actual task.1718> Server management principles for production operations.19> **Learn to THINK, not memorize commands.**2021---2223## 1. Process Management Principles2425### Tool Selection2627| Scenario | Tool |28|----------|------|29| **Node.js app** | PM2 (clustering, reload) |30| **Any app** | systemd (Linux native) |31| **Containers** | Docker/Podman |32| **Orchestration** | Kubernetes, Docker Swarm |3334### Process Management Goals3536| Goal | What It Means |37|------|---------------|38| **Restart on crash** | Auto-recovery |39| **Zero-downtime reload** | No service interruption |40| **Clustering** | Use all CPU cores |41| **Persistence** | Survive server reboot |4243---4445## 2. Monitoring Principles4647### What to Monitor4849| Category | Key Metrics |50|----------|-------------|51| **Availability** | Uptime, health checks |52| **Performance** | Response time, throughput |53| **Errors** | Error rate, types |54| **Resources** | CPU, memory, disk |5556### Alert Severity Strategy5758| Level | Response |59|-------|----------|60| **Critical** | Immediate action |61| **Warning** | Investigate soon |62| **Info** | Review daily |6364### Monitoring Tool Selection6566| Need | Options |67|------|---------|68| Simple/Free | PM2 metrics, htop |69| Full observability | Grafana, Datadog |70| Error tracking | Sentry |71| Uptime | UptimeRobot, Pingdom |7273---7475## 3. Log Management Principles7677### Log Strategy7879| Log Type | Purpose |80|----------|---------|81| **Application logs** | Debug, audit |82| **Access logs** | Traffic analysis |83| **Error logs** | Issue detection |8485### Log Principles86871. **Rotate logs** to prevent disk fill882. **Structured logging** (JSON) for parsing893. **Appropriate levels** (error/warn/info/debug)904. **No sensitive data** in logs9192---9394## 4. Scaling Decisions9596### When to Scale9798| Symptom | Solution |99|---------|----------|100| High CPU | Add instances (horizontal) |101| High memory | Increase RAM or fix leak |102| Slow response | Profile first, then scale |103| Traffic spikes | Auto-scaling |104105### Scaling Strategy106107| Type | When to Use |108|------|-------------|109| **Vertical** | Quick fix, single instance |110| **Horizontal** | Sustainable, distributed |111| **Auto** | Variable traffic |112113---114115## 5. Health Check Principles116117### What Constitutes Healthy118119| Check | Meaning |120|-------|---------|121| **HTTP 200** | Service responding |122| **Database connected** | Data accessible |123| **Dependencies OK** | External services reachable |124| **Resources OK** | CPU/memory not exhausted |125126### Health Check Implementation127128- Simple: Just return 200129- Deep: Check all dependencies130- Choose based on load balancer needs131132---133134## 6. Security Principles135136| Area | Principle |137|------|-----------|138| **Access** | SSH keys only, no passwords |139| **Firewall** | Only needed ports open |140| **Updates** | Regular security patches |141| **Secrets** | Environment vars, not files |142| **Audit** | Log access and changes |143144---145146## 7. Troubleshooting Priority147148When something's wrong:1491501. **Check if running** (process status)1512. **Check logs** (error messages)1523. **Check resources** (disk, memory, CPU)1534. **Check network** (ports, DNS)1545. **Check dependencies** (database, APIs)155156---157158## 8. Anti-Patterns159160| ❌ Don't | ✅ Do |161|----------|-------|162| Run as root | Use non-root user |163| Ignore logs | Set up log rotation |164| Skip monitoring | Monitor from day one |165| Manual restarts | Auto-restart config |166| No backups | Regular backup schedule |167168---169170> **Remember:** A well-managed server is boring. That's the goal.