feat: Add optional system optimizations to install script, refine cron job setup, and update related documentation.

This commit is contained in:
sebseb7
2025-12-18 14:41:48 +01:00
parent 374601f2fa
commit f7663c04c6
2 changed files with 88 additions and 8 deletions

View File

@@ -95,7 +95,7 @@ fswebcam -d /dev/video0 -r 1920x1080 --no-banner test.jpg
```bash ```bash
# View recent capture logs # View recent capture logs
tail -f /var/log/picupper.log tail -f ~/picUploadApi/demo/picupper.log
``` ```
### Common Issues ### Common Issues
@@ -116,8 +116,56 @@ crontab -e
``` ```
Examples: Examples:
- Every 5 minutes: `*/5 * * * * /home/pi/picupper-demo/capture-upload.sh` - Every 5 minutes: `*/5 * * * * ~/picUploadApi/demo/capture-upload.sh`
- Every 30 seconds: Use the included systemd timer (see advanced setup) - 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 ## Hardware Requirements
@@ -129,3 +177,4 @@ Examples:
## Network Notes ## Network Notes
The script retries failed uploads and logs all attempts. If your Pi loses network, captures continue and uploads resume when connectivity returns. The script retries failed uploads and logs all attempts. If your Pi loses network, captures continue and uploads resume when connectivity returns.

View File

@@ -60,20 +60,22 @@ echo "✓ Scripts are executable"
touch "$LOG_FILE" 2>/dev/null || true touch "$LOG_FILE" 2>/dev/null || true
echo "✓ Log file: $LOG_FILE" echo "✓ Log file: $LOG_FILE"
# Set up cron job # Set up cron job (script handles its own logging, no redirect needed)
CRON_JOB="* * * * * $CAPTURE_SCRIPT >> $LOG_FILE 2>&1" CRON_JOB="* * * * * $CAPTURE_SCRIPT"
echo "" echo ""
echo "Setting up cron job for 1 picture per minute..." echo "Setting up cron job for 1 picture per minute..."
# Check if cron job already exists # Check if cron job already exists
if crontab -l 2>/dev/null | grep -q "$CAPTURE_SCRIPT"; then 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 else
# Add to crontab # Add to crontab
(crontab -l 2>/dev/null || true; echo "$CRON_JOB") | crontab - (crontab -l 2>/dev/null || true; echo "$CRON_JOB") | crontab -
echo "✓ Cron job added"
fi fi
echo "✓ Cron job configured"
echo "" echo ""
echo "=== Installation Complete ===" echo "=== Installation Complete ==="
@@ -86,4 +88,33 @@ echo " Test capture: $CAPTURE_SCRIPT --test"
echo " Run manually: $CAPTURE_SCRIPT" echo " Run manually: $CAPTURE_SCRIPT"
echo " Uninstall: ${SCRIPT_DIR}/uninstall.sh" echo " Uninstall: ${SCRIPT_DIR}/uninstall.sh"
echo "" 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."