Linux OS Internals (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
Systemd Units and Service Management: Anatomy of a `.service` file, restart policies, and watchdog integration.
senior LevelCode ExampleHTTP & REST APIs
In Simple Words: A robust production systemd service definition:
ini
[Unit]
Description=Core API Microservice
After=network.target postgresql.service
Wants=postgresql.service
[Service]
Type=notify
ExecStart=/usr/local/bin/api-server --port=8080
Restart=on-failure
RestartSec=5s
User=appuser
Group=appuser
LimitNOFILE=65536
WatchdogSec=30s
# Security Sandboxing
ProtectSystem=strict
ProtectHome=true
NoNewPrivileges=true
[Install]
WantedBy=multi-user.target
- Watchdog Integration: The process must send periodic
sd_notify("WATCHDOG=1")signals. If deadlocked, systemd automatically restarts the service after 30 seconds.