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.

Image for post
Image for post

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 “" sections of the unit files as we created in this post.

#After installing docker
$ sudo systemctl enable docker
Image for post
Image for post

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
Image for post
Image for post

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:
Image for post
Image for post

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/

Computer Science And DevOps things :)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store