Useful systemd commands in daily work
About the article
This is a continuation of the systemd series. In this article, I'm focusing on practical commands that are useful in daily admin work.
Basic service management
Starting, stopping and restarting services
Starting a service
Stopping a service
Restarting a service
Reloading configuration without restarting service
Restart only if service is active
Restart or start if service is not running
Checking service status
Basic service status
Check if service is active
Check if service is enabled (autostart)
Check if service is failed
Status of all services
Configuring autostart
Enable service autostart
Enable and start service
Disable service autostart
Disable autostart and stop
Enable service only for current boot
System monitoring
System logs analysis
Display journal for specific service
Display from current boot
Display from previous boot
Continuous display of new log entries
Display only errors and warnings
Logs from last 24 hours
Logs from specific date/time
Show logs disk usage
Clear logs older than X days
Limit logs size to 500MB
Advanced log filtering
Logs for specific PID
Logs for specific user
Logs for specific execution path
Logs for specific host in container environment
Export logs to JSON format
Export logs to file
Network services management
Network status of specific interface
List all network interfaces
Restart network configuration (if active)
Network services diagnostics
Advanced network options
Managing DNS service
Check DNS configuration
Clear DNS cache
Check DNS cache statistics
Service configuration management
Edit service configuration file
Create configuration override
Check service file location
Reload all unit files
Check unit properties
Configuration preview
Display service file
Display service dependencies
Display service properties
Display specific property
Systemd time analysis
System boot time
Longest starting services
Boot path
Generate boot time chart
Analyze all service dependencies
Container and virtual machine management
List all containers
Start shell in container
Start shell as specific user in container
Restart container
Stop container
Container status
Nspawn - lightweight containers
Start container with specific directory as rootfs
Start container from image
Start container with network
Power management
System shutdown
System restart
System suspend
Hibernation
Hybrid mode (suspend-then-hibernate)
Schedule shutdown
Cancel scheduled shutdown
Scheduled tasks status
Resource management
Check memory limits
Check CPU limits
Check I/O limits
Set memory limit for service
Set CPU priority for service
Set TasksMax limit for service
Systemd automation
Generating dependencies
Automatically generate dependencies for service
Remove automatic dependency
Automation commands
Cascade restart services (all dependent)
Force reload all services
Generate system status report
Important configuration files location
Path | Description |
---|---|
/etc/systemd/system/ |
Unit files defined by administrator |
/run/systemd/system/ |
Unit files generated during runtime |
/lib/systemd/system/ |
Unit files provided by system packages |
/etc/systemd/system.conf |
Global systemd configuration |
/etc/systemd/user.conf |
Global configuration for user sessions |
/etc/systemd/journald.conf |
Logging system configuration |
/etc/systemd/logind.conf |
Session management configuration |
/etc/systemd/networkd.conf |
Network management configuration |
/etc/systemd/resolved.conf |
DNS service configuration |
Advanced tips
- To check systemd configuration consistency:
systemd-analyze verify name.service
- clear old systemd cache:
rm -rf /var/lib/systemd/catalog/database
- check failed units:
systemctl --failed --all
- set default target:
systemctl set-default multi-user.target
- temporarily start with different target:
systemctl isolate rescue.target
Tip
Create your own aliases for frequently used systemd commands in your .bashrc
file:
These are just some of the useful commands. Systemd is a rich tool that offers many functionalities.