Securite deploiement : copie sans liens vers MC_SERVI, script Caddy hors du home, listes en NUL
- publier.copier_vers_servi : copie les seuls fichiers ordinaires de public/data vers MC_SERVI ; lien refuse dans la source, lien remplace (jamais suivi) dans la destination ; ecriture temporaire O_EXCL|O_NOFOLLOW puis os.replace. Caddy ne sert que /data depuis ce dossier. - Unite : MC_PUBLIC dans ~/meteo-collecte/public, MC_SERVI=/srv/weather.gastinel.me. - deployer-vps.sh : ne copie plus le script Caddy dans ~ ; il le depose dans ~/meteo-collecte/deploy et affiche son sha256 pour une installation root:root 755 dans /usr/local/sbin. Sauvegardes : noms passes en NUL sur stdin, pas de commande construite a partir des noms. - appliquer-caddy-meteo.sh : refuse si /srv/weather.gastinel.me est un lien. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Cette révision appartient à :
1 Parent
21f7fca8b6
révision
778825198e
8 fichiers modifiés
+679
-571
Aucun fichier ne correspond à votre recherche
@@ -1,74 +1,76 @@
|
||||
"""Ordonnanceur : lancé par le minuteur systemd toutes les 5 min (hh:x4 et hh:x9).
|
||||
|
||||
Chaque source décide seule si elle appelle :
|
||||
* ROMMA : au plus une requête global=1 toutes les 10 min ;
|
||||
* Infoclimat : passage principal à hh:x4 si une station est due, rattrapage ciblé à hh:x9.
|
||||
Puis publication des fichiers statiques et purge de la base (14 jours). Une source en erreur n'empêche
|
||||
ni l'autre source ni la publication.
|
||||
|
||||
python3 -m meteo_collecte.ordonnanceur # un tick
|
||||
python3 -m meteo_collecte.ordonnanceur --publier # republie sans aucun appel réseau
|
||||
python3 -m meteo_collecte.ordonnanceur --config # affiche la configuration (sans secret)
|
||||
"""
|
||||
import datetime as dt
|
||||
import sys
|
||||
|
||||
from . import infoclimat, publier, romma
|
||||
from .commun import UTC, Config, Journal, Verrou, lire_json
|
||||
from .stockage import Stockage
|
||||
|
||||
|
||||
def tick(cfg, maintenant=None, fetch_infoclimat=infoclimat.telecharger, fetch_romma=romma.telecharger,
|
||||
appels=True):
|
||||
maintenant = maintenant or dt.datetime.now(UTC)
|
||||
var = cfg.base / "var"
|
||||
journal = Journal(var / "collecte.log")
|
||||
with Verrou(var / ".collecte.lock") as obtenu:
|
||||
if not obtenu:
|
||||
return {"action": "verrou"} # un tick précédent tourne encore
|
||||
stockage = Stockage(var / "mesures.sqlite")
|
||||
resumes = {}
|
||||
try:
|
||||
if appels and cfg.romma_actif:
|
||||
resumes["romma"] = _sans_planter(journal, maintenant, "romma",
|
||||
lambda: romma.passer(cfg, stockage, journal, maintenant, fetch_romma))
|
||||
if appels and cfg.infoclimat_actif:
|
||||
stations = lire_json(cfg.stations, {}).get("infoclimat", {})
|
||||
resumes["infoclimat"] = _sans_planter(journal, maintenant, "infoclimat", lambda: infoclimat.passer(
|
||||
cfg, stockage, journal, maintenant, stations, fetch=fetch_infoclimat))
|
||||
stockage.purger(maintenant, cfg.garder_jours)
|
||||
resumes["publiees"] = publier.publier(cfg, stockage, maintenant, resumes)
|
||||
finally:
|
||||
stockage.fermer()
|
||||
return resumes
|
||||
|
||||
|
||||
def _sans_planter(journal, maintenant, nom, f):
|
||||
try:
|
||||
return f()
|
||||
except Exception as e: # bug local (disque, base…) : journalisé, la suite du tick continue
|
||||
journal("ERREUR interne %s : %s" % (nom, str(e)[:300]), maintenant)
|
||||
return {"source": nom, "action": "erreur_interne"}
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
argv = sys.argv[1:] if argv is None else argv
|
||||
cfg = Config.depuis_env()
|
||||
if "--config" in argv:
|
||||
for k, v in vars(cfg).items():
|
||||
if k == "env":
|
||||
continue # l'environnement contient les secrets : jamais affiché
|
||||
print("%-20s %s" % (k, v)) # chemins et noms de variables seulement
|
||||
for nom in (cfg.var_jeton_infoclimat, cfg.var_cle_romma):
|
||||
try:
|
||||
cfg.secret(nom)
|
||||
print("%-20s définie (valeur masquée)" % nom)
|
||||
except LookupError:
|
||||
print("%-20s absente" % nom)
|
||||
return 0
|
||||
tick(cfg, appels="--publier" not in argv)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
"""Ordonnanceur : lancé par le minuteur systemd toutes les 5 min (hh:x4 et hh:x9).
|
||||
|
||||
Chaque source décide seule si elle appelle :
|
||||
* ROMMA : au plus une requête global=1 toutes les 10 min ;
|
||||
* Infoclimat : passage principal à hh:x4 si une station est due, rattrapage ciblé à hh:x9.
|
||||
Puis publication des fichiers statiques et purge de la base (14 jours). Une source en erreur n'empêche
|
||||
ni l'autre source ni la publication.
|
||||
|
||||
python3 -m meteo_collecte.ordonnanceur # un tick
|
||||
python3 -m meteo_collecte.ordonnanceur --publier # republie sans aucun appel réseau
|
||||
python3 -m meteo_collecte.ordonnanceur --config # affiche la configuration (sans secret)
|
||||
"""
|
||||
import datetime as dt
|
||||
import sys
|
||||
|
||||
from . import infoclimat, publier, romma
|
||||
from .commun import UTC, Config, Journal, Verrou, lire_json
|
||||
from .stockage import Stockage
|
||||
|
||||
|
||||
def tick(cfg, maintenant=None, fetch_infoclimat=infoclimat.telecharger, fetch_romma=romma.telecharger,
|
||||
appels=True):
|
||||
maintenant = maintenant or dt.datetime.now(UTC)
|
||||
var = cfg.base / "var"
|
||||
journal = Journal(var / "collecte.log")
|
||||
with Verrou(var / ".collecte.lock") as obtenu:
|
||||
if not obtenu:
|
||||
return {"action": "verrou"} # un tick précédent tourne encore
|
||||
stockage = Stockage(var / "mesures.sqlite")
|
||||
resumes = {}
|
||||
try:
|
||||
if appels and cfg.romma_actif:
|
||||
resumes["romma"] = _sans_planter(journal, maintenant, "romma",
|
||||
lambda: romma.passer(cfg, stockage, journal, maintenant, fetch_romma))
|
||||
if appels and cfg.infoclimat_actif:
|
||||
stations = lire_json(cfg.stations, {}).get("infoclimat", {})
|
||||
resumes["infoclimat"] = _sans_planter(journal, maintenant, "infoclimat", lambda: infoclimat.passer(
|
||||
cfg, stockage, journal, maintenant, stations, fetch=fetch_infoclimat))
|
||||
stockage.purger(maintenant, cfg.garder_jours)
|
||||
resumes["publiees"] = publier.publier(cfg, stockage, maintenant, resumes)
|
||||
if cfg.servi:
|
||||
resumes["servies"] = publier.copier_vers_servi(cfg.public, cfg.servi)
|
||||
finally:
|
||||
stockage.fermer()
|
||||
return resumes
|
||||
|
||||
|
||||
def _sans_planter(journal, maintenant, nom, f):
|
||||
try:
|
||||
return f()
|
||||
except Exception as e: # bug local (disque, base…) : journalisé, la suite du tick continue
|
||||
journal("ERREUR interne %s : %s" % (nom, str(e)[:300]), maintenant)
|
||||
return {"source": nom, "action": "erreur_interne"}
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
argv = sys.argv[1:] if argv is None else argv
|
||||
cfg = Config.depuis_env()
|
||||
if "--config" in argv:
|
||||
for k, v in vars(cfg).items():
|
||||
if k == "env":
|
||||
continue # l'environnement contient les secrets : jamais affiché
|
||||
print("%-20s %s" % (k, v)) # chemins et noms de variables seulement
|
||||
for nom in (cfg.var_jeton_infoclimat, cfg.var_cle_romma):
|
||||
try:
|
||||
cfg.secret(nom)
|
||||
print("%-20s définie (valeur masquée)" % nom)
|
||||
except LookupError:
|
||||
print("%-20s absente" % nom)
|
||||
return 0
|
||||
tick(cfg, appels="--publier" not in argv)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Référencer dans un nouveau ticket
Bloquer un utilisateur