Revolutionize Your Workflow: 10 Mind-Blowing Ways to Master Systemd’s Service Management!

If you’re running a modern Linux distribution like Ubuntu, Fedora, or CentOS, chances are you’ve already encountered Systemd. Systemd is a system and service manager for Linux and other Unix-like operating systems. It has replaced traditional init systems like SysVinit and Upstart and provides a range of new features not available in other init systems.

One of the key features of Systemd is its service management. Systemd can manage the startup and shutdown of system services and applications, monitor and control their status, handle dependencies and inter-dependencies, and perform advanced resource management.

In this article, we’ll discuss ten mind-blowing ways to master Systemd’s service management and revolutionize your workflow.

1. Know Your Units

In Systemd, a unit is a basic building block of the system. Units can be services, sockets, timers, mount points, devices, and many other types of system objects. To manage a unit, you need to know its properties, dependencies, runtime parameters, and configuration files. The systemctl command is your best friend for unit management. Use it to list, start, stop, enable, disable, reload, restart, and status-check units.

2. Create Your Own Units

Systemd provides a simple and powerful way to define custom units. You can create a unit file using a text editor and place it in the /etc/systemd/system directory. A unit file consists of a set of key-value pairs that describe the unit’s properties, dependencies, and actions. After creating a unit file, you can use systemctl to manage it as a regular unit.

3. Use Unit Templates

If you need to create multiple similar units, you can use unit templates. A unit template is a unit file with one or more variables that can be substituted with actual values at runtime. You can specify the variables in the unit file name or the unit file itself. When you enable or start a template unit, Systemd creates a new instance of the unit with the substituted values.

4. Manage Dependencies

Systemd manages dependencies between units using concepts of ordering, requirements, and conflicts. You can define dependencies between units using the Requires, Wants, BindsTo, Before, After, Conflicts, and Replaces options in unit files. Systemd uses these options to ensure that units are started and stopped in the correct order, handle requirements and conflicts between units, and restart or replace units when necessary.

5. Use Target Units

Target units are a higher-level abstraction of units. They are used to group related units and define the system’s startup and shutdown targets. A target unit is a symbolic link to a real or virtual unit that defines the target’s dependencies and actions. Systemd uses target units to provide a standardized way of booting and shutting down Linux systems. You can use systemctl isolate to switch to a different target unit than the current one.

6. Monitor and Control Services

Systemd provides a set of tools for monitoring and controlling running services. The systemctl command can show the status, journal, logs, and properties of the service. The systemd-cgls and systemd-cgtop commands can show the control group hierarchy and resource usage of the service. The systemd-run command can start a service in a transient or one-shot mode without creating a unit file.

7. Use Systemd’s Advanced Resource Management

Systemd provides advanced resource management features like cgroups, slice units, and resource limits. Cgroups are used for isolating and allocating resources like CPU, memory, I/O, and network bandwidth to groups of processes. Slice units are used for defining hierarchical resource domains with their own resource limits and policies. Systemd can enforce resource limits and priorities for system services and user sessions, improving the system’s stability and performance.

8. Customize the Boot Process

Systemd allows you to customize the boot process of your Linux system. You can add, remove, or modify unit files and target units to change the system’s startup and shutdown behavior. You can use the systemd-analyze command to analyze the boot process and optimize it for speed and efficiency. You can use the systemd-bootchart command to generate a graphical chart of the boot process.

9. Integrate with Other Tools

Systemd can integrate with other tools and technologies to provide a seamless and powerful system management experience. You can use the dbus API to control Systemd and receive notifications from it. You can use the journalctl command to query and analyze the system’s journal logs. You can use the udev subsystem to manage hardware devices and their events. You can use the networkd subsystem to manage network interfaces and connections.

10. Stay Up-to-Date and Secure

Systemd is a constantly evolving and improving system management solution. New features, bug fixes, and security patches are released regularly. To stay up-to-date and secure, you need to keep your Linux system and Systemd package updated. You also need to follow security best practices like disabling unused services, configuring firewalls, using strong passwords, and monitoring logs.

In conclusion, Systemd’s service management features provide a powerful and flexible way to manage Linux system services and resources. By mastering Systemd, you can revolutionize your workflow, increase your productivity, and improve your system’s stability and security.

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:

and on Ubuntu with:

Now start the new utility with Systemd:

You can then restart, stop, and see the status of man-db with that same style command – systemctl unit. Notice that “unit” works as shorthand for any “unit.service” file you will use.

The 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:

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:

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:

to both enable and start a unit in one command.

Now you can disable Hddtemp just as easily:

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.

Conclusion

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.

I have worked as a professional writer since 2011. I like to compose my articles in Vim, which I also use for hobbyist C and Ruby projects. When I’m not in front of a text editor, I run, bike, and play tennis until I’m too tired to move.

Our latest tutorials delivered straight to your inbox