RousselTMLEARNING

Article · Linux administration: from discovery to expertise

Packages, systemd services and logs

1. Package management #

Install, update, remove.

apt and dnf #

Installing a package
Always run apt update before apt install: the local index may be out of date.
ActionDebian / UbuntuRHEL / Rocky / Fedora
Update the indexapt updatednf check-update
Upgrade the systemapt upgradednf upgrade
Installapt install nginxdnf install nginx
Removeapt remove / purgednf remove
Searchapt searchdnf search
Infoapt showdnf info
Which package provides this file?dpkg -S /usr/bin/ssdnf provides /usr/bin/ss
Installed packagesdpkg -l / apt list --installedrpm -qa
History/var/log/apt/history.logdnf history
sudo apt update && sudo apt upgrade -y
apt list --upgradable
sudo apt autoremove            # dépendances devenues inutiles
sudo apt-mark hold postgresql-16   # bloquer une version
cat /var/run/reboot-required 2>/dev/null   # redémarrage nécessaire (noyau, libc)

Repositories and automatic updates #

Packages come from signed repositories (/etc/apt/sources.list.d/, /etc/yum.repos.d/). Only add a third-party repository from the official vendor, with its GPG key.

sudo apt install unattended-upgrades && sudo dpkg-reconfigure -plow unattended-upgrades   # Debian/Ubuntu
sudo dnf install dnf-automatic && sudo systemctl enable --now dnf-automatic.timer        # RHEL
Good practice: Apply security fixes automatically, but schedule major upgrades (and reboots) in a maintenance window, first on a test server.

2. Services with systemd #

Start, stop, diagnose.

systemctl #

Lifecycle of a systemd service
An enabled service starts at boot; Restart= relaunches it after a crash.
systemctl status nginx                 # état, PID, derniers logs
sudo systemctl start|stop|restart nginx
sudo systemctl reload nginx            # relire la configuration sans couper
sudo systemctl enable --now nginx      # activer au boot et démarrer
sudo systemctl disable nginx
systemctl is-active nginx ; systemctl is-enabled nginx
systemctl --failed                     # services en échec
systemctl list-units --type=service --state=running
systemctl cat nginx                    # fichier d'unité effectif
sudo systemctl edit nginx              # surcharge (drop-in) sans toucher au paquet
sudo systemctl mask nginx              # empêcher tout démarrage

Writing a unit #

# /etc/systemd/system/app.service
[Unit]
Description=API de commandes
After=network-online.target
Wants=network-online.target

[Service]
User=app
WorkingDirectory=/srv/app
EnvironmentFile=/etc/app/app.env
ExecStart=/srv/app/bin/server --port 8080
Restart=on-failure
RestartSec=5
# Durcissement
NoNewPrivileges=true
ProtectSystem=strict
ReadWritePaths=/var/lib/app
PrivateTmp=true

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload     # après toute modification d'unité
sudo systemctl enable --now app
systemd-analyze security app     # score d'exposition du service
Good practice: Never modify the files in /usr/lib/systemd/system (overwritten by updates): create an override with systemctl edit.

3. Logs #

journald and the files in /var/log.

journalctl #

Log flow
The journal is persistent if /var/log/journal exists (Storage=persistent).
journalctl -u nginx -f                 # suivre un service
journalctl -u app --since "1 hour ago"
journalctl -p warning -b               # avertissements et pires, depuis le boot
journalctl -k                          # messages du noyau
journalctl _PID=1234
journalctl -o json-pretty -n 1         # champs structurés
journalctl --disk-usage
sudo journalctl --vacuum-size=500M     # limiter la taille

Classic files #

FileContent
/var/log/syslog or messagesgeneral log (rsyslog)
/var/log/auth.log or secureauthentications, sudo, SSH
/var/log/kern.logkernel
/var/log/<service>/application logs (nginx, postgresql)

logrotate rotates, compresses and deletes old files according to /etc/logrotate.d/.

# /etc/logrotate.d/app
/var/log/app/*.log {
    daily
    rotate 14
    compress
    delaycompress
    missingok
    notifempty
    copytruncate
}
sudo logrotate -d /etc/logrotate.d/app   # simulation

4. Scheduling tasks #

cron and systemd timers.

cron #

Fields of a crontab line
*/5 in the minute field means « every 5 minutes ».
crontab -e            # tâches de l'utilisateur
sudo crontab -l -u root
ls /etc/cron.d /etc/cron.daily
# min heure jour mois jour_semaine  commande
30 2 * * *   /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1
*/5 * * * *  /usr/local/bin/check.sh
0 8 * * 1-5  /usr/local/bin/rapport.sh
Common mistake: cron runs with a minimal environment (reduced PATH, no shell variables): use absolute paths and redirect the output, otherwise errors go unnoticed.

systemd timers #

A timer triggers a service: you benefit from journald logs, dependencies, Persistent=true (catching up on a run missed during downtime) and a random delay.

# /etc/systemd/system/backup.service
[Unit]
Description=Sauvegarde quotidienne
[Service]
Type=oneshot
ExecStart=/usr/local/bin/backup.sh

# /etc/systemd/system/backup.timer
[Unit]
Description=Planification de la sauvegarde
[Timer]
OnCalendar=*-*-* 02:30
RandomizedDelaySec=15m
Persistent=true
[Install]
WantedBy=timers.target
sudo systemctl enable --now backup.timer
systemctl list-timers
systemd-analyze calendar 'Mon..Fri 08:00'   # vérifier une expression

📄 Packages, systemd services, logs and scheduled tasks →

My progress

  • ⏱ Estimated time : ≈ 14 min

Sign in to track your progress and take notes. Sign in

💬 Questions about this lesson

No questions yet: be the first to ask for help or share your configuration.

Ask a question about this lesson →

Recommended Articles

The Bash shell and files: navigation, redirections, pipes and text processing

Master the Linux command line: paths, file handling, wildcards, redirections, pipes, searching wi...

Bash scripts for administrators: writing robust scripts

Automate Linux administration with Bash: variables and quoting, conditions, loops, functions, exi...

Processes, memory and performance: monitoring and troubleshooting a Linux server

Understand and control Linux processes (ps, top, signals, nice, jobs), interpret load, memory and...

Active Directory Domain Services and DNS

Understand and deploy Active Directory: forest, domains, organizational units, domain controllers...

HAProxy cheat sheet: the essential commands

A practical guide gathering all the essential commands to install, manage, test and debug HAProxy...

Fluent Bit: pipeline inputs in detail

Everything about Fluent Bit inputs: the role of tags, reading files with tail (positions, rotatio...

Windows networking: IP, DNS, DHCP, firewall and remote access

Configure and troubleshoot Windows networking with PowerShell, deploy a DHCP server, master Windo...

Grafana Alloy: collecting system metrics and local logs

Learn how to configure Grafana Alloy to monitor the server it runs on, with a focus on configurat...

Ansible: ad-hoc commands

Run immediate actions on a fleet of servers with ansible: the ping, command, shell, copy, apt, se...

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!