Update Docker configuration, enhance error handling, and improve logging

- Added health check to the camera management API service in docker-compose.yml for better container reliability.
- Updated installation scripts in Dockerfile to check for existing dependencies before installation, improving efficiency.
- Enhanced error handling in the USDAVisionSystem class to allow partial operation if some components fail to start, preventing immediate shutdown.
- Improved logging throughout the application, including more detailed error messages and critical error handling in the main loop.
- Refactored WebSocketManager and CameraMonitor classes to use debug logging for connection events, reducing log noise.
This commit is contained in:
salirezav
2025-12-03 17:23:31 -05:00
parent 2bce817b4e
commit 933d4417a5
30 changed files with 4314 additions and 220 deletions

View File

@@ -6,6 +6,12 @@ services:
dockerfile: Dockerfile
working_dir: /app
restart: unless-stopped # Automatically restart container if it fails or exits
healthcheck:
test: ["CMD-SHELL", "python3 -c 'import urllib.request; urllib.request.urlopen(\"http://localhost:8000/health\").read()' || exit 1"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
volumes:
- ./camera-management-api:/app
- /mnt/nfs_share:/mnt/nfs_share
@@ -20,29 +26,42 @@ services:
- MEDIAMTX_RTSP_PORT=8554
command: >
sh -lc "
apt-get update && apt-get install -y libusb-1.0-0-dev ffmpeg;
set -e # Exit on error
# Only install system packages if not already installed (check for ffmpeg)
if ! command -v ffmpeg &> /dev/null; then
echo 'Installing system dependencies...';
apt-get update && apt-get install -y --no-install-recommends libusb-1.0-0-dev ffmpeg;
else
echo 'System dependencies already installed';
fi
# Install camera SDK if not already installed
if [ ! -f /lib/libMVSDK.so ] && [ -f 'camera_sdk/linuxSDK_V2.1.0.49(250108)/install.sh' ]; then
echo 'Installing camera SDK...';
cd 'camera_sdk/linuxSDK_V2.1.0.49(250108)';
chmod +x install.sh;
./install.sh;
./install.sh || echo 'Warning: Camera SDK installation may have failed';
cd /app;
echo 'Camera SDK installed successfully';
else
echo 'Camera SDK already installed or install script not found';
fi;
# Install Python dependencies
# Install Python dependencies (only if requirements.txt changed or packages missing)
if [ -f requirements.txt ]; then
pip install --no-cache-dir -r requirements.txt;
pip install --no-cache-dir -r requirements.txt || echo 'Warning: Some Python packages may have failed to install';
else
pip install --no-cache-dir -e .;
pip install --no-cache-dir -e . || echo 'Warning: Package installation may have failed';
fi;
# Start the application
python main.py --config config.compose.json
# Start the application with error handling
echo 'Starting USDA Vision Camera System...';
python main.py --config config.compose.json || {
echo 'Application exited with error code: $?';
echo 'Waiting 5 seconds before exit...';
sleep 5;
exit 1;
}
"
network_mode: host