User:Tsu2/systemd-2

Jump to: navigation, search

systemd - Practical Intro and Proposed Use for Technical Help Forums

When posting to the Technical Help Forums, it is always helpful to post as much useful information as possible. systemd can help gather basic information, and might even be enough for you to solve the problem yourself!

The systemd "status" command by itself can display a lot of information about your problem, here is an example of a malfunctioning dnsmasq service (daemon)

$ systemctl status dnsmasq.service

dnsmasq.service - DNS caching server.

         Loaded: loaded (/lib/systemd/system/dnsmasq.service; enabled)
         Active: failed (Result: exit-code) since Fri, 22 Feb 2013 14:04:13 -0800; 1 weeks and 1 days ago
         CGroup: name=systemd:/system/dnsmasq.service

Feb 22 14:04:12 OPENSUSEBOX dnsmasq[731]: dnsmasq: error at line 95 of /etc/dnsmasq.conf

As you can see from above,
The status of Unit Name "dnsmasq.service" is being retrieved.
There are multiple possible states, currently the Unit is loaded, enabled and the location of the Unit configuration is described.
It should be running (Active) but an error occurred.
The dnsmasq.service does not have a parent process and a CGroup with the dnsmasq name has been created so if any child processes are spawned, they will be managed together and under this CGroup.
The actual location of the error.
If the version of systemd supports, lines from the journal (not supported in 12.2, supported in 12.3 and later)

Cool, huh?

So, how do you go about getting this info? It's not difficult, the only trick perhaps is to get the name of the Unit relevant to your problem.

Some systemd fundamentals and background...

systemd is a replacement for
Bootup and shutdown management,
Unifying the many systems like SystemV use of bash init scripts,
Udev for device auto detection and configuration,
Mounting and unmounting partitions and devices,
even basic commands like start, restart and shutdown which can vary from distro to distro.

You no longer need to learn how each and every subsystem works and their unique commands, you now have a single system that does it all and uses similar commands applied to every "unit." Units are the objects that represent every manageable subsystem type. To date there are 10 main types(may grow) but there is also an additional "special" type which is the wild card that can be used to manage units that don't fit into the standard types. The "systemd." part of the name is required when defining configurations, which can often be omitted when using the command line.


Unit Types
systemd.service service
systemd.socket socket based activation (eg network sockets)
systemd.target during bootup, "synchronization points"
systemd.device Expose kernel-based device support, can be used for device based activation
systemd.mount mount points
systemd.automount parallelized bootup and on demand mount points
systemd.snapshot preserve state of a set of units
systemd.snapshot preserve state of a set of units
systemd.timer trigger units based on timers
systemd.swap similar.mount, but for swap files and partitions
systemd.path dynamically add/remove paths for units when changed or modified
<special>.target A number of special units that invoke common functionality, Can be invoked by CLI

Cookbook steps for "systemd status" for Troubleshooting and Posting

In almost all cases, now a single command may give you all the info you need where to fix your problem

systemctl status <unitname.unittype>

Finding the Unit name

The trick may be to identify exactly what the "unitname.unittype" is, if you don't know already you can list all the units on your system but the list will be very, very long

Note: When you want to leave the systemd output and return to your default console, just type "q"

systemctl -a

If you only want to list the loaded units, just type systemctl by itself with no flags

systemctl

If you only want to list a unit type, you can specify. The following lists only the services (daemons) on your system, see the above list for other unit types

systemctl --type=service

You can read the documentation for other options including scoping the list by state if you wish.

Summary and Example

So, the exact steps to display the above "dnsmasq" example might be...
1. I know it's a service, so I can list only the services to see if "dnsmasq" or something else is in there

systemctl --type=service

2. Having found dnsmasq.service and verifying it's reporting an error, I can get more info about the unit

systemctl status dnwmasq.service

I can then copy the info right out of the console, if I wanted to instead write the info to a file I could simply run the following

systemctl status dnsmasq.service > journalresult.txt

additional information

MAN pages of course! (But it's long and sometimes complex)
Link to SDB systemd - None seems to exist today
A slide deck introducing systemd
Lennart Poettering's systemd blog (>20 installments), a primary author of systemd
Freedesktop.org systemd landing page
Link to something