This document is a WORK IN PROGRESS.
This is just a quick personal cheat sheet: treat its contents with caution!
SystemD¶
SystemD is a suite of basic building blocks for a Linux system. It provides a system and service manager that runs as PID 1 and starts the rest of the system.
Reference(s)
Table of contents¶
TODO
Services¶
Basic services control¶
afficher directement à la fin des logs
afficher les derniers logs en direct
editer le contenu d(un service systemd existant (très important, pour éviter d'écrire par dessus les services gérés par le système avec les )
afficher le contenu d(un service systemd (incluant aussi les modifications faites via edit
, qui se retrouveront dans le dossier override.conf)
afficher les valeurs de toutes les variables associées à un service :
afficher les variables d(environnement associées à un service :
après avoir créé ou modifié un service, il faut penser à lancer :
affiche tous les emplacements de documentation pour trouver différentes informations
affiche les dépendances d'un service
affiche les dépendances inverses d'un service
affiche les services qui ont pris le plus de temps à s'activer
affiche la chaine critique de démarrage du système, et mets en évidence qui est resté le plus longtemps sur le chemin critique de démarrage:
créé un fichier .svg qui affiche graphiquement comment sont séquencés les services au démarrage et en combien de temps:
créé un fichier .svg qui affiche graphiquement les dépendences et reverses dépendances d'un service:
-
Start the
service_name
service: -
Stop the
service_name
service: -
Restart the
service_name
service: -
Reload
service_name
configuration without stopping theservice_name
service: -
Check the
service_name
service status: -
Enable the
service_name
service on system boot: -
Disable the
service_name
service on system boot: -
Check if the
service_name
service is enable or disable on system boot:
Inspect services¶
-
Check if any SystemD services have entered in a failed state:
-
List SystemD services that have failed:
Override services¶
Let's you want the ntpd
service to automatically restart if a failure happens. You could
"manually" edit the associated .service
file (/usr/lib/systemd/system/ntpd.service
), but this
file could be overritten after a system update or package install. This is where the systemctl
edit
command is interresting, it will create an associated override.conf
file that will always
apply:
-
Edit the override file (e.g. of
ntpd.service
, located in/etc/systemd/system/ntpd.service.d/override.conf
and not in/usr/lib/systemd/system/ntpd.service
) : -
Check the syntax e.g. of
/usr/lib/systemd/system/ntpd.service
and/etc/systemd/system/ntpd.service.d/override.conf
: -
Print the full ntpd service (
ntpd.service
andntpd.servce.d/override.conf
) :$ systemctl cat ntpd.service > # /usr/lib/systemd/system/ntpd.service > [Unit] > Description=Network Time Service > After=syslog.target ntpdate.service sntp.service > > [Service] > Type=forking > EnvironmentFile=-/etc/sysconfig/ntpd > ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS > PrivateTmp=true > > [Install] > WantedBy=multi-user.target > > # /etc/systemd/system/ntpd.service.d/override.conf > [Service] > Restart=on-failure
Analyze services¶
Reference(s)
- Create an SVG graphic detailing which system services have been started at what time, highlighting the time they spent on initialization:
Run levels¶
TODO
Tips and tricks¶
-
Start system in a non-graphical mode:
-
Check systemd
journal
for a service:-x, --catalog
: Augment log lines with explanation texts from the message catalog. This will add explanatory help texts to log messages in the output where this is available. These short help texts will explain the context of an error or log event, possible solutions, as well as pointers to support forums, developer documentation, and any other relevant manuals.-e, --pager-end
Immediately jump to the end of the journal inside the implied pager tool.-u, --unit=UNIT|PATTERN
Show messages for the specified systemd unit UNIT (such as a service unit), or for any of the units matched by PATTERN. -
Check systemd
journal
for every services:-x, --catalog
Augment log lines with explanation texts from the message catalog. This will add explanatory help texts to log messages in the output where this is available.-b [[ID][±offset]|all], --boot[=[ID][±offset]|all]
Show messages from a specific boot. This will add a match for "_BOOT_ID=". The argument may be empty, in which case logs for the current boot will be shown.-p 3, --priority=
Filter output by message priorities or priority ranges. Takes either a single numeric or textual log level (i.e. between 0 "emerg" and 7 "debug").The log levels are the usual syslog log levels as documented in syslog, i.e.: - "emerg" (0) - "alert" (1) - "crit" (2) - "err" (3), - "warning" (4) - "notice" (5) - "info" (6) - "debug" (7) If a single log level is specified, all messages with this log level or a lower (hence more important) log level are shown. If a range is specified, all messages within the range are shown.
If this cheat sheet has been useful to you, then please consider leaving a star here.