linux-cheatsheet

A cheatsheet with common linux commands and tools

View on GitHub

systemd and logging

systemd

Systemd is the most commonly used init system in Linux. It represents the first process started by the kernel.

systemctl

systemctl is used to manage system services.

Note: If a name without extension is specified, .service is automatically assumed.

Units represent a single service. Targets are groups of services that can be activated together:

Other useful commands are:

unit files

Example:

[Unit]
Description=My New Service

[Service]
ExecStart=/bin/bash /opt/service.sh

[Install]
WantedBy=multi-user.target

WantedBy is used to define when a unit starts. More: man systemd.unit

Unit files from installed software are stored in /lib/systemd/system. To overwrite them, create a file in /etc/systemd/system.

To use a unit stored in another folder, it can be linked to /etc/systemd/system:

After changing unit files, the following command needs to be run:

loginctl

Loginctl can be used to view sessions managed by systemd.

journalctl

Journalctl can be used to view logs created with systemd.

Note: Systemd journald stores files in a binary format which cannot be easily tampered with.

Syslog

Syslog is older that journal but is still widely used. Logs are stored in plaintext format.



This cheatsheet was created by Rafael Urben. Found a mistake? Feel free to create a PR or open an issue on GitHub!