From f7663c04c63ff770a467d3d2849f59be6a1ff504 Mon Sep 17 00:00:00 2001 From: sebseb7 Date: Thu, 18 Dec 2025 14:41:48 +0100 Subject: [PATCH] feat: Add optional system optimizations to install script, refine cron job setup, and update related documentation. --- demo/README.md | 55 ++++++++++++++++++++++++++++++++++++++++++++++--- demo/install.sh | 41 +++++++++++++++++++++++++++++++----- 2 files changed, 88 insertions(+), 8 deletions(-) diff --git a/demo/README.md b/demo/README.md index 82d2cdd..71c4a1f 100644 --- a/demo/README.md +++ b/demo/README.md @@ -95,7 +95,7 @@ fswebcam -d /dev/video0 -r 1920x1080 --no-banner test.jpg ```bash # View recent capture logs -tail -f /var/log/picupper.log +tail -f ~/picUploadApi/demo/picupper.log ``` ### Common Issues @@ -116,8 +116,56 @@ crontab -e ``` Examples: -- Every 5 minutes: `*/5 * * * * /home/pi/picupper-demo/capture-upload.sh` -- Every 30 seconds: Use the included systemd timer (see advanced setup) +- Every 5 minutes: `*/5 * * * * ~/picUploadApi/demo/capture-upload.sh` +- Every 30 seconds: Use systemd timer instead of cron + +--- + +## SD Card Preservation + +Reduce SD card writes to extend its lifetime: + +### Option 1: Minimal Changes (Recommended) + +```bash +# Disable swap +sudo swapoff -a +# Comment out swap line in /etc/fstab +sudo nano /etc/fstab + +# Disable automatic apt updates +sudo systemctl disable apt-daily.timer apt-daily-upgrade.timer +``` + +### Option 2: Full Read-Only Mode + +```bash +sudo raspi-config +# Navigate to: Performance Options → Overlay File System → Enable +``` + +⚠️ **Before enabling read-only mode**, change log location to tmpfs: +```bash +# Edit picupper.conf +LOG_FILE="/tmp/picupper.log" +``` + +--- + +## Auto-Reboot (Stability) + +For long-running deployments, schedule automatic reboots: + +```bash +sudo crontab -e +``` + +Add (reboots at 00:00, 06:00, 12:00, 18:00): +``` +0 */6 * * * /sbin/reboot +``` + +--- ## Hardware Requirements @@ -129,3 +177,4 @@ Examples: ## Network Notes The script retries failed uploads and logs all attempts. If your Pi loses network, captures continue and uploads resume when connectivity returns. + diff --git a/demo/install.sh b/demo/install.sh index 9dbb939..7fd9046 100644 --- a/demo/install.sh +++ b/demo/install.sh @@ -60,20 +60,22 @@ echo "✓ Scripts are executable" touch "$LOG_FILE" 2>/dev/null || true echo "✓ Log file: $LOG_FILE" -# Set up cron job -CRON_JOB="* * * * * $CAPTURE_SCRIPT >> $LOG_FILE 2>&1" +# Set up cron job (script handles its own logging, no redirect needed) +CRON_JOB="* * * * * $CAPTURE_SCRIPT" echo "" echo "Setting up cron job for 1 picture per minute..." # Check if cron job already exists if crontab -l 2>/dev/null | grep -q "$CAPTURE_SCRIPT"; then - echo "⚠ Cron job already exists, skipping" + echo "⚠ Cron job already exists, updating..." + # Remove old entry and add new one + (crontab -l 2>/dev/null | grep -v "$CAPTURE_SCRIPT"; echo "$CRON_JOB") | crontab - else # Add to crontab (crontab -l 2>/dev/null || true; echo "$CRON_JOB") | crontab - - echo "✓ Cron job added" fi +echo "✓ Cron job configured" echo "" echo "=== Installation Complete ===" @@ -86,4 +88,33 @@ echo " Test capture: $CAPTURE_SCRIPT --test" echo " Run manually: $CAPTURE_SCRIPT" echo " Uninstall: ${SCRIPT_DIR}/uninstall.sh" echo "" -echo "To change frequency, edit crontab: crontab -e" + +# Offer optional optimizations +echo "=== Optional: System Optimizations ===" +echo "" +read -p "Disable swap & apt-updates to preserve SD card? [y/N] " -n 1 -r +echo "" +if [[ $REPLY =~ ^[Yy]$ ]]; then + echo "Disabling swap..." + sudo swapoff -a 2>/dev/null || true + echo "Disabling apt-daily timers..." + sudo systemctl disable apt-daily.timer apt-daily-upgrade.timer 2>/dev/null || true + echo "✓ SD card preservation enabled" +fi + +echo "" +read -p "Set up auto-reboot every 6 hours for stability? [y/N] " -n 1 -r +echo "" +if [[ $REPLY =~ ^[Yy]$ ]]; then + REBOOT_JOB="0 */6 * * * /sbin/reboot" + if sudo crontab -l 2>/dev/null | grep -q "/sbin/reboot"; then + echo "⚠ Reboot cron already exists, skipping" + else + (sudo crontab -l 2>/dev/null || true; echo "$REBOOT_JOB") | sudo crontab - + echo "✓ Auto-reboot scheduled (00:00, 06:00, 12:00, 18:00)" + fi +fi + +echo "" +echo "Setup complete! First capture will happen at the next minute." +