Skip to main content

Systemctl Command Deep Dive and Usage Tutorial

·560 words·3 mins
Linux Systemctl Systemd DevOps Sysadmin
Table of Contents

In this tutorial, we explore how to use systemctlโ€”the primary command-line tool for interacting with systemdโ€”to manage services, sockets, mount points, and system states on modern Linux systems.

๐Ÿ’ป Introduction to systemctl
#

systemctl is the central tool used to control the systemd system and service manager.

systemd is a modern initialization system replacing the traditional SysV init process. It provides a unified framework for:

  • Service management
  • Process supervision
  • Logging
  • Boot analysis
  • Dependency control

Most mainstream Linux distributionsโ€”including Ubuntu, Fedora, Debian, Rocky Linux, and Arch Linuxโ€”use systemd by default.

๐Ÿš€ Getting Started with systemd and systemctl
#

1. Check systemd version
#

systemd --version

2. Locate systemd and systemctl binaries
#

whereis systemd
whereis systemctl

3. Verify if systemd is running
#

ps -eaf | grep [s]ystemd

4. Analyze system boot duration
#

systemd-analyze

5. Analyze service startup times
#

systemd-analyze blame

6. Visualize the boot chain
#

systemd-analyze critical-chain

๐Ÿ“ฆ Managing Units with systemctl
#

7. List all available units
#

systemctl list-unit-files

8. List all active units
#

systemctl list-units

9. List all failed units
#

systemctl --failed

10. Check if a service is enabled at boot
#

systemctl is-enabled crond.service

11. Check service status
#

systemctl status firewalld.service

12. List all services
#

systemctl list-unit-files --type=service

๐Ÿ”ง Start, Stop, Restart, and Reload Services
#

13. Manage a service (example: httpd)
#

systemctl start httpd.service
systemctl restart httpd.service
systemctl stop httpd.service
systemctl reload httpd.service
systemctl status httpd.service

14. Enable/disable service at boot
#

systemctl enable httpd.service
systemctl disable httpd.service

15. Mask/unmask a service
#

systemctl mask httpd.service
systemctl unmask httpd.service

16. Kill a service process
#

systemctl kill httpd

๐Ÿ’พ Managing Mount Points
#

17. List mount units
#

systemctl list-unit-files --type=mount

18. Control mount units
#

systemctl start tmp.mount
systemctl stop tmp.mount
systemctl restart tmp.mount
systemctl reload tmp.mount
systemctl status tmp.mount

19โ€“20. Enable/disable/mask/unmask mount units
#

systemctl enable tmp.mount
systemctl disable tmp.mount
systemctl mask tmp.mount
systemctl unmask tmp.mount

๐Ÿ”Œ Managing Socket Units
#

21. List socket units
#

systemctl list-unit-files --type=socket

22. Control a socket (example: cups.socket)
#

systemctl start cups.socket
systemctl restart cups.socket
systemctl stop cups.socket
systemctl reload cups.socket
systemctl status cups.socket

23โ€“24. Enable/disable/mask/unmask sockets
#

systemctl enable cups.socket
systemctl disable cups.socket
systemctl mask cups.socket
systemctl unmask cups.socket

๐Ÿ“ˆ CPU Resource Management
#

25. View CPU shares for a service
#

systemctl show -p CPUShares httpd.service

26. Set CPU shares for a service
#

systemctl set-property httpd.service CPUShares=2000

27. Display all service parameters
#

systemctl show httpd

28. Display critical chain for a service
#

systemd-analyze critical-chain httpd.service

29. List service dependencies
#

systemctl list-dependencies httpd.service

๐Ÿงฉ Control Groups (cgroups)
#

30. Display cgroup hierarchy
#

systemd-cgls

31. View CPU, memory, and I/O activity
#

systemd-cgtop

โš™๏ธ Managing System Runlevels (Targets)
#

32. Enter rescue mode
#

systemctl rescue

33. Enter emergency mode
#

systemctl emergency

34. Show default target
#

systemctl get-default

35โ€“36. Switch between graphical and multi-user modes
#

systemctl isolate graphical.target
systemctl isolate multi-user.target

37. Change default runlevel
#

systemctl set-default graphical.target
systemctl set-default multi-user.target

38. System power operations
#

systemctl reboot
systemctl halt
systemctl suspend
systemctl hibernate
systemctl hybrid-sleep

๐Ÿ“ Summary
#

This guide provides a complete, hands-on understanding of systemctl and systemdโ€”covering:

  • Unit management
  • Boot analysis
  • Service troubleshooting
  • Resource control
  • Runlevel/target operations
  • Mount and socket management

Mastering systemctl is essential for anyone working in Linux system administration, DevOps, or SRE roles.

Related

600 Essential Linux Commands for Developers and Sysadmins
·1004 words·5 mins
Linux Linux Commands Sysadmin DevOps Server Management
CentOS vs. Ubuntu: Choosing the Best Linux Server Distribution
·702 words·4 mins
CentOS Data Center Linux Server Ubuntu
10 Useful Tips for Using the Exclamation Mark (!) in Linux
·428 words·3 mins
Bash Linux Shell