Systemctl is a command-line tool used to monitor and control systemd and units. It has several sub-commands used to show the statuses of unit files and active units or control and monitor specific units.
There are sub-commands to control a specific unit (or unit file). If you are not logged in as the superuser, add the sudo
prefix to the command.
When you want to start a unit named unit_a.service, use this command.
sudo systemctl start unit_a
When you want to stop a running unit, use this command.
sudo systemctl stop unit_a
When you want to restart a running unit, use this command.
sudo systemctl restart unit_a
When you update a unit file and reload it, use this command.
sudo systemctl reload unit_a
When you want to start a unit (unit_a) automatically at boot, you need to enable it with this sub-command. When you run this command, a symbolic link of unit_a's unit file is created under a related directory of the unit that has a dependency with unit_a (typically, under a directory ending with .wants). This symbolic link is used to start unit_a.
sudo systemctl enable unit_a
Created symlink /etc/systemd/system/multi-user.target.wants/unit_a.service → /etc/systemd/system/unit_a.service.
With --now
option, you can also start the unit when you run the command.
sudo systemctl enable --now unit_a
When you don't want to start the unit (unit_a) automatically at boot anymore, you can disable it with this sub-command. When you run this command, the symbolic link under the directory (ending with .wants) is removed.
sudo systemctl disable unit_a
Removed /etc/systemd/system/multi-user.target.wants/unit_a.service.
With --now
option, you can also stop the unit when you run the command.
sudo systemctl disable --now unit_a
When you want to check the status of a specific unit, such as ‘active(running)
’ or ‘stopped
’ and ‘enabled
’ or ‘disabled
’, you can use this sub-command. For this command, the sudo privilege is not necessary.
systemctl status unit_a
● unit_a.service - unit description
Loaded: loaded (/etc/systemd/system/unit_a.service; enabled; vendor preset: >
Active: active (running) since Sat 2023-01-14 02:45:18 UTC; 11s ago
Main PID: 103219 (unit_a.)
:
The status information is shown with a pager. To exit the pager mode, press the q key.
There are sub-commands that are not used for a specific unit, such as systemctl list-unit-files
and systemctl list-unit
, which are explained on the systemd topic page. There are also other sub-commands not used for a specific unit.
When you edit a unit file already recognized by systemd, you need to reload it for systemd to recognize the changes. For example, if you edit service_a's unit file and check its status, you'll see a warning like the one below.
systemctl status service_a
Warning: The unit file, source configuration file or drop-ins of service_a.service changed on disk. Run 'systemctl daemon-reload' to reload units.
To make systemd recognize the change, run the command like shown below. Use sudo to avoid the authentication error if you are not logged in as the superuser.
sudo systemctl daemon-reload
systemd manages multiple units in parallel. When the system starts, default.target is activated and dependent units are also activated. There is a tree of dependencies of the unit. By running this sub-command, you can see the dependencies in the tree structure.
systemctl list-dependencies
default.target
● ├─accounts-daemon.service
:
● └─multi-user.target
● ├─apache2.service
● ├─apport.service
● ├─atd.service
:
● ├─wpa_supplicant.service
● ├─basic.target
● │ ├─-.mount
:
● │ ├─sockets.target
● │ │ ├─acpid.socket
:
● │ ├─sysinit.target
● │ │ ├─apparmor.service
● │ │ ├─blk-availability.service
:
● │ └─timers.target
● │ ├─apt-daily-upgrade.timer
:
The default target unit is used as a starting point for system boot. The default target is represented by the /etc/systemd/system/default.target file. This is a symbolic link to the original .target file in another location. To check the original target file, you can use this sub-command.
systemctl get-default
graphical.target
Systemctl is a command-line tool used to monitor and control systemd and units. It has several sub-commands used to show the statuses of unit files and active units or control and monitor specific units.
There are sub-commands to control a specific unit (or unit file). If you are not logged in as the superuser, add the sudo
prefix to the command.
When you want to start a unit named unit_a.service, use this command.
sudo systemctl start unit_a
When you want to stop a running unit, use this command.
sudo systemctl stop unit_a
When you want to restart a running unit, use this command.
sudo systemctl restart unit_a
When you update a unit file and reload it, use this command.
sudo systemctl reload unit_a
When you want to start a unit (unit_a) automatically at boot, you need to enable it with this sub-command. When you run this command, a symbolic link of unit_a's unit file is created under a related directory of the unit that has a dependency with unit_a (typically, under a directory ending with .wants). This symbolic link is used to start unit_a.
sudo systemctl enable unit_a
Created symlink /etc/systemd/system/multi-user.target.wants/unit_a.service → /etc/systemd/system/unit_a.service.
With --now
option, you can also start the unit when you run the command.
sudo systemctl enable --now unit_a
When you don't want to start the unit (unit_a) automatically at boot anymore, you can disable it with this sub-command. When you run this command, the symbolic link under the directory (ending with .wants) is removed.
sudo systemctl disable unit_a
Removed /etc/systemd/system/multi-user.target.wants/unit_a.service.
With --now
option, you can also stop the unit when you run the command.
sudo systemctl disable --now unit_a
When you want to check the status of a specific unit, such as ‘active(running)
’ or ‘stopped
’ and ‘enabled
’ or ‘disabled
’, you can use this sub-command. For this command, the sudo privilege is not necessary.
systemctl status unit_a
● unit_a.service - unit description
Loaded: loaded (/etc/systemd/system/unit_a.service; enabled; vendor preset: >
Active: active (running) since Sat 2023-01-14 02:45:18 UTC; 11s ago
Main PID: 103219 (unit_a.)
:
The status information is shown with a pager. To exit the pager mode, press the q key.
There are sub-commands that are not used for a specific unit, such as systemctl list-unit-files
and systemctl list-unit
, which are explained on the systemd topic page. There are also other sub-commands not used for a specific unit.
When you edit a unit file already recognized by systemd, you need to reload it for systemd to recognize the changes. For example, if you edit service_a's unit file and check its status, you'll see a warning like the one below.
systemctl status service_a
Warning: The unit file, source configuration file or drop-ins of service_a.service changed on disk. Run 'systemctl daemon-reload' to reload units.
To make systemd recognize the change, run the command like shown below. Use sudo to avoid the authentication error if you are not logged in as the superuser.
sudo systemctl daemon-reload
systemd manages multiple units in parallel. When the system starts, default.target is activated and dependent units are also activated. There is a tree of dependencies of the unit. By running this sub-command, you can see the dependencies in the tree structure.
systemctl list-dependencies
default.target
● ├─accounts-daemon.service
:
● └─multi-user.target
● ├─apache2.service
● ├─apport.service
● ├─atd.service
:
● ├─wpa_supplicant.service
● ├─basic.target
● │ ├─-.mount
:
● │ ├─sockets.target
● │ │ ├─acpid.socket
:
● │ ├─sysinit.target
● │ │ ├─apparmor.service
● │ │ ├─blk-availability.service
:
● │ └─timers.target
● │ ├─apt-daily-upgrade.timer
:
The default target unit is used as a starting point for system boot. The default target is represented by the /etc/systemd/system/default.target file. This is a symbolic link to the original .target file in another location. To check the original target file, you can use this sub-command.
systemctl get-default
graphical.target