Add wakeup.sh script for convenient development server startup: - Port 8000 availability check before starting - Automatic virtual environment activation - Log file management in logs/ directory - Fresh log file on each startup (clears previous logs) - Colored output for better visibility - Real-time logging to both console and file - Helpful error messages with troubleshooting commands
51 lines
1.3 KiB
Bash
Executable File
51 lines
1.3 KiB
Bash
Executable File
|
|
|
|
#!/bin/bash
|
|
# Tatlock Server Startup Script
|
|
|
|
set -e
|
|
|
|
# Colors for output
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
RED='\033[0;31m'
|
|
NC='\033[0m' # No Color
|
|
|
|
echo -e "${GREEN}Starting Tatlock server...${NC}"
|
|
|
|
# Check if port 8000 is already in use
|
|
if lsof -Pi :8000 -sTCP:LISTEN -t >/dev/null 2>&1 ; then
|
|
echo -e "${RED}Error: Port 8000 is already in use${NC}"
|
|
echo "Run: lsof -i :8000 to see what's using it"
|
|
echo "Or run: kill \$(lsof -t -i:8000) to stop it"
|
|
exit 1
|
|
fi
|
|
|
|
# Activate virtual environment if not already activated
|
|
if [ -z "$VIRTUAL_ENV" ]; then
|
|
if [ -d ".venv" ]; then
|
|
echo -e "${YELLOW}Activating virtual environment...${NC}"
|
|
source .venv/bin/activate
|
|
else
|
|
echo -e "${RED}Error: Virtual environment not found${NC}"
|
|
echo "Run: python -m venv .venv && source .venv/bin/activate && pip install -r requirements.txt"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Create logs directory if it doesn't exist
|
|
LOGS_DIR="logs"
|
|
mkdir -p "$LOGS_DIR"
|
|
|
|
# Clear/create log file
|
|
LOG_FILE="$LOGS_DIR/server.log"
|
|
> "$LOG_FILE"
|
|
echo -e "${YELLOW}Logs will be written to: ${LOG_FILE}${NC}"
|
|
|
|
# Start the server
|
|
echo -e "${GREEN}Starting uvicorn server on http://localhost:8000${NC}"
|
|
echo -e "${YELLOW}Press Ctrl+C to stop the server${NC}"
|
|
echo ""
|
|
|
|
uvicorn src.main:app --reload --host 0.0.0.0 --port 8000 2>&1 | tee "$LOG_FILE"
|