One of the most important skills any Systemd newcomer can learn is how to manage their computer’s services. For the purposes of this article we will discuss the basics: starting, stopping, enabling, and disabling services from the Linux command line.
These tasks aren’t difficult to master, yet they become an undeniable need when you’re forced to halt an out-of-control program or when you want to install a new application.
What Is Systemd?
Chances are good that your Linux computer currently runs Systemd. Many distros, including Arch Linux, Debian, Fedora, Red Hat, and Ubuntu, all use it by default. Some distributions would be difficult or impossible to run without it being installed.
Systemd works foremost as a robust replacement to the old init project SysV that UNIX distros had used since the 1980s. Key developer Lennart Poettering has also stated that Systemd goes beyond init tasks and may also act as a development platform and a link between individual applications and the Linux kernel.
This has caused a lot of outrage at Poettering’s platform as a whole, primarily because its monolithic nature appears to act against “the UNIX way” of simple, modular code.
Whichever side you choose in the debate about Systemd’s legitimacy, you may still fall under its wing this second. Therefore, you will need to know how to use it, and there’s no better way to get started than to install a new program.
Starting and Stopping Units
Systemd starts, stops, enables, and disables “units.” Units are comprised of the services, mount points, devices, and sockets on your computer. In these instructions you will be working with services (.service files), the files that represent programs on your computer that wait to be accessed for a specific task.
Several Linux distros have access to
Hddtemp, a small utility that checks the temperature of a hard drive. Hddtemp has a .service file and can run as a daemon, so you can start it manually and enable it to start at boot. It’s small and non-invasive; you can download it, try it in conjunction with Systemd, and delete it later if you don’t want it around.
Install it on Arch with:
sudo pacman -S hddtemp
and on Ubuntu with:
sudo apt-get install hddtemp
Now start the new utility with Systemd:
sudo systemctl start hddtemp.service
You can then restart, stop, and see the status of man-db with that same style command –
systemctl <action> unit. Notice that “unit” works as shorthand for any “unit.service” file you will use.
sudo systemctl start hddtemp,
sudo systemctl stop hddtemp, and
sudo systemctl restart hddtemp commands produce no output by default when they’re successful.
You can get more information about the service with:
sudo systemctl status hddtemp
In this case the command reveals the name of the service, its state (active or inactive), and the starting/stopping that’s taken place over the past few minutes. If any of the above commands failed or produced an error, those problems would show up in the status report.
Enabling and Disabling Units
When you start or stop a unit, you’re completing a manual process that will likely last only through your current session. When you reboot, the unit you started may not run automatically.
To have units start at boot, try enabling them with Hddtemp:
sudo systemctl enable hddtemp
The output here shows that Systemd created a symlink to tell itself to start Hddtemp when your computer goes through the boot process. In the future, feel free to use the shortcut:
sudo systemctl enable --now unit
to both enable and start a unit in one command.
Now you can disable Hddtemp just as easily:
sudo systemctl disable hddtemp
If you’re ever unsure about whether or not a unit is enabled, you can run
sudo systemctl is-enabled unit to find out.
You can now remove Hddtemp from your computer if you don’t want it around.
These commands are the end result of the complex machine that is Systemd. Love it or hate it, there is no denying that if you use Systemd, these commands will become useful to the management of programs on your computer.
Check out the “COMMANDS” section of the Systemctl man page with
man systemctl. You will find these same commands – start, stop, enable, disable – alongside many others that are just as easy to use but will dig deeper than these basic examples shown here.
Our latest tutorials delivered straight to your inbox