Systemd Tools → systemctl

Mehmet Ali Baykara
3 min readMay 31, 2020

In the last post we dealed with the way of creating services under Systemd. To make system administration easier, Systemd gives us some tools such as systemctl, journalctl, bootctl, coredumpctl and so on. In this post, I will focus on systemctl which is a real hand-on tool for Linux users and administrators.

The systemctl command gives powerful subcommand to inspect Systemd services and jobs. Let’s go over some of them and see closely.

NOT: systemctl command required sudo privilege

By using systemctl command you can perform following tasks

  1. systemctl list-units ist units that Systemd currently has in memory →
#It will list all currently running units 
$ sudo systemctl list-units

2. systemctl enable <service_name> will enable give service or unit. by creating a set of symlinks, as encoded in the “[Install]" sections of the unit files as we created in this post.

#After installing docker
$ sudo systemctl enable docker

3. Now you have installed or created service and enabled as well. The next step is starting the service by hitting the start. There is no output after the execution of the following command.

# The service will be activated. 
$ sudo systemctl start docker

4. Nice, we have created a service, enabled then started. So let’s see whether it is working.

$ sudo systemctl status docker

The status of our docker service tells the service is active and running, description and process ID, and more Infos.

5. Another useful command is daemon-reload. If you reconfigure any unit file or any other related configuration of running service, after that you have to reload daemon services to catch new configurations. This will restart all services.

$ sudo systemctl daemon-reload

Typical troubleshooting

  • Typo in the configuration file. For instance, I deliberately made a typo in docker.service file and then try to restart again. Failed as below:

There is a bunch of systemctl commands that allows you to maintain and track your system

  • stop
  • edit
  • reboot
  • poweroff
  • hibernate
  • list-dependencies

and much more. Please see the man page in detail.

References
* https://www.freedesktop.org/software/systemd/man/systemctl.html
* https://wiki.ubuntuusers.de/systemd/systemctl/

--

--