Start Script Reference¶
The Heritage Data Processor Start Script (start_hdp.sh) performs pre-start validation and launches the application with proper environment configuration.
Overview¶
This script validates the installation, activates the Python environment, verifies dependencies, and starts the application through npm.
Usage¶
Basic Usage¶
Performs all checks in standard mode (warnings only for version mismatches).
Command-Line Options¶
Options:
--strict: Fail on any version mismatches or outdated packages. Default: warn only--help: Display usage information and exit
Usage Examples¶
Example 1: Standard Start¶
Performs all checks, warns about issues but continues unless critical.
Example 2: Strict Mode¶
Fails immediately if any version mismatches or outdated packages are detected.
Example 3: Help Information¶
Displays usage information:
Usage: ./start_hdp.sh [--strict]
Options:
--strict Fail on any version mismatches (default: warn only)
--help Show this help message
Requirements¶
Prerequisites¶
- Installation: Complete installation must be finished first
- Working Directory: Must be run from project root directory
- Virtual Environment:
.venvdirectory must exist with proper Python installation - Node Modules:
node_modulesdirectory must exist
Startup Steps¶
Step 1: Project Structure Validation¶
Verifies the script is running from the correct directory.
Validation Checks:
- Presence of
package.json - Presence of
requirements.txt
Error Message:
🔴 Not in project root directory.
This script must be run from the Heritage Data Processor root directory.
Expected files:
- package.json
- requirements.txt
Current directory: /home/user/wrong-location
Step 2: Virtual Environment Activation¶
Activates the Python virtual environment located at .venv.
Process:
- Existence Check: Verifies
.venvdirectory exists - Activation Script: Sources
.venv/bin/activate - Verification: Confirms
VIRTUAL_ENVenvironment variable is set - Version Display: Shows activated Python version
Error Scenarios:
Virtual Environment Not Found:
Activation Script Missing:
🔴 Virtual environment activation script not found.
Virtual environment may be corrupted. Try:
rm -rf .venv
uv venv .venv --python=3.11
Activation Failed:
Step 3: Python Dependencies Verification¶
Validates that all required Python packages are installed with correct versions.
Verification Process:
- Parse Requirements: Reads
requirements.txtline by line, skipping comments and empty lines - List Installed: Uses
uv pip list --format=freezeto get installed packages - Match Packages: Performs case-insensitive comparison (PyPI is case-insensitive)
- Version Check: For packages with
==version specifiers, verifies exact match
Package Extraction:
Uses regex to extract package name before operators:
Missing Packages:
🔴 Missing Python packages (3):
- flask==2.3.0
- pandas==2.0.0
- requests==2.28.0
Install missing packages:
uv pip install -r requirements.txt
Version Mismatches:
In standard mode (default):
⚠️ Version mismatches detected (2):
- numpy: required 1.24.0, installed 1.23.5
- scipy: required 1.10.1, installed 1.10.0
⚠️ Continuing despite version mismatches (use --strict to fail)
[INFO] To fix mismatches, run: uv pip install -r requirements.txt
In strict mode (--strict):
🔴 Version mismatches found in strict mode.
Update dependencies:
uv pip install -r requirements.txt --upgrade
Success Message:
Step 4: Node.js Dependencies Verification¶
Validates Node.js dependencies are installed and checks for outdated packages.
Checks Performed:
- npm Availability: Verifies npm command is accessible
- node_modules Existence: Confirms directory exists
- package.json Existence: Validates package file is present
- Start Script: Verifies
startscript is defined in package.json - Outdated Check: Runs
npm outdatedto detect outdated packages
Module Count:
Reports number of installed modules:
Outdated Packages:
In standard mode:
⚠️ Found 12 outdated Node.js package(s)
⚠️ Run 'npm outdated' to see details
[INFO] Continuing despite outdated packages (use --strict to fail)
In strict mode:
Missing Start Script:
🔴 No 'start' script defined in package.json.
Add a start script to package.json:
"scripts": {
"start": "your-start-command"
}
Step 5: Application Startup¶
Launches the application using npm start.
Environment Export:
Before starting, exports virtual environment variables for child processes:
Execution:
Output Streaming:
All npm output is displayed in real-time and logged to the log file.
Process Control:
The script runs in the foreground and takes over the terminal until the application is stopped (Ctrl+C).
Failure Handling:
If npm start exits with non-zero code:
🔴 Application exited with error.
Check the log file: start_hdp_20251021_143500.log
Check application logs for more details
Logging¶
Log File¶
Format: start_hdp_YYYYMMDD_HHMMSS.log
Content: Captures all validation steps, checks, and application output
Location: Created in current working directory
Log Functions¶
Available Functions:
error_exit(): Logs error and exits with code 1warning(): Logs warning with yellow colorinfo(): Logs informational messagesuccess(): Logs success with green checkmarkdebug(): Logs debug information in bluestep_header(): Displays cyan-colored section headers
Error Handling¶
Exit on Error¶
The script uses set -euo pipefail for strict error handling:
set -e: Exit on any command failureset -u: Exit on undefined variable referenceset -o pipefail: Exit if any command in pipeline fails
Cleanup Trap¶
Registers cleanup function to deactivate virtual environment on exit: