Unidad 5.2: systemd units y journalctl
Gestion de servicios con systemctl y lectura de logs
Unidad 5.2: systemd units y journalctl
Introduccion
El brochure del curso indica que la Unidad 5 incluye systemd units y journalctl. Esto es el corazon de la operacion en Linux moderno: servicios como SSH, Nginx, Docker y bases de datos se controlan con systemd.
Tiempo estimado: 60-90 minutos
Conceptos clave
- Unit: recurso gestionado por systemd (ej:
nginx.service,ssh.service). - Active vs enabled:
- active: corre ahora
- enabled: arranca al boot
systemctl: controlar servicios
BASH
1$ systemctl status ssh --no-pager
* ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled)
Active: active (running) since Sun 2026-02-01 09:10:00 UTC; 2h 15min ago
2$ sudo systemctl restart ssh
3$ sudo systemctl enable nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service -> /lib/systemd/system/nginx.service.
4$ sudo systemctl disable nginx
Removed /etc/systemd/system/multi-user.target.wants/nginx.service.- 1
- systemctl status … –no-pager muestra estado y si esta enabled
- 2
- systemctl restart reinicia el servicio (aplica cambios)
- 3
- systemctl enable habilita arranque automatico
- 4
- systemctl disable deshabilita arranque automatico
journalctl: logs del servicio
BASH
- 1
- journalctl -u … –since trae logs recientes del servicio
- 2
- journalctl -f sigue logs en tiempo real (similar a tail -f)
Ejemplos practicos multi-SO
Linux
BASH
1$ systemctl status nginx --no-pager
* nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled)
Active: active (running) since Sun 2026-02-01 09:12:14 UTC; 2h 10min ago- 1
- systemctl status muestra estado del servicio
macOS
BASH
1$ launchctl list | head -n 5
PID Status Label
89 0 com.apple.audio.coreaudiod
95 0 com.apple.WindowServer- 1
- launchctl list lista servicios/agents de launchd (equivalente conceptual)
Windows
POWERSHELL
1PS> Get-Service -Name w32time | Select-Object Name,Status,StartType
Name Status StartType
---- ------ ---------
w32time Running Automatic- 1
- Get-Service consulta estado de un servicio
| Aspecto | Linux (systemd) | macOS (launchd) | Windows |
|---|---|---|---|
| Estado servicio | systemctl status |
launchctl list |
Get-Service |
| Logs | journalctl -u |
(logs del sistema) | Event Log |
Mejores practicas
TipRECOMENDACION
Si un servicio falla, lee logs antes de reiniciar en bucle.
Casos de uso: - nginx/ssh/mysql no levantan.
Cuando aplicar: 1. systemctl status <svc> 2. journalctl -u <svc> --since "30 min ago" 3. Corregir configuracion y recien reiniciar.
Resumen
systemctlcontrola servicios y su comportamiento al arranque.journalctles el log principal para diagnosticar fallas.