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/12/13 11:56] – [Servizi enabled, disabled, masked, ...] niccolo | doc:appunti:linux:sa:systemd [2024/11/15 15:01] (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 100: | Line 101: | ||
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 ===== | ===== Modificare Ctrl-Alt-Del con Systemd ===== | ||
Line 120: | Line 144: | ||
Non è necessario modificare il contenuto di questa directory, si può fare un override creando il link simbolico opportuno nella directory **/ | Non è necessario modificare il contenuto di questa directory, si può fare un override creando il link simbolico opportuno nella directory **/ | ||
- | ===== Riferimenti web ===== | + | ===== 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:// | ||
+ | |||
+ | ===== 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:// | * **[[https:// | ||
Understanding Systemd Units and Unit Files]]** | Understanding Systemd Units and Unit Files]]** | ||
* **[[https:// | * **[[https:// |
doc/appunti/linux/sa/systemd.1513162612.txt.gz · Last modified: 2017/12/13 11:56 by niccolo