====== systemd ====== Voir aussi [[/informatique/system_admin/journalctl|journalctl]] * https://systemd.io/ * https://www.freedesktop.org/software/systemd/man/latest/ Les directives: * https://www.freedesktop.org/software/systemd/man/latest/systemd.directives.html Outil d'analyse: * https://www.freedesktop.org/software/systemd/man/latest/systemd-analyze.html Pour envoyer une notification en cas d'échec d'exécution, créer un ''template service'' : * https://www.baeldung.com/linux/systemd-service-fail-notification * https://superuser.com/questions/1621517/having-all-systemd-timers-mail-to-root-on-error ''OnFailure'' est lié au démarrage du service. Pour traiter un retour d'erreur il faut créer un traitement dans ''ExecStopPost''. ===== Timer (Cron) ===== Avec Debian 12 (bookworm) cron/crontab n'est pas installé, il faut utiliser les [[https://www.freedesktop.org/software/systemd/man/latest/systemd.timer.html|systemd.timer]]. Pour la programmation voir la syntaxe [[https://www.freedesktop.org/software/systemd/man/latest/systemd.time.html#Calendar%20Events|Calendar Events]]. Pour tester la syntaxe OnCalendar: ''systemd-analyze calendar "*-*-* 00/2:00:00"'' Tutos pour créer des timers : - https://blog.stephane-robert.info/docs/admin-serveurs/linux/timers/ - https://www.siberoloji.com/how-to-use-systemd-timers-instead-of-cron-in-debian-12-bookworm/ ==== Exemple ==== les stats de livraison d'emails avec Postfix sur handipause.fr : Le service ''/etc/systemd/system/mail-stats.service'' # # Génère des stats de delivery pour Postfix # # Doc: # Timer: https://blog.stephane-robert.info/docs/admin-serveurs/linux/timers/ # Service: https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html # Unit: https://www.freedesktop.org/software/systemd/man/latest/systemd.unit.html # [Unit] Description=Génère qlqs stats Postfix # A space-separated list of one or more units that are activated when this unit enters the "failed" state. OnFailure=onfailure-email@%N.service [Service] Type=oneshot ExecStart=/usr/bin/php /home/debian/postfix-delivery-status/scripts/deliveryStats/deliveryStats.php /home/debian/postfix-delivery-status/conf/handipause.conf.php /var/www/html # Additional commands that are executed after the service is stopped. #ExecStopPost= Le timer ''/etc/systemd/system/mail-stats.timer'' [Unit] Description=Génère périodiquement qlqs stats Postfix [Timer] # https://www.freedesktop.org/software/systemd/man/latest/systemd.time.html# # check format with `systemd-analyze calendar "*-*-* 00/2:00:00"` OnCalendar=*-*-* 00/6:00:00 Persistent=true [Install] WantedBy=timers.target ===== Resolve ===== La gestion DSN par systemd. * [[https://www.malekal.com/configurer-cache-dns-linux-systemd-resolved-dnsmasq-bind/|Configurer un cache DNS sur Linux avec systemd-resolved, dnsmasq ou BIND]] * https://www.freedesktop.org/wiki/Software/systemd/writing-network-configuration-managers/ sudo systemctl status systemd-resolved.service # ========== $ sudo resolvectl status Global Protocols: +LLMNR +mDNS -DNSOverTLS DNSSEC=no/unsupported resolv.conf mode: uplink Link 2 (ens3) Current Scopes: DNS LLMNR/IPv4 LLMNR/IPv6 Protocols: +DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported Current DNS Server: 2001:41d0:3:163::1 DNS Servers: 2001:41d0:3:163::1 213.186.33.99 Link 3 (ens4) Current Scopes: DNS LLMNR/IPv4 LLMNR/IPv6 Protocols: +DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported Current DNS Server: 213.186.33.99 DNS Servers: 213.186.33.99 # ========== $ sudo resolvectl statistics DNSSEC supported by current servers: no Transactions Current Transactions: 0 Total Transactions: 2906 Cache Current Cache Size: 1 Cache Hits: 478 Cache Misses: 4417 DNSSEC Verdicts Secure: 0 Insecure: 0 Bogus: 0 Indeterminate: 0 # ========== $ sudo resolvectl query 1.1.1.1 1.1.1.1: one.one.one.one -- link: ens3 -- Information acquired via protocol DNS in 23.6ms. -- Data is authenticated: no; Data was acquired via local or encrypted transport: no -- Data from: network