# The `systemctl` command The `systemctl` command is used to control and manage systemd services and the systemd system and service manager in Linux. It's the primary tool for managing services in modern Linux distributions. ## Syntax ``` systemctl [options] command [service-name] ``` ## Common Commands ### Service Management ``` start [service] Start a service stop [service] Stop a service restart [service] Restart a service reload [service] Reload service configuration status [service] Show service status enable [service] Enable service to start at boot disable [service] Disable service from starting at boot ``` ### System Commands ``` reboot Restart the system poweroff Shutdown the system suspend Suspend the system hibernate Hibernate the system ``` ## Options Some popular option flags include: ``` -l Show full output (don't truncate) --no-pager Don't pipe output into a pager --failed Show only failed units --all Show all units, including inactive ones -q Quiet mode, suppress output -t Specify unit type (service, socket, etc.) ``` ## Examples 1. Start a service ```bash systemctl start nginx ``` 2. Stop a service ```bash systemctl stop apache2 ``` 3. Check service status ```bash systemctl status ssh ``` 4. Enable a service to start at boot ```bash systemctl enable mysql ``` 5. Disable a service from starting at boot ```bash systemctl disable bluetooth ``` 6. Restart a service ```bash systemctl restart networking ``` 7. Reload service configuration without stopping ```bash systemctl reload nginx ``` 8. List all active services ```bash systemctl list-units --type=service ``` 9. List all services (active and inactive) ```bash systemctl list-units --type=service --all ``` 10. List failed services ```bash systemctl --failed ``` 11. Show service dependencies ```bash systemctl list-dependencies nginx ``` 12. Check if a service is enabled ```bash systemctl is-enabled ssh ``` 13. Check if a service is active ```bash systemctl is-active mysql ``` 14. Restart the system ```bash systemctl reboot ``` 15. Shutdown the system ```bash systemctl poweroff ``` ## Service Status Information When checking status, you'll see: - **Active (running)**: Service is currently running - **Active (exited)**: Service completed successfully - **Inactive (dead)**: Service is not running - **Failed**: Service failed to start ## Use Cases - Managing web servers (nginx, apache) - Controlling database services (mysql, postgresql) - Managing system services (ssh, networking) - Troubleshooting service issues - Automating service management in scripts - System administration and maintenance ## Important Notes - Requires root privileges for most operations (use `sudo`) - Services are called "units" in systemd terminology - Configuration files are located in `/etc/systemd/system/` - Always check service status after making changes - Use `journalctl` to view detailed service logs The `systemctl` command is essential for modern Linux system administration and service management. For more details, check the manual: `man systemctl`