v1.7.4: Source de verite unique pour les services + update self-healing
setup_services.sh devient la source unique pour les services systemd (le service rtc_save_to_db etait auparavant cree inline dans installation_part2.sh, en doublon avec un commentaire dans save_to_db.py). update_firmware.sh appelle maintenant setup_services.sh apres le git pull. Resultat: les capteurs deja deployes peuvent se reparer tout seuls au prochain update firmware (services manquants, masques, ou nouveaux services ajoutes au repo apres l'installation initiale). Defensif: systemctl unmask sur rtc_save_to_db avant creation du fichier .service, pour eviter d'ecrire dans /dev/null si le service avait ete masque (cas observe sur un capteur en production). Pas de risque sur les capteurs sains: reecriture des .service avec le meme contenu, comportement inchange. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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" <<EOF
|
||||
[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
|
||||
EOF
|
||||
|
||||
success "Systemd service file created: $SERVICE_FILE_2"
|
||||
|
||||
# Reload systemd to recognize the new service
|
||||
info "Reloading systemd daemon..."
|
||||
sudo systemctl daemon-reload
|
||||
|
||||
# Enable the service to start on boot
|
||||
info "Enabling the service to start on boot..."
|
||||
sudo systemctl enable rtc_save_to_db.service
|
||||
|
||||
# Start the service immediately
|
||||
info "Starting the service..."
|
||||
sudo systemctl start rtc_save_to_db.service
|
||||
|
||||
# Display device information
|
||||
echo ""
|
||||
echo "=========================================="
|
||||
|
||||
@@ -321,6 +321,28 @@ RemainAfterExit=yes
|
||||
WantedBy=multi-user.target
|
||||
EOL
|
||||
|
||||
# Create service file for RTC Save to DB (long-running service, no timer)
|
||||
# Unmask first in case it was previously masked (symlink to /dev/null)
|
||||
# so the cat below writes a real file, not into /dev/null.
|
||||
systemctl unmask rtc_save_to_db.service 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
|
||||
|
||||
|
||||
@@ -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..."
|
||||
|
||||
Reference in New Issue
Block a user