Skip to content

Latest commit

 

History

History
214 lines (150 loc) · 4.82 KB

File metadata and controls

214 lines (150 loc) · 4.82 KB

dev-control

A shell script utility for managing local development servers. Provides simple commands to start, stop, restart, and monitor multiple development servers with logging and process management.

Installation

1. Add to PATH (Make globally available)

Add this line to your ~/.zshrc or ~/.bash_profile:

export PATH="$PATH:/Users/stian/dev/scripts/dev-control"

Then reload your shell:

source ~/.zshrc  # or source ~/.bash_profile

2. Enable Aliases (Optional)

For convenient project-specific aliases, add this to your ~/.zshrc or ~/.bash_profile:

source /Users/stian/dev/scripts/dev-control/.dev-aliases

Then reload your shell:

source ~/.zshrc  # or source ~/.bash_profile

Usage

Once installed in PATH, you can run the script globally:

dev-start.sh [command]

Or if aliases are enabled:

sp [command]
sp-start
sp-stop
sp-status
sp-restart
sp-logs

Commands

Command Description
start Start both backend and frontend servers
stop Stop both servers
status Display detailed status of both servers (PID, ports, CPU, memory, URLs)
restart Restart both servers (stop + start)
logs Tail logs from both servers in real-time

Examples

# Start servers
dev-start.sh start

# Check status
dev-start.sh status

# View live logs
dev-start.sh logs

# Restart servers
dev-start.sh restart

# Stop servers
dev-start.sh stop

How It Works

The script is project-agnostic and works with any project structure:

  1. Project Root: Uses the directory where you run the script from (pwd)
  2. Backend Port: Defaults to 3001 (can be overridden with BACKEND_PORT=3002)
  3. Frontend Port: Defaults to 3000 (can be overridden with FRONTEND_PORT=3001)
  4. Log Directory: Creates .dev-logs/ in the project root
  5. PID Files: Stored in /tmp/ using project folder name for uniqueness

Using with Different Projects

Simply navigate to your project root and run:

cd /path/to/your/project
dev-start.sh start

Custom Ports

Override default ports by setting environment variables:

BACKEND_PORT=3002 FRONTEND_PORT=3001 dev-start.sh start

Multiple Projects

You can run multiple projects simultaneously. Each uses its own PID files based on the folder name:

# Project 1
cd /path/to/project1
dev-start.sh start

# Project 2 (in another terminal)
cd /path/to/project2
dev-start.sh start

Features

  • Dual Server Management: Control backend and frontend servers simultaneously
  • Process Tracking: Uses PID files to track running processes
  • Resource Monitoring: Displays CPU and memory usage in status view
  • Comprehensive Logging: Writes separate logs for backend and frontend
  • Color-Coded Output: Easy-to-read colored terminal output
  • Process Safety: Checks if processes are actually running before operations
  • Real-time Log Tailing: View both backend and frontend logs simultaneously

Logs Location

Logs are stored in the project's .dev-logs/ directory:

  • Backend: .dev-logs/backend.log
  • Frontend: .dev-logs/frontend.log

View logs manually:

tail -f /Users/stian/dev/splan.no/sp-utlegg2/.dev-logs/backend.log
tail -f /Users/stian/dev/splan.no/sp-utlegg2/.dev-logs/frontend.log

Aliases Reference

If you source .dev-aliases, you get these shortcuts:

sp-start                # Start servers
sp-stop                 # Stop servers
sp-status               # Check status
sp-restart              # Restart servers
sp-logs                 # View logs
sp-cd                   # Go to project root
sp-frontend             # Go to frontend directory
sp-backend              # Go to backend directory
sp-build                # Build both backend and frontend
sp-test                 # Run tests
sp [command]            # Generic sp command

Troubleshooting

Servers won't start

  1. Check if ports are already in use:

    lsof -i :3000  # Frontend
    lsof -i :3001  # Backend
  2. Review the logs:

    tail -f .dev-logs/backend.log
    tail -f .dev-logs/frontend.log

Stale PID files

If you see "already running" but servers aren't actually running, clean up:

rm /tmp/sp-utlegg2-backend.pid /tmp/sp-utlegg2-frontend.pid

Logs command not working

The logs command uses named pipes. If it hangs, kill it and try again:

dev-start.sh stop
rm /tmp/backend_pipe /tmp/frontend_pipe 2>/dev/null
dev-start.sh logs

Requirements

  • bash 4.0+
  • npm (for running dev servers)
  • Standard Unix utilities (ps, kill, mkdir, cat, sed)

Files

  • dev-start.sh - Main control script
  • .dev-aliases - Optional shell aliases for convenience
  • README.md - This documentation

License

Internal utility script for splan.no development