Modern Linux distributions use systemd as the init system and service manager. Understanding it is essential for system administration.
Service Management
systemctl start service # Start service
systemctl stop service # Stop service
systemctl restart service # Restart service
systemctl reload service # Reload configuration
systemctl status service # Check status
Service States
systemctl enable service # Enable on boot
systemctl disable service # Disable on boot
systemctl is-enabled service # Check if enabled
systemctl is-active service # Check if running
Viewing Services
systemctl list-units # All units
systemctl list-units --type=service # Only services
systemctl list-unit-files # All unit files
Service Files
Service files are located in:
- /etc/systemd/system/ - System services
- /usr/lib/systemd/system/ - Package-installed services
- ~/.config/systemd/user/ - User services
Example Service File
[Unit]
Description=My Custom Service
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/myprogram
Restart=always
[Install]
WantedBy=multi-user.target
Logs with journalctl
journalctl -u service # Service logs
journalctl -f # Follow logs
journalctl --since today # Since today
journalctl -p err # Error level only
Timers (Cron Alternative)
systemctl list-timers # List all timers
systemctl status timer # Timer status
systemd provides a unified interface for managing system services and resources.