doc:appunti:linux:sa:systemd
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| doc:appunti:linux:sa:systemd [2017/11/07 10:22] – [Servizi, Unit file, ...] niccolo | doc:appunti:linux:sa:systemd [2025/07/04 14:43] (current) – [Verifica dipendenze servizi] niccolo | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Systemd ====== | ====== Systemd ====== | ||
| + | **[[wp> | ||
| ===== Comandi di servizio ===== | ===== Comandi di servizio ===== | ||
| - | Quando si modifica qualche file di configurazione (ad esempio gli script | + | Quando si modifica qualche file di configurazione (ad esempio gli //unit files// |
| < | < | ||
| Line 101: | Line 102: | ||
| La condizione **masked** di alcuni **unit file** è equivalente a // | La condizione **masked** di alcuni **unit file** è equivalente a // | ||
| + | ===== Starting a service when a filesystem is available an mounted ===== | ||
| + | |||
| + | This solution was tested on **Debian 9 Stretch**. | ||
| + | |||
| + | We have a filesystem on an **external USB disk**, which is not guaranteed to be present at bootstrap; to avoid hangs or errors during bootstrap, we have the following in **/ | ||
| + | |||
| + | < | ||
| + | PARTUUID=92e84ecd-a306-44df-929b-... /data ext4 auto, | ||
| + | </ | ||
| + | |||
| + | If the USB disk is not plugged during bootstrap, the filesystem is not mounted and there are not blocking errors (due the **nofail** option). We want to start a service (actually the Kodi Media Center) only if the filesystem is mounted. The relevant lines in the unit file **/ | ||
| + | |||
| + | < | ||
| + | # See man systemd.unit for the following directives. | ||
| + | # This is equivalent of placing an " | ||
| + | RequiresMountsFor = /data | ||
| + | # When systemd starts or stops " | ||
| + | PartOf = data.mount | ||
| + | </ | ||
| + | |||
| + | In this way, the Kodi service is not started if the USB disk is not connected. If the device is connected at a later time, the filesystem is automatically mounted and the Kodi service is automatically started. | ||
| + | |||
| + | |||
| + | ===== Modificare Ctrl-Alt-Del con Systemd ===== | ||
| + | |||
| + | Con il vecchio sistema di init **sysvinit** l' | ||
| + | |||
| + | Nelle nuove versioni di Debian si utilizza **systemd** per l'init del sistema, il vecchio file di configurazione non esiste più. Ecco come associare un **poweroff** invece di un **reboot**: | ||
| + | |||
| + | < | ||
| + | ln -s / | ||
| + | </ | ||
| + | |||
| + | === Spiegazione === | ||
| + | |||
| + | Le operazioni predefinite sono definite dai file contenuti in **/ | ||
| + | |||
| + | < | ||
| + | ctrl-alt-del.target -> reboot.target | ||
| + | </ | ||
| + | |||
| + | Non è necessario modificare il contenuto di questa directory, si può fare un override creando il link simbolico opportuno nella directory **/ | ||
| + | ===== Timeout in attesa di un device ===== | ||
| + | |||
| + | Può capitare che il processo di **bootstrap fallisce** perché un device elencato in **/ | ||
| + | |||
| + | < | ||
| + | / | ||
| + | </ | ||
| + | |||
| + | ===== Verifica Servizi ===== | ||
| + | |||
| + | Alcuni comandi utili per **verificare il funzionamento** dei servizi gestiti da **systemd**. | ||
| + | |||
| + | Mostra lo stato di tutti i **servizi** e di tutte le **unit**: | ||
| + | |||
| + | < | ||
| + | systemctl --all --full status | ||
| + | </ | ||
| + | |||
| + | Mostra le **unit** // | ||
| + | |||
| + | < | ||
| + | systemctl --all list-dependencies ntp.service | ||
| + | </ | ||
| + | |||
| + | ===== Verifica dipendenze servizi ===== | ||
| + | |||
| + | Generates textual **dependency graph** description in //dot// format: | ||
| + | |||
| + | < | ||
| + | systemd-analyze dot | ||
| + | systemd-analyze dot ' | ||
| + | systemd-analyze dot dhcpcd.service | ||
| + | </ | ||
| + | |||
| + | Prints an **SVG graphic** detailing **which system services have been started at what time**: | ||
| + | |||
| + | < | ||
| + | systemd-analyze plot > services-start-graph.svg | ||
| + | </ | ||
| + | |||
| + | Shows units **required** and **wanted** by the specified units: | ||
| + | |||
| + | < | ||
| + | systemctl list-dependencies | ||
| + | systemctl list-dependencies dhcpcd.service | ||
| + | systemctl list-dependencies wpa_supplicant@..service | ||
| + | </ | ||
| + | |||
| + | * **[[https:// | ||
| + | * **[[https:// | ||
| + | * **[[https:// | ||
| + | |||
| + | ===== Verifica job non completati ===== | ||
| + | |||
| + | Mostra i processi in esecuzione. In condizioni normali, quando il bootstrap è terminato, la lista dovrebbe essere vuota: | ||
| + | |||
| + | < | ||
| + | systemctl list-jobs | ||
| + | </ | ||
| + | |||
| + | ===== Alternativa allo script rc.local ===== | ||
| + | |||
| + | Come eseguire uno script all' | ||
| + | |||
| + | Creare una unit Systemd **/ | ||
| + | |||
| + | < | ||
| + | # / | ||
| + | # | ||
| + | # Service executed once the system has reached the multi-user status. | ||
| + | # | ||
| + | # Type=oneshot | ||
| + | # RemainAfterExit=yes | ||
| + | # when all its processes exited. | ||
| + | # | ||
| + | # Eanble the service with: | ||
| + | # | ||
| + | |||
| + | [Service] | ||
| + | Type=oneshot | ||
| + | RemainAfterExit=yes | ||
| + | ExecStart=/ | ||
| + | |||
| + | [Install] | ||
| + | WantedBy=multi-user.target | ||
| + | </ | ||
| + | |||
| + | Abilitare la unit e predisporre lo script **/ | ||
| + | |||
| + | ===== Riferimenti web ===== | ||
| + | |||
| + | * **[[https:// | ||
| + | Understanding Systemd Units and Unit Files]]** | ||
| + | * **[[https:// | ||
doc/appunti/linux/sa/systemd.1510046561.txt.gz · Last modified: by niccolo
