diff --git a/RTC/save_to_db.py b/RTC/save_to_db.py index 19e8c58..ee99354 100755 --- a/RTC/save_to_db.py +++ b/RTC/save_to_db.py @@ -1,45 +1,15 @@ ''' - ____ _____ ____ + ____ _____ ____ | _ \_ _/ ___| - | |_) || || | - | _ < | || |___ + | |_) || || | + | _ < | || |___ |_| \_\|_| \____| - + Script to read time from RTC module and save it to DB -I2C connection -Address 0x68 -/usr/bin/python3 /var/www/nebuleair_pro_4g/RTC/save_to_db.py - -This need to be run as a system service - ---> sudo nano /etc/systemd/system/rtc_save_to_db.service - -⬇️ -[Unit] -Description=RTC Save to DB Script -After=network.target - -[Service] -ExecStart=/usr/bin/python3 /var/www/nebuleair_pro_4g/RTC/save_to_db.py -Restart=always -RestartSec=1 -User=root -WorkingDirectory=/var/www/nebuleair_pro_4g -StandardOutput=append:/var/www/nebuleair_pro_4g/logs/rtc_save_to_db.log -StandardError=append:/var/www/nebuleair_pro_4g/logs/rtc_save_to_db_errors.log - -[Install] -WantedBy=multi-user.target -⬆️ - - -sudo systemctl daemon-reload -sudo systemctl enable rtc_save_to_db.service - -sudo systemctl start rtc_save_to_db.service - -sudo systemctl status rtc_save_to_db.service +I2C connection - Address 0x68 +Runs as a long-running systemd service (rtc_save_to_db.service). +The service file is created by services/setup_services.sh — single source of truth. ''' import smbus2 import time diff --git a/VERSION b/VERSION index 661e7ae..10c0880 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.7.3 +1.7.4 diff --git a/changelog.json b/changelog.json index e553461..60845a2 100644 --- a/changelog.json +++ b/changelog.json @@ -1,5 +1,26 @@ { "versions": [ + { + "version": "1.7.4", + "date": "2026-05-12", + "changes": { + "features": [], + "improvements": [ + "Services systemd: source de verite unique dans services/setup_services.sh (le service rtc_save_to_db etait auparavant cree inline dans installation_part2.sh)", + "update_firmware.sh: appelle maintenant setup_services.sh apres git pull (self-healing des services manquants/masques sur les capteurs deja deployes)", + "setup_services.sh: systemctl unmask defensif sur rtc_save_to_db avant creation du fichier (evite l'ecriture dans /dev/null si le service avait ete masque)" + ], + "fixes": [ + "Bug observe sur capteur deployé: rtc_save_to_db.service masque -> timestamp_table reste a 'not connected' -> RTC affiche comme non connecte dans les logs SARA alors que le materiel fonctionne. L'update firmware ne reparait pas cette situation. Avec v1.7.4, un simple update firmware repare automatiquement." + ], + "compatibility": [ + "Aucun risque sur les capteurs sains: les fichiers .service sont reecrits avec le meme contenu, comportement inchange", + "Capteurs avec services manquants/masques: seront repares automatiquement au prochain update firmware", + "Aucune migration manuelle requise" + ] + }, + "notes": "Reorganisation interne du provisionnement des services systemd. installation_part2.sh ne contient plus la definition inline du service RTC (deduplique). save_to_db.py ne contient plus les instructions systemd en commentaire (deduplique). update_firmware.sh devient self-healing pour les services." + }, { "version": "1.7.3", "date": "2026-05-12", diff --git a/installation_part2.sh b/installation_part2.sh index 2153f56..20cb236 100644 --- a/installation_part2.sh +++ b/installation_part2.sh @@ -72,13 +72,10 @@ imsi_number=$(echo "$imsi_output" | grep -oP '^\d{15}$' || echo "N/A") #info "Connect SARA R4 to network" #python3 /var/www/nebuleair_pro_4g/SARA/sara_connectNetwork.py ttyAMA2 20810 60 -#Need to create the two service -# 1. start the scripts to set-up the services -# 2. rtc_save_to_db - -#1. set-up the services (SARA, NPM, BME280, etc) +# Set up all systemd services (SARA, NPM, BME280, RTC save_to_db, etc.) +# Single source of truth: services/setup_services.sh info "Setting up systemd services..." - + if [[ -f "$REPO_DIR/services/setup_services.sh" ]]; then sudo chmod +x "$REPO_DIR/services/setup_services.sh" sudo "$REPO_DIR/services/setup_services.sh" || warning "Failed to set up systemd services" @@ -87,43 +84,6 @@ else warning "Systemd services setup script not found." fi -#2. Add rtc_save_to_db.service -SERVICE_FILE_2="/etc/systemd/system/rtc_save_to_db.service" -info "Setting up systemd service for rtc_save_to_db..." - -# Create the systemd service file (overwrite if necessary) -sudo bash -c "cat > $SERVICE_FILE_2" </dev/null || true +cat > /etc/systemd/system/rtc_save_to_db.service << 'EOL' +[Unit] +Description=RTC Save to DB Script +After=network.target + +[Service] +ExecStart=/usr/bin/python3 /var/www/nebuleair_pro_4g/RTC/save_to_db.py +Restart=always +RestartSec=1 +User=root +WorkingDirectory=/var/www/nebuleair_pro_4g +StandardOutput=append:/var/www/nebuleair_pro_4g/logs/rtc_save_to_db.log +StandardError=append:/var/www/nebuleair_pro_4g/logs/rtc_save_to_db_errors.log + +[Install] +WantedBy=multi-user.target +EOL + # Reload systemd to recognize new services systemctl daemon-reload @@ -342,6 +364,13 @@ systemctl enable nebuleair-cpu-power.service systemctl start nebuleair-cpu-power.service echo "Started nebuleair-cpu-power service" +# Enable and start RTC Save to DB service (long-running, no timer) +# Use restart instead of start to pick up new content if the service was +# already running with an older version of the file. +systemctl enable rtc_save_to_db.service +systemctl restart rtc_save_to_db.service +echo "Started rtc_save_to_db service" + echo "Checking status of all timers..." systemctl list-timers | grep nebuleair diff --git a/update_firmware.sh b/update_firmware.sh index 658ea6f..6cf2a35 100755 --- a/update_firmware.sh +++ b/update_firmware.sh @@ -107,6 +107,20 @@ if [ "${APACHE_CHANGED:-false}" = true ]; then print_status "✓ Apache reloaded" fi +# Step 3c: Reconcile systemd services with the repo (self-heal) +# Re-running setup_services.sh ensures any service that was removed, +# masked, or never installed gets recreated from the canonical source. +# Idempotent: rewriting an existing service file with the same content +# is a no-op for already-running services. +print_status "" +print_status "Step 3c: Reconciling systemd services with setup_services.sh..." +if [ -x /var/www/nebuleair_pro_4g/services/setup_services.sh ]; then + sudo /var/www/nebuleair_pro_4g/services/setup_services.sh + check_status "Setup services reconciliation" +else + print_status "⚠ setup_services.sh not found or not executable, skipping" +fi + # Step 4: Restart critical services if they exist print_status "" print_status "Step 4: Managing system services..."