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

Services, scheduled tasks, event logs and performance

Control Windows services and their recovery, automate with Task Scheduler, use event logs with Ge...

Linux vs Unix: the complete guide to commands and distributions

Understand the differences between Linux and Unix, explore distributions (server, desktop, lightw...

Linux administration best practices

Checklist for administering Linux servers: accounts and sudo, SSH, updates, systemd services, sto...

Linux system architecture: kernel, boot and directory tree

Understand how a Linux server works: kernel and user space, the UEFI, GRUB, initramfs and systemd...

Linux server security and hardening

Harden a Linux server: least privilege, updates, secure SSH, firewall, fail2ban, SELinux and AppA...

Backup, monitoring and troubleshooting of a Linux server

Operate a Linux server day to day: 3-2-1 backup strategy with rsync, tar, LVM snapshots and resti...

Users, groups, sudo and permissions on Linux

Manage Linux accounts (useradd, usermod, passwd, chage), groups, sudo and visudo, rwx and octal p...

Storage on Linux: disks, partitions, file systems and LVM

Administer Linux storage: lsblk and blkid, GPT partitioning, ext4 and XFS, mounting and /etc/fsta...

Networking on Linux: configuration, diagnosis, firewall and SSH

Configure and troubleshoot Linux networking: ip, ss, netplan and NetworkManager, DNS, layered dia...

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!