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:
@@ -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 "=========================================="
|
||||
|
||||
Reference in New Issue
Block a user