SystemD – systemctl

Published on June 4, 2022 at 9:31 am by LEW

Introduction

SystemD is used in many Linux distributions. So we will be taking a look at the systemctl command, as it is what most users will encounter when working with services.

SystemD has replaced System V in many mainline Linux Distributions (see this post) for working with services. So we will take some time and look at the systemctl command, used to manipulate services under SystemD

What is a Service

Without going overly deep, a service is an application running in the background that carries out specific tasks that are essential for a system to perform specific functions.

Just starting your computer initiates a number of background services. If you are interested in the running services just enter the following.

systemctl

Be prepared, the list could be extensive. Note that these are running services. If you are interested in all services regardless of the status (active, failed, running, stopped, etc.), then use this command.

systemctl –type=service

Depending on the length of the list you may want to pipe the output through a pager reader (more or less), or though a filter (like grep).

Common systemctl Tasks

Some of the more common tasks you may end up doing with systemctl is starting, stopping, restarting, reloading, enabling, and disabling services.

A common example is making changes to a configuration file, which will not take effect until the service is restarted or reloaded. Or installing an application that relies on a background service that needs to be enabled.

Most examples you are likely to find in a search relate to Linux servers, web, ftp, ssh, mail, etc. And under most distributions (Arch and LFS being notable exceptions) these applications are started automatically by the installer.

Generals you will only need to work with a service when you change a configuration file, and you do not want to reboot your computer.

Usage of systemctl

The basic syntax for using sytemctrl is as follows.

systemctl [options] command <application><.service>

The options can be found on the man page. But we will not be using any of them for our discussion here. In theory you should add the <.servcie> to the end of application, but it has been my experience that systemd is smart enough to figure things out without it. That just leaves the command section. The most common commands are listed below.

start: This command does what it says, starts a service that is not running.

stop: Similarly this command stops a running service.

restart: This command stops, then starts a running service.

reload: This command attempts to reload the configuration without stopping the service. This only works on services designed for it, so your millage will be variable with this command.

enable: This command sets a service up to start automatically during the boot process.

disable: This command and disables startup during the boot process.

status: This command prints out some basic information about a service.

Note: The next couple of commands can be used without an application.

shutdown: This shuts down your system.

reboot: This shuts down and reboots your system.

halt: This command halts your system

Conclusion

In this post we have briefly covered some of the more common commands used with systemctl.

But this is but one aspect of SystemD. In a future post we will look at some of the other cool things that can be done with SystemD.

Add New Comment

Your email address will not be published. Required fields are marked *