systemctl
Overview
The systemctl
command controls the systemd system and service manager. It’s used to manage system services, check system status, and change system state.
Syntax
systemctl [options] command [name]
Common Commands
Command | Description |
---|---|
start |
Start service |
stop |
Stop service |
restart |
Restart service |
reload |
Reload configuration |
status |
Check status |
enable |
Enable at boot |
disable |
Disable at boot |
is-active |
Check if active |
is-enabled |
Check if enabled |
list-units |
List units |
list-unit-files |
List unit files |
daemon-reload |
Reload systemd |
Common Options
Option | Description |
---|---|
-H HOST |
Remote host |
-M CONTAINER |
Container name |
-t TYPE |
List specific type |
-a, --all |
Show all units |
-l, --full |
Don’t ellipsize |
--failed |
Show failed units |
--user |
User service manager |
--system |
System service manager |
Key Use Cases
- Service management
- System state control
- Boot configuration
- Service monitoring
- System troubleshooting
Examples with Explanations
Example 1: Service Status
systemctl status nginx
Check nginx service status
Example 2: Start Service
systemctl start mysql
Start MySQL service
Example 3: Enable Service
systemctl enable ssh
Enable SSH at boot
Common Usage Patterns
Service control:
systemctl restart service
Boot management:
systemctl enable --now service
Status check:
systemctl is-active service
Service States
- active (running)
- active (exited)
- active (waiting)
- inactive (dead)
- failed
- activating
- deactivating
Additional Resources
Best Practices
- Regular status checks
- Enable required services
- Monitor failed units
- Document changes
- Security considerations
Troubleshooting
- Failed services
- Boot problems
- Dependencies
- Configuration errors
- Resource issues
Unit Types
- service
- socket
- device
- mount
- target