Difference between revisions of "Systemd"

From ArchWiki
Jump to: navigation, search
(Undo revision 254813 by Waterbrother (talk) "/bin/systemd" is a symlink to "/usr/lib/systemd/systemd", so using "/usr/lib/systemd/systemd" is preferred)
(Journald in conjunction with syslog: rm specific version clutter)
 
(371 intermediate revisions by more than 100 users not shown)
Line 2: Line 2:
 
[[Category:Daemons and system services]]
 
[[Category:Daemons and system services]]
 
[[Category:Boot process]]
 
[[Category:Boot process]]
 +
[[ar:Systemd]]
 +
[[de:Systemd]]
 +
[[el:Systemd]]
 
[[es:Systemd]]
 
[[es:Systemd]]
 +
[[fa:Systemd]]
 
[[fr:Systemd]]
 
[[fr:Systemd]]
 
[[it:Systemd]]
 
[[it:Systemd]]
 
[[ja:Systemd]]
 
[[ja:Systemd]]
 +
[[pt:Systemd]]
 
[[ru:Systemd]]
 
[[ru:Systemd]]
 
[[zh-CN:Systemd]]
 
[[zh-CN:Systemd]]
 
[[zh-TW:Systemd]]
 
[[zh-TW:Systemd]]
{{Article summary start}}
+
{{Related articles start}}
{{Article summary text|Covers how to install and configure systemd.}}
+
{{Related|systemd/User}}
{{Article summary heading|Related}}
+
{{Related|systemd/Timers}}
{{Article summary wiki|systemd/User}}
+
{{Related|systemd FAQ}}
{{Article summary wiki|systemd/Services}}
+
{{Related|init}}
{{Article summary wiki|systemd FAQ}}
+
{{Related|init Rosetta}}
{{Article summary wiki|init Rosetta}}
+
{{Related|Daemons#List of daemons}}
{{Article summary wiki|udev}}
+
{{Related|udev}}
{{Article summary end}}
+
{{Related|Improve boot performance}}
 +
{{Related|Allow users to shutdown}}
 +
{{Related articles end}}
 +
 
 
From the [http://freedesktop.org/wiki/Software/systemd project web page]:
 
From the [http://freedesktop.org/wiki/Software/systemd project web page]:
  
'''''systemd''' is a system and service manager for Linux, compatible with SysV and LSB init scripts. '''systemd''' provides aggressive parallelization capabilities, uses socket and [[D-Bus]] activation for starting services, offers on-demand starting of daemons, keeps track of processes using Linux [[cgroups|control groups]], supports snapshotting and restoring of the system state, maintains mount and automount points and implements an elaborate transactional dependency-based service control logic. It can work as a drop-in replacement for [[SysVinit|sysvinit]].''
+
:''systemd'' is a system and service manager for Linux, compatible with SysV and LSB init scripts. systemd provides aggressive parallelization capabilities, uses socket and [[D-Bus]] activation for starting services, offers on-demand starting of daemons, keeps track of processes using Linux [[control groups]], supports snapshotting and restoring of the system state, maintains mount and automount points and implements an elaborate transactional dependency-based service control logic.
  
{{Note|1=For a detailed explanation as to why Arch has moved to systemd, see [https://bbs.archlinux.org/viewtopic.php?pid=1149530#p1149530 this forum post].}}
+
{{Note|1=For a detailed explanation as to why Arch has moved to ''systemd'', see [https://bbs.archlinux.org/viewtopic.php?pid=1149530#p1149530 this forum post].}}
  
See also the [[Wikipedia:Systemd|Wikipedia article]].
+
== Basic systemctl usage  ==
  
== Considerations before switching ==
+
The main command used to introspect and control ''systemd'' is ''systemctl''. Some of its uses are examining the system state and managing the system and services. See {{ic|man systemctl}} for more details.
  
* Do [http://freedesktop.org/wiki/Software/systemd/ some reading] about systemd.
+
{{Tip|
* Note the fact that systemd has a '''journal''' system that replaces '''syslog''', although the two can co-exist. See the [[#Journal|section on the journal]] below.
+
* You can use all of the following ''systemctl'' commands with the {{ic|-H ''user''@''host''}} switch to control a ''systemd'' instance on a remote machine. This will use [[SSH]] to connect to the remote ''systemd'' instance.
* While systemd can replace some of the functionality of '''cron''', '''acpid''', or '''xinetd''', there is no need to switch away from using the traditional daemons unless you want to.
+
* ''systemadm'' is the official graphical frontend for ''systemctl'' and is provided by the {{Pkg|systemd-ui}} package.
* Interactive initscripts are not working with systemd. In particular, '''netcfg-menu''' [https://bugs.archlinux.org/task/31377 cannot] be used at system start-up.
+
* [[Plasma]] users can install {{Pkg|systemd-kcm}} as a graphical fronted for ''systemctl''. After installing the module will be added under ''System administration''.}}
  
== Installation ==
+
=== Analyzing the system state ===
{{Note|{{pkg|systemd}} and {{pkg|systemd-sysvcompat}} are both installed by default on installation media newer than [https://www.archlinux.org/news/systemd-is-now-the-default-on-new-installations/ 2012-10-13].}}
+
  
{{Note|If you are running Arch Linux inside a VPS, please see [[Virtual_Private_Server#Moving_your_VPS_from_initscripts_to_systemd|the appropriate page]].}}
+
Show '''system status''' using:
  
The following section is aimed at Arch Linux installations that still rely on {{pkg|sysvinit}} and {{pkg|initscripts}} which have not migrated to {{pkg|systemd}}.
+
$ systemctl status
  
# Install {{pkg|systemd}} and append the following to your [[kernel parameters]]: {{ic|1=init=/usr/lib/systemd/systemd}}
+
'''List running''' units:
# Once completed you may enable any desired services via the use of {{ic|systemctl enable <service_name>}} (this roughly equates to what you included in the {{ic|DAEMONS}} array. New names can be found [[Daemons_List|here]]).
+
# Reboot your system and verify that {{ic|systemd}} is currently active by issuing the following command: {{ic|cat /proc/1/comm}}. This should return the string {{ic|systemd}}.
+
# Make sure your hostname is set correctly under systemd: {{ic|hostnamectl set-hostname myhostname}}.
+
# Proceed to remove {{pkg|initscripts}} and {{pkg|sysvinit}} from your system and install {{pkg|systemd-sysvcompat}}.
+
# Optionally, remove the {{ic|1=init=/usr/lib/systemd/systemd}} parameter as it is no longer needed. {{pkg|systemd-sysvcompat}} provides the default init.
+
  
=== Supplementary information ===
+
$ systemctl
  
* If you have {{ic|quiet}} in your kernel parameters, you might want to remove it for your first couple of systemd boots, to assist with identifying any issues during boot.
+
or:
  
* Adding your user to [[Users and Groups|groups]] ({{ic|sys}}, {{ic|disk}}, {{ic|lp}}, {{ic|network}}, {{ic|video}}, {{ic|audio}}, {{ic|optical}}, {{ic|storage}}, {{ic|scanner}}, {{ic|power}}, etc.) is '''not''' necessary for most use cases with systemd. The groups can even cause some functionality to break. For example, the {{ic|audio}} group will break fast user switching and allows applications to block software mixing. Every PAM login provides a logind session, which for a local session will give you permissions via [[Wikipedia:Access control list|POSIX ACLs]] on audio/video devices, and allow certain operations like mounting removable storage via [[udisks]].
+
$ systemctl list-units
  
* See the [[Network Configuration]] article for how to set up networking targets.
+
'''List failed''' units:
  
== Native configuration ==
+
$ systemctl --failed
  
{{Note|You may need to create these files. All files should have {{ic|644}} permissions and {{ic|root:root}} ownership.}}
+
The available unit files can be seen in {{ic|/usr/lib/systemd/system/}} and {{ic|/etc/systemd/system/}} (the latter takes precedence). '''List installed''' unit files with:
  
=== Locale ===
+
$ systemctl list-unit-files
  
{{Note|Before you set the default locale, you first need to enable locales available to the system by uncommenting them in {{ic|/etc/locale.gen}} and then executing {{ic|locale-gen}} as root. The locale set via {{ic|localectl}} must be one of the '''uncommented''' locales in {{ic|/etc/locale.gen}}.}}
+
=== Using units ===
  
The default system locale is configured in {{ic|/etc/locale.conf}}. To set the default locale, do:
+
Units can be, for example, services (''.service''), mount points (''.mount''), devices (''.device'') or sockets (''.socket'').
  
# localectl set-locale LANG="de_DE.utf8"
+
When using ''systemctl'', you generally have to specify the complete name of the unit file, including its suffix, for example {{ic|sshd.socket}}. There are however a few short forms when specifying the unit in the following ''systemctl'' commands:
  
See {{ic|man 1 localectl}} and {{ic|man 5 locale.conf}} for details.
+
* If you do not specify the suffix, systemctl will assume ''.service''. For example, {{ic|netctl}} and {{ic|netctl.service}} are equivalent.
 +
* Mount points will automatically be translated into the appropriate ''.mount'' unit. For example, specifying {{ic|/home}} is equivalent to {{ic|home.mount}}.
 +
* Similar to mount points, devices are automatically translated into the appropriate ''.device'' unit, therefore specifying {{ic|/dev/sda2}} is equivalent to {{ic|dev-sda2.device}}.
  
* For more information, see [[Locale]].
+
See {{ic|man systemd.unit}} for details.
  
Here is an example file:
+
{{Note|Some unit names contain an {{ic|@}} sign (e.g. {{ic|name@''string''.service}}): this means that they are [http://0pointer.de/blog/projects/instances.html instances] of a ''template'' unit, whose actual file name does not contain the {{ic|''string''}} part (e.g. {{ic|name@.service}}). {{ic|''string''}} is called the ''instance identifier'', and is similar to an argument that is passed to the template unit when called with the ''systemctl'' command: in the unit file it will substitute the {{ic|%i}} specifier.
{{hc|/etc/locale.conf|<nowiki>
+
LANG=en_US.utf8
+
</nowiki>}}
+
  
=== Virtual console ===
+
To be more accurate, ''before'' trying to instantiate the {{ic|name@.suffix}} template unit, ''systemd'' will actually look for a unit with the exact {{ic|name@string.suffix}} file name, although by convention such a "clash" happens rarely, i.e. most unit files containing an {{ic|@}} sign are meant to be templates. Also, if a template unit is called without an instance identifier, it will just fail, since the {{ic|%i}} specifier cannot be substituted.
 +
}}
  
The virtual console (keyboard mapping, console font and console map) is configured in {{ic|/etc/vconsole.conf}}:
+
{{Tip|
 +
* Most of the following commands also work if multiple units are specified, see {{ic|man systemctl}} for more information.
 +
* The {{ic|--now}} switch can be used in conjunction with {{ic|enable}}, {{ic|disable}}, and {{ic|mask}} to respectively start, stop, or mask immediately the unit rather than after the next boot.
 +
* A package may offer units for different purposes. If you just installed a package, {{ic|pacman -Qql ''package'' <nowiki>|</nowiki> grep -Fe .service -e .socket}} can be used to check and find them.}}
  
{{hc|/etc/vconsole.conf|2=
+
'''Start''' a unit immediately:
KEYMAP=us
+
FONT=lat9w-16
+
FONT_MAP=8859-1_to_uni}}
+
  
{{Note|As of {{pkg|systemd}}-194, the built-in ''kernel'' font and the ''us'' keymap are used if {{ic|1=KEYMAP=}} and {{ic|1=FONT=}} are empty or not set.}}
+
# systemctl start ''unit''
  
Another way to set the keyboard mapping (keymap) is doing:
+
'''Stop''' a unit immediately:
  
  # localectl set-keymap de
+
  # systemctl stop ''unit''
  
<code>localectl</code> can also be used to set the X11 keymap:
+
'''Restart''' a unit:
  
  # localectl set-x11-keymap de
+
  # systemctl restart ''unit''
  
See {{ic|man 1 localectl}} and {{ic|man 5 vconsole.conf}} for details.
+
Ask a unit to '''reload''' its configuration:
  
* For more information, see [[Fonts#Console fonts|console fonts]] and [[KEYMAP|keymaps]].
+
# systemctl reload ''unit''
  
=== Time zone ===
+
Show the '''status''' of a unit, including whether it is running or not:
  
The time zone is configured by creating an appropriate {{ic|/etc/localtime}} symlink, pointing to a zoneinfo file under {{ic|/usr/share/zoneinfo/}}. To do this automatically:
+
$ systemctl status ''unit''
  
# timedatectl set-timezone America/Toronto
+
'''Check''' whether a unit is already enabled or not:
  
See {{ic|man 1 timedatectl}}, {{ic|man 5 localtime}}, and {{ic|man 7 archlinux}} for more details.
+
$ systemctl is-enabled ''unit''
  
Alternatively, create the symlink yourself:
+
'''Enable''' a unit to be started on '''bootup''':
<!-- DO NOT MAKE THIS AN ABSOLUTE SYMLINK, archlinux(7) clearly shows this should be a relative symlink -->
+
# ln -sf ../usr/share/zoneinfo/America/Toronto /etc/localtime
+
  
If the old configuration file {{ic|/etc/timezone}} exists you can now remove it safely, because it is not used by systemd.
+
# systemctl enable ''unit''
  
=== Hardware clock ===
+
'''Disable''' a unit to not start during bootup:
  
Systemd will use '''UTC''' for the hardware clock by default.
+
# systemctl disable ''unit''
  
{{Tip|It is advised to have a [[NTP|Network Time Protocol daemon]] running to keep the system time synchronized with Internet time and the hardware clock.}}
+
'''Mask''' a unit to make it impossible to start it:
  
==== Hardware clock in localtime ====
+
# systemctl mask ''unit''
  
If you want to change the hardware clock to use local time ('''STRONGLY DISCOURAGED''') do:
+
'''Unmask''' a unit:
  
  # timedatectl set-local-rtc true
+
  # systemctl unmask ''unit''
  
If you want to revert to the hardware clock being in UTC, do:
+
Show the '''manual page''' associated with a unit (this has to be supported by the unit file):
  
  # timedatectl set-local-rtc false
+
  $ systemctl help ''unit''
  
Be warned that, if the hardware clock is set to localtime, dealing with daylight saving time is messy. If the DST changes when your computer is off, your clock will be wrong on next boot ([http://www.cl.cam.ac.uk/~mgk25/mswish/ut-rtc.html there is a lot more to it]). Recent kernels set the system time from the RTC directly on boot, assuming that the RTC is in UTC. This means that if the RTC is in local time, then the system time will first be set up wrongly and then corrected shortly afterwards on every boot. This is the root of certain weird bugs (time going backwards is rarely a good thing).
+
Reload ''systemd'', scanning for '''new or changed units''':
  
One reason for allowing the RTC to be in local time is to allow dual boot with Windows ([http://blogs.msdn.com/b/oldnewthing/archive/2004/09/02/224672.aspx which uses localtime]). However, Windows is able to deal with the RTC being in UTC with a simple [[Time#UTC in Windows|registry fix]]. It is recommended to configure Windows to use UTC, rather than Linux to use localtime. If you make Windows use UTC, also remember to disable the "Internet Time Update" Windows feature, so that Windows don't mess with the hardware clock, trying to sync it with internet time. You should instead leave touching the RTC and syncing it to internet time to Linux, by enabling an [[NTP]] daemon, as suggested previously.
+
# systemctl daemon-reload
  
* For more information, see [[Time]].
+
=== Power management ===
  
=== Kernel modules ===
+
[[polkit]] is necessary for power management as an unprivileged user. If you are in a local ''systemd-logind'' user session and no other session is active, the following commands will work without root privileges. If not (for example, because another user is logged into a tty), ''systemd'' will automatically ask you for the root password.
  
Today, all necessary module loading is handled automatically by [[udev]], so that, if you don't want/need to use any out-of-tree kernel modules, there is no need to put modules that should be loaded at boot in any config file. However, there are cases where you might want to load an extra module during the boot process, or blacklist another one for your computer to function properly.
+
Shut down and reboot the system:
  
==== Extra modules to load at boot ====
+
$ systemctl reboot
  
Extra kernel modules to be loaded during boot are configured as a static list in files under {{ic|/etc/modules-load.d/}}. Each configuration file is named in the style of {{ic|/etc/modules-load.d/<program>.conf}}. Configuration files simply contain a list of kernel module names to load, separated by newlines. Empty lines and lines whose first non-whitespace character is {{ic|#}} or {{ic|;}} are ignored.
+
Shut down and power-off the system:
  
{{hc|/etc/modules-load.d/virtio-net.conf|
+
$ systemctl poweroff
# Load virtio-net.ko at boot
+
virtio-net}}
+
  
See {{ic|man 5 modules-load.d}} for more details.
+
Suspend the system:
  
==== Configure module options ====
+
$ systemctl suspend
  
Additional module options must be set in the {{ic|/etc/modprobe.d/modprobe.conf}}.
+
Put the system into hibernation:
  
Example:
+
$ systemctl hibernate
  
* we have {{ic|/etc/modules-load.d/loop.conf}} with module {{ic|loop}} insude to load during the boot.
+
Put the system into hybrid-sleep state (or suspend-to-both):
  
* in the {{ic|/etc/modprobe.d/modprobe.conf}} specify the additional options, e.g. {{ic|options loop max_loop&#61;64}}
+
$ systemctl hybrid-sleep
  
Afterwards, the newly set option might be verified via {{ic|cat /sys/module/loop/parameters/max_loop}}
+
== Writing unit files ==
  
==== Blacklisting ====
+
The syntax of ''systemd'''s [http://www.freedesktop.org/software/systemd/man/systemd.unit.html unit files] is inspired by XDG Desktop Entry Specification ''.desktop'' files, which are in turn inspired by Microsoft Windows ''.ini'' files. Unit files are loaded from two locations. From lowest to highest precedence they are:
  
Module blacklisting works the same way as with {{Pkg|initscripts}} since it is actually handled by {{Pkg|kmod}}. See [[Kernel modules#Blacklisting|Module Blacklisting]] for details.
+
* {{ic|/usr/lib/systemd/system/}}: units provided by installed packages
 +
* {{ic|/etc/systemd/system/}}: units installed by the system administrator
  
=== Filesystem mounts ===
+
{{Note|
 +
* The load paths are completely different when running ''systemd'' in [[systemd/User#How it works|user mode]].
 +
* systemd unit names may only contain ASCII alphanumeric characters, underscores and periods. All other characters must be replaced by C-style "\x2d" escapes. See {{ic|man systemd.unit}} and {{ic|man systemd-escape}} for more information.}}
  
The default setup will automatically fsck and mount filesystems before starting services that need them to be mounted. For example, systemd automatically makes sure that remote filesystem mounts like [[NFS]] or [[Samba]] are only started after the network has been set up. Therefore, local and remote filesystem mounts specified in {{ic|/etc/fstab}} should work out of the box.
+
Look at the units installed by your packages for examples, as well as the [http://www.freedesktop.org/software/systemd/man/systemd.service.html#Examples annotated example section] of {{ic|man systemd.service}}.
  
See {{ic|man 5 systemd.mount}} for details.
+
{{Tip|Comments prepended with {{ic|#}} may be used in unit-files as well, but only in new lines. Do not use end-line comments after ''systemd'' parameters or the unit will fail to activate.}}
  
==== Automount ====
+
=== Handling dependencies ===
  
* If you have a large {{ic|/home}} partition, it might be better to allow services that do not depend on {{ic|/home}} to start while {{ic|/home}} is checked by fsck. This can be achieved by adding the following options to the {{ic|/etc/fstab}} entry of your {{ic|/home}} partition:
+
With ''systemd'', dependencies can be resolved by designing the unit files correctly. The most typical case is that the unit ''A'' requires the unit ''B'' to be running before ''A'' is started. In that case add {{ic|1=Requires=''B''}} and {{ic|1=After=''B''}} to the {{ic|[Unit]}} section of ''A''. If the dependency is optional, add {{ic|1=Wants=''B''}} and {{ic|1=After=''B''}} instead. Note that {{ic|1=Wants=}} and {{ic|1=Requires=}} do not imply {{ic|1=After=}}, meaning that if {{ic|1=After=}} is not specified, the two units will be started in parallel.
  
noauto,x-systemd.automount
+
Dependencies are typically placed on services and not on targets. For example, {{ic|network.target}} is pulled in by whatever service configures your network interfaces, therefore ordering your custom unit after it is sufficient since {{ic|network.target}} is started anyway.
  
This will fsck and mount {{ic|/home}} when it is first accessed, and the kernel will buffer all file access to {{ic|/home}} until it is ready.
+
=== Service types ===
  
Note: this will make your {{ic|/home}} filesystem type {{ic|autofs}}, which is ignored by [[mlocate]] by default. The speedup of automounting {{ic|/home}} may not be more than a second or two, depending on your system, so this trick may not be worth it.
+
There are several different start-up types to consider when writing a custom service file. This is set with the {{ic|1=Type=}} parameter in the {{ic|[Service]}} section:
  
* The same applies to remote filesystem mounts. If you want them to be mounted only upon access, you will need to use the {{ic|noauto,x-systemd.automount}} parameters. In addition, you can use the {{ic|1=x-systemd.device-timeout=#}} option to specify a timeout in case the network resource is not available.
+
* {{ic|1=Type=simple}} (default): ''systemd'' considers the service to be started up immediately. The process must not fork. Do not use this type if other services need to be ordered on this service, unless it is socket activated.
 +
* {{ic|1=Type=forking}}: ''systemd'' considers the service started up once the process forks and the parent has exited. For classic daemons use this type unless you know that it is not necessary. You should specify {{ic|1=PIDFile=}} as well so ''systemd'' can keep track of the main process.
 +
* {{ic|1=Type=oneshot}}: this is useful for scripts that do a single job and then exit. You may want to set {{ic|1=RemainAfterExit=yes}} as well so that ''systemd'' still considers the service as active after the process has exited.
 +
* {{ic|1=Type=notify}}: identical to {{ic|1=Type=simple}}, but with the stipulation that the daemon will send a signal to ''systemd'' when it is ready. The reference implementation for this notification is provided by ''libsystemd-daemon.so''.
 +
* {{ic|1=Type=dbus}}: the service is considered ready when the specified {{ic|BusName}} appears on DBus's system bus.
 +
* {{ic|1=Type=idle}}: ''systemd'' will delay execution of the service binary until all jobs are dispatched. Other than that behavior is very similar to {{ic|1=Type=simple}}.  
  
* If you have encrypted filesystems with keyfiles, you can also add the {{ic|noauto}} parameter to the corresponding entries in {{ic|/etc/crypttab}}. Systemd will then not open the encrypted device on boot, but instead wait until it is actually accessed and then automatically open it with the specified keyfile before mounting it. This might save a few seconds on boot if you are using an encrypted RAID device for example, because systemd doesn't have to wait for the device to become available. For example:
+
See the [http://www.freedesktop.org/software/systemd/man/systemd.service.html#Type= systemd.service(5)] man page for a more detailed explanation of the {{ic|Type}} values.
  
{{hc|/etc/crypttab|
+
=== Editing provided units ===
data /dev/md0 /root/key noauto}}
+
  
==== LVM ====
+
To avoid conflicts with pacman, unit files provided by packages should not be directly edited. There are two safe ways to modify a unit without touching the original file: create a new unit file which overwrites the original unit or create drop-in snippets which are applied on top of the original unit. For both methods, you must reload the unit afterwards to apply your changes. This can be done either by editing the unit with {{ic|systemctl edit}} (which reloads the unit automatically) or by reloading all units with:
  
If you have [[LVM]] volumes not activated via the [[Mkinitcpio|initramfs]], enable the {{ic|lvm-monitoring}} service, which is provided by the {{pkg|lvm2}} package:
+
# systemctl daemon-reload
  
# systemctl enable lvm-monitoring
+
{{Tip|
 +
* You can use ''systemd-delta'' to see which unit files have been overridden or extended and what exactly has been changed.
 +
* Use {{ic|systemctl cat ''unit''}} to view the content of a unit file and all associated drop-in snippets.
 +
* Syntax highlighting for ''systemd'' unit files within [[Vim]] can be enabled by installing {{Pkg|vim-systemd}}.
 +
}}
  
Similarly, if you have LVM on encrypted devices mounted later during boot (e.g. from {{ic|/etc/crypttab}}), enable the {{ic|lvm-on-crypt}} service, which is also provided by the {{pkg|lvm2}} package:
+
==== Replacement unit files ====
  
# systemctl enable lvm-on-crypt
+
To replace the unit file {{ic|/usr/lib/systemd/system/''unit''}}, create the file {{ic|/etc/systemd/system/''unit''}} and reenable the unit to update the symlinks:
  
=== ACPI power management ===
+
# systemctl reenable ''unit''
  
Systemd handles some power-related [[Wikipedia:Advanced_Configuration_and_Power_Interface|ACPI]] events. They can be configured via the following options from {{ic|/etc/systemd/logind.conf}}:
+
Alternatively, run:
  
* {{ic|HandlePowerKey}}: specifies which action is invoked when the power key is pressed.
+
# systemctl edit --full ''unit''
* {{ic|HandleSuspendKey}}: specifies which action is invoked when the suspend key is pressed.
+
* {{ic|HandleHibernateKey}}: specifies which action is invoked when the hibernate key is pressed.
+
* {{ic|HandleLidSwitch}}: specifies which action is invoked when the lid is closed.
+
  
The specified action can be one of {{ic|ignore}}, {{ic|poweroff}}, {{ic|reboot}}, {{ic|halt}}, {{ic|suspend}}, {{ic|hibernate}}, {{ic|hybrid-sleep}}, {{ic|lock}} or {{ic|kexec}}.
+
This opens {{ic|/etc/systemd/system/''unit''}} in your editor (copying the installed version if it does not exist yet) and automatically reloads it when you finish editing.
  
If these options are not configured, systemd will use its defaults: {{ic|1=HandlePowerKey=poweroff}}, {{ic|1=HandleSuspendKey=suspend}}, {{ic|1=HandleHibernateKey=hibernate}}, and {{ic|1=HandleLidSwitch=suspend}}.
+
{{Note|Pacman does not update the replacement unit files when the originals are updated, so this method can make system maintenance more difficult. For this reason the next approach is recommended.}}
  
On systems which run no graphical setup or only a simple window manager like [[i3]] or [[awesome]], this may replace the [[acpid]] daemon which is usually used to react to these ACPI events.
+
==== Drop-in snippets ====
  
{{Note|Run {{ic|systemctl restart systemd-logind.service}} for your changes to take effect.}}
+
To create drop-in snippets for the unit file {{ic|/usr/lib/systemd/system/''unit''}}, create the directory {{ic|/etc/systemd/system/''unit''.d/}} and place ''.conf'' files there to override or add new options. ''systemd'' will parse these ''.conf'' files and apply them on top of the original unit.
  
{{Note|Systemd cannot handle AC and Battery ACPI events, so if you use [[Laptop Mode Tools]] or other similar tools [[acpid]] is still required.}}
+
The easiest way to do this is to run:
  
In the current version of systemd, the {{ic|Handle*}} options will apply throughout the system unless they are "inhibited" (temporarily turned off) by a program, such as a power manager inside a desktop environment. If these inhibits are not taken, you can end up with a situation where systemd suspends your system, then when it wakes up the other power manager suspends it again.
+
# systemctl edit ''unit''
  
{{Warning|Currently, the power managers in the newest versions of [[KDE]] and [[GNOME]] are the only ones that issue the necessary "inhibited" commands. Until the others do, you will need to set the {{ic|Handle}} options to {{ic|ignore}} if you want your ACPI events to be handled by [[Xfce]], [[acpid]] or other programs.}}
+
This opens the file {{ic|/etc/systemd/system/''unit''.d/override.conf}} in your text editor (creating it if necessary) and automatically reloads the unit when you are done editing.
  
{{Note|Systemd can also use other suspend backends (such as [[Uswsusp]] or [[TuxOnIce]]), in addition to the default ''kernel'' backend, in order to put the computer to sleep or hibernate.}}
+
==== Examples ====
  
==== Sleep hooks ====
+
For example, if you simply want to add an additional dependency to a unit, you may create the following file:
  
Systemd does not use [[pm-utils]] to put the machine to sleep when using {{ic|systemctl suspend}}, {{ic|systemctl hibernate}} or {{ic|systemctl hybrid-sleep}}; [[pm-utils]] hooks, including any [[Pm-utils#Creating_your_own_hooks|custom hooks]], will not be run. However, systemd provides two similar mechanisms to run custom scripts on these events.
+
{{hc|/etc/systemd/system/''unit''.d/customdependency.conf|2=
 
+
===== Suspend/resume service files =====
+
 
+
Service files can be hooked into suspend.target, hibernate.target and sleep.target to execute actions before or after suspend/hibernate. Separate files should be created for user actions and root/system actions.  To activate the user service files, {{ic|# systemctl enable suspend@<user> && systemctl enable resume@<user>}}. Examples:
+
 
+
{{hc|/etc/systemd/system/suspend@.service|2=<nowiki>
+
 
[Unit]
 
[Unit]
Description=User suspend actions
+
Requires=''new dependency''
Before=sleep.target
+
After=''new dependency''
 
+
}}
[Service]
+
User=%I
+
Type=forking
+
Environment=DISPLAY=:0
+
ExecStartPre= -/usr/bin/pkill -u %u unison ; /usr/local/bin/music.sh stop ; /usr/bin/mysql -e 'slave stop'
+
ExecStart=/usr/bin/sflock
+
  
[Install]
+
As another example, in order to replace the {{ic|ExecStart}} directive for a unit that is not of type {{ic|oneshot}}, create the following file:
WantedBy=sleep.target</nowiki>}}
+
 
+
{{hc|/etc/systemd/system/resume@.service|2=<nowiki>
+
[Unit]
+
Description=User resume actions
+
After=suspend.target
+
  
 +
{{hc|/etc/systemd/system/''unit''.d/customexec.conf|2=
 
[Service]
 
[Service]
User=%I
+
ExecStart=
Type=simple
+
ExecStart=''new command''
ExecStartPre=/usr/local/bin/ssh-connect.sh
+
}}
ExecStart=/usr/bin/mysql -e 'slave start'
+
  
[Install]
+
Note how {{ic|ExecStart}} must be cleared before being re-assigned ([https://bugzilla.redhat.com/show_bug.cgi?id=756787#c9]).
WantedBy=suspend.target</nowiki>}}
+
  
For root/system actions (activate with {{ic|# systemctl enable root-suspend}}):
+
One more example to automatically restart a service:
 
+
{{hc|/etc/systemd/system/root-resume.service|2=<nowiki>
+
[Unit]
+
Description=Local system resume actions
+
After=suspend.target
+
  
 +
{{hc|/etc/systemd/system/''unit''.d/restart.conf|2=
 
[Service]
 
[Service]
Type=simple
+
Restart=always
ExecStart=/usr/bin/systemctl restart mnt-media.automount
+
RestartSec=30
 +
}}
  
[Install]
+
== Targets ==
WantedBy=suspend.target</nowiki>}}
+
  
{{hc|/etc/systemd/system/root-suspend.service|2=<nowiki>
+
{{Style|Unclear description, copy-pasted content (explicitly mentions "Fedora").|section=Make section "Targets" more clearly}}
[Unit]
+
Description=Local system suspend actions
+
Before=sleep.target
+
  
[Service]
+
''systemd'' uses ''targets'' which serve a similar purpose as runlevels but act a little different. Each ''target'' is named instead of numbered and is intended to serve a specific purpose with the possibility of having multiple ones active at the same time. Some ''target''s are implemented by inheriting all of the services of another ''target'' and adding additional services to it. There are ''systemd'' ''target''s that mimic the common SystemVinit runlevels so you can still switch ''target''s using the familiar {{ic|telinit RUNLEVEL}} command.
Type=simple
+
ExecStart=-/usr/bin/pkill sshfs
+
  
[Install]
+
=== Get current targets ===
WantedBy=sleep.target</nowiki>}}
+
  
A couple of handy hints about these service files (more in {{ic|man systemd.service}}):
+
The following should be used under ''systemd'' instead of running {{ic|runlevel}}:
* If {{ic|1=<nowiki>Type=OneShot</nowiki>}} then you can use multiple {{ic|1=<nowiki>ExecStart=</nowiki>}} lines. Otherwise only one ExecStart line is allowed. You can add more commands with either {{ic|ExecStartPre}} or by separating commands with a semicolon (see the first example above -- note the spaces before and after the semicolon...these are required!).
+
* A command prefixed with '-' will cause a non-zero exit status to be ignored and treated as a successful command.
+
* The best place to find errors when troubleshooting these service files is of course with {{ic|journalctl}}.
+
  
===== Combined Suspend/resume service file =====
+
$ systemctl list-units --type=target
  
With the combined suspend/resume service file, a single hook does all the work for different phases (sleep/resume) and for different targets (suspend/hibernate/hybrid-sleep).
+
=== Create custom target ===
  
Example and explanation:
+
The runlevels that held a defined meaning under sysvinit (i.e., 0, 1, 3, 5, and 6); have a 1:1 mapping with a specific ''systemd'' ''target''. Unfortunately, there is no good way to do the same for the user-defined runlevels like 2 and 4. If you make use of those it is suggested that you make a new named ''systemd'' ''target'' as {{ic|/etc/systemd/system/''your target''}} that takes one of the existing runlevels as a base (you can look at {{ic|/usr/lib/systemd/system/graphical.target}} as an example), make a directory {{ic|/etc/systemd/system/''your target''.wants}}, and then symlink the additional services from {{ic|/usr/lib/systemd/system/}} that you wish to enable.
  
{{hc|/etc/systemd/system/wicd-sleep.service|2=<nowiki>
+
=== Targets table ===
[Unit]
+
Description=Wicd sleep hook
+
Before=sleep.target
+
StopWhenUnneeded=yes
+
  
[Service]
+
{| class="wikitable"
Type=oneshot
+
! SysV Runlevel !! systemd Target !! Notes
RemainAfterExit=yes
+
|-
ExecStart=-/usr/share/wicd/daemon/suspend.py
+
| 0 || runlevel0.target, poweroff.target || Halt the system.
ExecStop=-/usr/share/wicd/daemon/autoconnect.py
+
|-
 +
| 1, s, single || runlevel1.target, rescue.target || Single user mode.
 +
|-
 +
| 2, 4 || runlevel2.target, runlevel4.target, multi-user.target || User-defined/Site-specific runlevels. By default, identical to 3.
 +
|-
 +
| 3 || runlevel3.target, multi-user.target || Multi-user, non-graphical. Users can usually login via multiple consoles or via the network.
 +
|-
 +
| 5 || runlevel5.target, graphical.target || Multi-user, graphical. Usually has all the services of runlevel 3 plus a graphical login.
 +
|-
 +
| 6 || runlevel6.target, reboot.target || Reboot
 +
|-
 +
| emergency || emergency.target || Emergency shell
 +
|-
 +
|}
  
[Install]
+
=== Change current target ===
WantedBy=sleep.target</nowiki>}}
+
  
* {{ic|1=<nowiki>RemainAfterExit=yes</nowiki>}}: After started, the service is considered active until it is explicitly stopped.
+
In ''systemd'' targets are exposed via ''target units''. You can change them like this:
* {{ic|1=<nowiki>StopWhenUnneeded=yes</nowiki>}}: When active, the service will be stopped if no other active service requires it. In this specific example, it will be stopped after sleep.target is stopped.
+
* Because sleep.target is pulled in by suspend.target, hibernate.target and hybrid-sleep.target and sleep.target itself is a StopWhenUnneeded service, the hook is guaranteed to start/stop properly for different tasks.
+
  
===== Hooks in /usr/lib/systemd/system-sleep =====
+
# systemctl isolate graphical.target
  
Systemd runs all executables in {{ic|/usr/lib/systemd/system-sleep/}}, passing two arguments to each of them:
+
This will only change the current target, and has no effect on the next boot. This is equivalent to commands such as {{ic|telinit 3}} or {{ic|telinit 5}} in Sysvinit.
  
* Argument 1: either {{ic|pre}} or {{ic|post}}, depending on whether the machine is going to sleep or waking up
+
=== Change default target to boot into ===
* Argument 2: {{ic|suspend}}, {{ic|hibernate}} or {{ic|hybrid-sleep}}, depending on which is being invoked
+
  
In contrast to [[pm-utils]], systemd will run these scripts concurrently and not one after another.
+
The standard target is {{ic|default.target}}, which is aliased by default to {{ic|graphical.target}} (which roughly corresponds to the old runlevel 5). To change the default target at boot-time, append one of the following [[kernel parameters]] to your bootloader:
  
The output of any custom script will be logged by {{ic|systemd-suspend.service}}, {{ic|systemd-hibernate.service}} or {{ic|systemd-hybrid-sleep.service}}. You can see its output in systemd's [[Systemd#Journal|journal]]:
+
* {{ic|1=systemd.unit=multi-user.target}} (which roughly corresponds to the old runlevel 3),
# journalctl -b -u systemd-suspend
+
* {{ic|1=systemd.unit=rescue.target}} (which roughly corresponds to the old runlevel 1).
  
Note that you can also use {{ic|sleep.target}}, {{ic|suspend.target}}, {{ic|hibernate.target}} or {{ic|hybrid-sleep.target}} to hook units into the sleep state logic instead of using custom scripts.
+
Alternatively, you may leave the bootloader alone and change {{ic|default.target}}. This can be done using ''systemctl'':
  
An example of a custom sleep script:
+
# systemctl set-default multi-user.target
  
{{hc|/usr/lib/systemd/system-sleep/example.sh|
+
To be able to override the previously set {{ic|default.target}}, use the force option:
#!/bin/sh
+
case $1/$2 in
+
  pre/*)
+
    echo "Going to $2..."
+
    ;;
+
  post/*)
+
    echo "Waking up from $2..."
+
    ;;
+
esac}}
+
  
Don't forget to make your script executable:
+
  # systemctl set-default -f multi-user.target
  # chmod a+x /usr/lib/systemd/system-sleep/example.sh
+
  
See {{ic|man 7 systemd.special}} and {{ic|man 8 systemd-sleep}} for more details.
+
The effect of this command is output by ''systemctl''; a symlink to the new default target is made at {{ic|/etc/systemd/system/default.target}}.
  
=== Temporary files ===
+
== Temporary files ==
  
Systemd-tmpfiles uses configuration files in {{ic|/usr/lib/tmpfiles.d/}} and {{ic|/etc/tmpfiles.d/}} to describe the creation, cleaning and removal of volatile and temporary files and directories which usually reside in directories such as {{ic|/run}} or {{ic|/tmp}}. Each configuration file is named in the style of {{ic|/etc/tmpfiles.d/<program>.conf}}. This will also override any files in {{ic|/usr/lib/tmpfiles.d/}} with the same name.
+
"''systemd-tmpfiles'' creates, deletes and cleans up volatile and temporary files and directories." It reads configuration files in {{ic|/etc/tmpfiles.d/}} and {{ic|/usr/lib/tmpfiles.d/}} to discover which actions to perform. Configuration files in the former directory take precedence over those in the latter directory.
  
tmpfiles are usually provided together with service files to create directories which are expected to exist by certain daemons. For example the [[Samba]] daemon expects the directory {{ic|/run/samba}} to exist and to have the correct permissions. The corresponding tmpfile looks like this:
+
Configuration files are usually provided together with service files, and they are named in the style of {{ic|/usr/lib/tmpfiles.d/''program''.conf}}. For example, the [[Samba]] daemon expects the directory {{ic|/run/samba}} to exist and to have the correct permissions. Therefore, the {{Pkg|samba}} package ships with this configuration:
  
 
{{hc|/usr/lib/tmpfiles.d/samba.conf|
 
{{hc|/usr/lib/tmpfiles.d/samba.conf|
 
D /run/samba 0755 root root}}
 
D /run/samba 0755 root root}}
  
tmpfiles may also be used to write values into certain files on boot. For example, if you use {{ic|/etc/rc.local}} to disable wakeup from USB devices with {{ic|echo USBE > /proc/acpi/wakeup}}, you may use the following tmpfile instead:
+
Configuration files may also be used to write values into certain files on boot. For example, if you used {{ic|/etc/rc.local}} to disable wakeup from USB devices with {{ic|echo USBE > /proc/acpi/wakeup}}, you may use the following tmpfile instead:
  
 
{{hc|/etc/tmpfiles.d/disable-usb-wake.conf|
 
{{hc|/etc/tmpfiles.d/disable-usb-wake.conf|
 
w /proc/acpi/wakeup - - - - USBE}}
 
w /proc/acpi/wakeup - - - - USBE}}
  
See {{ic|man 5 tmpfiles.d}} for details.
+
See the {{ic|systemd-tmpfiles(8)}} and {{ic|tmpfiles.d(5)}} man pages for details.
{{note|This method may not work to set options in {{ic|/sys}} since the {{ic|systemd-tmpfiles-setup}} service may run before the appropriate device modules is loaded. In this case you could check whether the module has a parameter for the option you want to set with {{ic|modinfo <module>}} and set this option with a [[Modprobe.d#Configuration|config file in {{ic|/etc/modprobe.d}}]]. Otherwise you will have to write a [[Udev#About_udev_rules|udev rule]] to set the appropriate attribute as soon as the device appears.}}
+
  
=== Units ===
+
{{Note|This method may not work to set options in {{ic|/sys}} since the ''systemd-tmpfiles-setup'' service may run before the appropriate device modules is loaded. In this case you could check whether the module has a parameter for the option you want to set with {{ic|modinfo ''module''}} and set this option with a [[Kernel modules#Setting module options|config file in /etc/modprobe.d]]. Otherwise you will have to write a [[Udev#About_udev_rules|udev rule]] to set the appropriate attribute as soon as the device appears.}}
  
A unit configuration file encodes information about a service, a socket, a device, a mount point, an automount point, a swap file or partition, a start-up target, a file system path or a timer controlled and supervised by systemd. The syntax is inspired by XDG Desktop Entry Specification .desktop files, which are in turn inspired by Microsoft Windows .ini files.
+
== Timers ==
  
See {{ic|man 5 systemd.unit}} for details.
+
A timer is a unit configuration file whose name ends with ''.timer'' and encodes information about a timer controlled and supervised by ''systemd'', for timer-based activation. See [[systemd/Timers]].
  
== Basic systemctl usage  ==
+
{{Note|Timers can replace ''cron'' functionality to a great extent. See [[systemd/Timers#As a cron replacement]].}}
  
The main command used to introspect and control systemd is {{ic|systemctl}}. Some of its uses are examining the system state and managing the system and services. See {{ic|man 1 systemctl}} for more details.
+
== Mounting ==
  
{{Tip|You can use all of the following {{ic|systemctl}} commands with the {{ic|-H <user>@<host>}} switch to control a systemd instance on a remote machine. This will use [[SSH]] to connect to the remote systemd instance.}}
+
Since systemd is a replacement for System V init, it is in charge of the mounts specified in {{ic|/etc/fstab}}. In fact, it goes beyond the usual {{ic|fstab}} capabilities, implementing special mount options prefixed with {{ic|x-systemd.}}. See [[Fstab#Automount_with_systemd]] for an example of ''automounting'' (mounting on-demand) using these extensions. See [https://www.freedesktop.org/software/systemd/man/systemd.mount.html#fstab] for the complete documentation of these extensions.
  
{{Note|{{ic|systemadm}} is the official graphical frontend for {{ic|systemctl}}. It is provided by the {{AUR|systemd-ui-git}} package from the [[AUR]].}}
+
== Journal ==
  
=== Analyzing the system state ===
+
''systemd'' has its own logging system called the journal; therefore, running a {{ic|syslog}} daemon is no longer required. To read the log, use:
  
List running units:
+
# journalctl
  
  $ systemctl
+
In Arch Linux, the directory {{ic|/var/log/journal/}} is a part of the {{Pkg|systemd}} package, and the journal (when {{ic|1=Storage=}} is set to {{ic|auto}} in {{ic|/etc/systemd/journald.conf}}) will write to {{ic|/var/log/journal/}}. If you or some program delete that directory, ''systemd'' will '''not''' recreate it automatically and instead will write its logs to {{ic|/run/systemd/journal}} in a nonpersistent way. However, the folder will be recreated when you set {{ic|1=Storage=persistent}} and run {{ic|systemctl restart systemd-journald}} (or reboot).
  
or:
+
=== Filtering output ===
  
$ systemctl list-units
+
''journalctl'' allows you to filter the output by specific fields. Be aware that if there are many messages to display or filtering of large time span has to be done, the output of this command can be delayed for quite some time.
  
List failed units:
+
{{Tip|While the journal is stored in a binary format, the content of stored messages is not modified. This means it is viewable with ''strings'', for example for recovery in an environment which does not have ''systemd'' installed. Example command:
 +
{{bc|$ strings /mnt/arch/var/log/journal/af4967d77fba44c6b093d0e9862f6ddd/system.journal <nowiki>| grep -i</nowiki> ''message''}}
 +
}}
  
$ systemctl --failed
+
Examples:
  
The available unit files can be seen in {{ic|/usr/lib/systemd/system/}} and {{ic|/etc/systemd/system/}} (the latter takes precedence). You can see list installed unit files by:
+
* Show all messages from this boot: {{bc|# journalctl -b}} However, often one is interested in messages not from the current, but from the previous boot (e.g. if an unrecoverable system crash happened). This is possible through optional offset parameter of the {{ic|-b}} flag: {{ic|journalctl -b -0}} shows messages from the current boot, {{ic|journalctl -b -1}} from the previous boot, {{ic|journalctl -b -2}} from the second previous and so on. See {{ic|man 1 journalctl}} for full description, the semantics is much more powerful.
 +
* Show all messages from date (and optional time): {{bc|1=# journalctl --since="2012-10-30 18:17:16"}}
 +
* Show all messages since 20 minutes ago: {{bc|1=# journalctl --since "20 min ago"}}
 +
* Follow new messages: {{bc|# journalctl -f}}
 +
* Show all messages by a specific executable: {{bc|# journalctl /usr/lib/systemd/systemd}}
 +
* Show all messages by a specific process: {{bc|1=# journalctl _PID=1}}
 +
* Show all messages by a specific unit: {{bc|# journalctl -u netcfg}}
 +
* Show kernel ring buffer: {{bc|1=# journalctl -k}}
 +
* Show auth.log equivalent by filtering on syslog facility: {{bc|1=# journalctl -f -l SYSLOG_FACILITY=10}}
  
$ systemctl list-unit-files
+
See {{ic|man 1 journalctl}}, {{ic|man 7 systemd.journal-fields}}, or Lennart's [http://0pointer.de/blog/projects/journalctl.html blog post] for details.
  
=== Using units ===
+
{{Tip|1=
 +
By default, ''journalctl'' truncates lines longer than screen width, but in some cases, it may be better to enable wrapping instead of truncating. This can be controlled by the {{ic|SYSTEMD_LESS}} [[environment variable]], which contains options passed to [[Core utilities#less|less]] (the default pager) and defaults to {{ic|FRSXMK}} (see {{ic|man 1 less}} and {{ic|man 1 journalctl}} for details).
  
Units can be, for example, services ({{ic|.service}}), mount points ({{ic|.mount}}), devices ({{ic|.device}}) or sockets ({{ic|.socket}}).
+
By omitting the {{ic|S}} option, the output will be wrapped instead of truncated. For example, start ''journalctl'' as follows:
  
When using {{ic|systemctl}}, you generally have to specify the complete name of the unit file, including its suffix, for example {{ic|sshd.socket}}. There are however a few shortforms when specifying the unit in the following {{ic|systemctl}} commands:
+
$ SYSTEMD_LESS=FRXMK journalctl
  
* If you don't specify the suffix, systemctl will assume {{ic|.service}}. For example, {{ic|netcfg}} and {{ic|netcfg.service}} are treated equivalent.
+
If you would like to set this behaviour as default, [[Environment variables#Per_user|export]] the variable from {{ic|~/.bashrc}} or {{ic|~/.zshrc}}.
* Mount points will automatically be translated into the appropriate {{ic|.mount}} unit. For example, specifying {{ic|/home}} is equivalent to {{ic|home.mount}}.
+
}}
* Similiar to mount points, devices are automatically translated into the appropriate {{ic|.device}} unit, therefore specifying {{ic|/dev/sda2}} is equivalent to {{ic|dev-sda2.device}}.
+
  
See {{ic|man systemd.unit}} for details.
+
=== Journal size limit ===
  
Activate a unit immediately:
+
If the journal is persistent (non-volatile), its size limit is set to a default value of 10% of the size of the respective file system. For example, with {{ic|/var/log/journal}} located on a 50 GiB root partition this would lead to 5 GiB of journal data. The maximum size of the persistent journal can be controlled by uncommenting and changing the following:
  
# systemctl start <unit>
+
{{hc|/etc/systemd/journald.conf|2=
 +
SystemMaxUse=50M
 +
}}
  
Deactivate a unit immediately:
+
Refer to {{ic|man journald.conf}} for more info.
  
# systemctl stop <unit>
+
=== Clean journal files manually ===
  
Restart a unit:
+
The journal files are located under {{ic|/var/log/journal}}, {{ic|rm}} will do the work.
 +
Or, use {{ic|journalctl}},
  
# systemctl restart <unit>
+
Examples:
  
Ask a unit to reload its configuration:
+
* Remove archived journal files until the disk space they use falls below 100M: {{bc|1=# journalctl --vacuum-size=100M}}
 +
* Make all journal files contain no data older than 2 weeks. {{bc|1=# journalctl --vacuum-time=2weeks}}
  
# systemctl reload <unit>
+
Refer to {{ic|man journalctl}} for more info.
  
Show the status of a unit, including whether it is running or not:
+
=== Journald in conjunction with syslog ===
  
$ systemctl status <unit>
+
Compatibility with a classic, non-journald aware [[Syslog-ng|syslog]] implementation can be provided by letting ''systemd'' forward all messages via the socket {{ic|/run/systemd/journal/syslog}}. To make the syslog daemon work with the journal, it has to bind to this socket instead of {{ic|/dev/log}} ([http://lwn.net/Articles/474968/ official announcement]).
  
Check whether a unit is already enabled or not:
+
The default {{ic|journald.conf}} for forwarding to the socket is {{ic|1=ForwardToSyslog=no}} to avoid system overhead, because [[rsyslog]] or [[syslog-ng]] pull the messages from the journal by [http://lists.freedesktop.org/archives/systemd-devel/2014-August/022295.html#journald itself].
  
$ systemctl is-enabled <unit>
+
See [[Syslog-ng#Overview]] and [[Syslog-ng#syslog-ng and systemd journal]], or [[rsyslog]] respectively, for details on configuration.
  
Enable a unit to be started on bootup:
+
=== Forward journald to /dev/tty12 ===
  
# systemctl enable <unit>
+
Create a [[#Editing provided units|drop-in directory]] {{ic|/etc/systemd/journald.conf.d}} and create a {{ic|fw-tty12.conf}} file in it:
  
{{Note|Services without an {{ic|[Install]}} section are usually called automatically by other services. If you need to install them manually, use the following command, replacing {{ic|foo}} with the name of the service.
+
{{hc|1=/etc/systemd/journald.conf.d/fw-tty12.conf|2=
# ln -s /usr/lib/systemd/system/''foo''.service /etc/systemd/system/graphical.target.wants/
+
[Journal]
 +
ForwardToConsole=yes
 +
TTYPath=/dev/tty12
 +
MaxLevelConsole=info
 
}}
 
}}
  
Disable a unit to not start during bootup:
+
Then [[restart]] systemd-journald.
  
# systemctl disable <unit>
+
=== Specify a different journal to view ===
 +
There may be a need to check the logs of another system that is dead in the water, like booting from a live system to recover a production system. In such case, one can mount the disk in e.g. {{ic|/mnt}}, and specify the journal path via {{ic|-D}}/{{ic|--directory}}, like so:
  
Show the manual page associated with a unit (this has to be supported by the unit file):
+
$ journalctl -D ''/mnt''/var/log/journal -xe
  
$ systemctl help <unit>
+
== Troubleshooting ==
  
Reload systemd, scanning for new or changed units:
+
=== Investigating systemd errors ===
  
# systemctl daemon-reload
+
As an example, we will investigate an error with {{ic|systemd-modules-load}} service:
  
=== Power management ===
+
'''1.''' Lets find the ''systemd'' services which fail to start:
{{ic|polkit}} is necessary for power management.
+
If you are in a local {{ic|systemd-logind}} user session and no other session is active, the following commands will work without root privileges. If not (for example, because another user is logged into a tty), systemd will automatically ask you for the root password.
+
  
Shut down and reboot the system:
+
{{hc|1=$ systemctl --failed|2=
 +
systemd-modules-load.service  loaded '''failed failed'''  Load Kernel Modules
 +
}}
  
$ systemctl reboot
+
'''2.''' Ok, we found a problem with {{ic|systemd-modules-load}} service. We want to know more:
 +
{{hc|$ systemctl status systemd-modules-load|2=
 +
systemd-modules-load.service - Load Kernel Modules
 +
  Loaded: loaded (/usr/lib/systemd/system/systemd-modules-load.service; static)
 +
  Active: '''failed''' (Result: exit-code) since So 2013-08-25 11:48:13 CEST; 32s ago
 +
    Docs: man:systemd-modules-load.service(8).
 +
          man:modules-load.d(5)
 +
  Process: '''15630''' ExecStart=/usr/lib/systemd/systemd-modules-load ('''code=exited, status=1/FAILURE''')
 +
}}
 +
If the {{ic|Process ID}} is not listed, just restart the failed service with {{ic|systemctl restart systemd-modules-load}}
  
Shut down and power-off the system:
+
'''3.''' Now we have the process id (PID) to investigate this error in depth. Enter the following command with the current {{ic|Process ID}} (here: 15630):
 +
{{hc|1=$ journalctl _PID=15630|2=
 +
-- Logs begin at Sa 2013-05-25 10:31:12 CEST, end at So 2013-08-25 11:51:17 CEST. --
 +
Aug 25 11:48:13 mypc systemd-modules-load[15630]: '''Failed to find module 'blacklist usblp''''
 +
Aug 25 11:48:13 mypc systemd-modules-load[15630]: '''Failed to find module 'install usblp /bin/false''''
 +
}}
  
$ systemctl poweroff
+
'''4.''' We see that some of the kernel module configs have wrong settings. Therefore we have a look at these settings in {{ic|/etc/modules-load.d/}}:
 +
{{hc|$ ls -Al /etc/modules-load.d/|
 +
...
 +
-rw-r--r--  1 root root    79  1. Dez 2012  blacklist.conf
 +
-rw-r--r--  1 root root    1  2. Mär 14:30 encrypt.conf
 +
-rw-r--r--  1 root root    3  5. Dez 2012  printing.conf
 +
-rw-r--r--  1 root root    6 14. Jul 11:01 realtek.conf
 +
-rw-r--r--  1 root root    65  2. Jun 23:01 virtualbox.conf
 +
...
 +
}}
  
Suspend the system:
+
'''5.''' The {{ic|Failed to find module 'blacklist usblp'}} error message might be related to a wrong setting inside of {{ic|blacklist.conf}}. Lets deactivate it with inserting a trailing '''#''' before each option we found via step 3:
 +
{{hc|/etc/modules-load.d/blacklist.conf|
 +
'''#''' blacklist usblp
 +
'''#''' install usblp /bin/false
 +
}}
  
  $ systemctl suspend
+
'''6.''' Now, try to start {{ic|systemd-modules-load}}:
 +
  $ systemctl start systemd-modules-load
 +
If it was successful, this should not prompt anything. If you see any error, go back to step 3 and use the new PID for solving the errors left.
  
Put the system into hibernation:
+
If everything is ok, you can verify that the service was started successfully with:
 +
{{hc|$ systemctl status systemd-modules-load|2=
 +
systemd-modules-load.service - Load Kernel Modules
 +
  Loaded: '''loaded''' (/usr/lib/systemd/system/systemd-modules-load.service; static)
 +
  Active: '''active (exited)''' since So 2013-08-25 12:22:31 CEST; 34s ago
 +
    Docs: man:systemd-modules-load.service(8)
 +
          man:modules-load.d(5)
 +
Process: 19005 ExecStart=/usr/lib/systemd/systemd-modules-load (code=exited, status=0/SUCCESS)
 +
Aug 25 12:22:31 mypc systemd[1]: '''Started Load Kernel Modules'''.
 +
}}
  
$ systemctl hibernate
+
Often you can solve these kind of problems like shown above. For further investigation look at [[#Diagnosing boot problems]].
  
Put the system into hybrid-sleep state (or suspend-to-both):
+
=== Diagnosing boot problems ===
  
$ systemctl hybrid-sleep
+
''systemd'' has several options for diagnosing problems with the boot process. See [[boot debugging]] and the [http://freedesktop.org/wiki/Software/systemd/Debugging/ systemd debugging documentation].
  
== Running DEs under systemd ==
+
=== Diagnosing problems with a specific service ===
  
To enable graphical login, run your preferred [[Display Manager]] daemon (e.g. [[KDM]]). At the moment, service files exist for [[GDM]], [[KDM]], [[SLiM]], [[XDM]], [[LXDM]] and [[LightDM]].
+
{{Accuracy|This may not catch all errors such as missing libraries.|User talk:Alucryd#Plex}}
  
# systemctl enable kdm
+
If some ''systemd'' service misbehaves and you want to get more information about what is going on, set the {{ic|SYSTEMD_LOG_LEVEL}} [[environment variable]] to {{ic|debug}}. For example, to run the ''systemd-networkd'' daemon in debug mode:
  
This should work out of the box. If not, you might have a {{ic|default.target}} set manually or from a older install:
+
# systemctl stop systemd-networkd
 +
# SYSTEMD_LOG_LEVEL=debug /lib/systemd/systemd-networkd
  
{{hc|# ls -l /etc/systemd/system/default.target|
+
Or, equivalently, modify the service file temporarily for gathering enough output. For example:
/etc/systemd/system/default.target -> /usr/lib/systemd/system/graphical.target}}
+
  
Simply delete the symlink and systemd will use its stock {{ic|default.target}} (i.e. {{ic|graphical.target}}).
+
{{hc|/usr/lib/systemd/system/systemd-networkd.service|2=
 +
[Service]
 +
...
 +
Environment=SYSTEMD_LOG_LEVEL=debug
 +
....
 +
}}
  
# rm /etc/systemd/system/default.target
+
If debug information is required long-term, add the variable the [[#Editing provided units|regular]] way.
  
=== Using systemd-logind ===
+
=== Shutdown/reboot takes terribly long ===
  
{{Note|As of 2012-10-30, [[ConsoleKit]] has been [https://www.archlinux.org/news/consolekit-replaced-by-logind/ replaced by systemd-logind] as the default mechanism to login to the DE.}}
+
If the shutdown process takes a very long time (or seems to freeze) most likely a service not exiting is to blame. ''systemd'' waits some time for each service to exit before trying to kill it. To find out if you are affected, see [http://freedesktop.org/wiki/Software/systemd/Debugging/#shutdowncompleteseventually this article].
  
In order to check the status of your user session, you can use {{ic|loginctl}}. All [[PolicyKit]] actions like suspending the system or mounting external drives will work out of the box.
+
=== Short lived processes do not seem to log any output ===
  
$ loginctl show-session $XDG_SESSION_ID
+
If {{ic|journalctl -u foounit}} does not show any output for a short lived service, look at the PID instead. For example, if {{ic|systemd-modules-load.service}} fails, and {{ic|systemctl status systemd-modules-load}} shows that it ran as PID 123, then you might be able to see output in the journal for that PID, i.e. {{ic|journalctl -b _PID&#61;123}}. Metadata fields for the journal such as {{ic|_SYSTEMD_UNIT}} and {{ic|_COMM}} are collected asynchronously and rely on the {{ic|/proc}} directory for the process existing. Fixing this requires fixing the kernel to provide this data via a socket connection, similar to {{ic|SCM_CREDENTIALS}}.
  
== Writing custom .service files ==
+
=== Disabling application crash dumps journaling ===
''See: [[Systemd/Services]]''
+
  
=== Handling dependencies ===
+
Edit the file {{ic|/etc/systemd/coredump.conf}} by adding this line:
  
With systemd, dependencies can be resolved by designing the unit files correctly. The most typical case is that the unit {{ic|A}} requires the unit {{ic|B}} to be running before {{ic|A}} is started. In that case add {{ic|1=Requires=B}} and {{ic|1=After=B}} to the {{ic|[Unit]}} section of {{ic|A}}. If the dependency is optional, add {{ic|1=Wants=B}} and {{ic|1=After=B}} instead. Note that {{ic|1=Wants=}} and {{ic|1=Requires=}} do not imply {{ic|1=After=}}, meaning that if {{ic|1=After=}} is not specified, the two units will be started in parallel.
+
  Storage=none
  
Dependencies are typically placed on services and not on targets. For example, {{ic|network.target}} is pulled in by whatever service configures your network interfaces, therefore ordering your custom unit after it is sufficient since {{ic|network.target}} is started anyway.
+
and run:
 
+
=== Type ===
+
 
+
There are several different start-up types to consider when writing a custom service file. This is set with the {{ic|1=Type=}} parameter in the {{ic|[Service]}} section. See {{ic|man systemd.service}} for a more detailed explanation.
+
 
+
* {{ic|1=Type=simple}} (default): systemd considers the service to be started up immediately. The process must not fork. Do not use this type if other services need to be ordered on this service, unless it is socket activated.
+
* {{ic|1=Type=forking}}: systemd considers the service started up once the process forks and the parent has exited. For classic daemons use this type unless you know that it is not necessary. You should specify {{ic|1=PIDFile=}} as well so systemd can keep track of the main process.
+
* {{ic|1=Type=oneshot}}: This is useful for scripts that do a single job and then exit. You may want to set {{ic|1=RemainAfterExit=yes}} as well so that systemd still considers the service as active after the process has exited.
+
* {{ic|1=Type=notify}}: Identical to {{ic|1=Type=simple}}, but with the stipulation that the daemon will send a signal to systemd when it is ready. The reference implementation for this notification is provided by {{ic|libsystemd-daemon.so}}.
+
* {{ic|1=Type=dbus}}: The service is considered ready when the specified {{ic|BusName}} appears on DBus's system bus.
+
 
+
=== Editing provided unit files ===
+
 
+
To edit a unit file provided by a package, you can create a directory called {{ic|/etc/systemd/system/<unit>.d/}} for example {{ic|/etc/systemd/system/httpd.service.d/}}  and place {{ic|*.conf}} files in there to override or add new options. Systemd will parse these {{ic|*.conf}} files and apply them on top of the original unit. For example, if you simply want to add an additional dependency to a unit, you may create the following file:
+
 
+
{{hc|/etc/systemd/system/<unit>.d/customdependency.conf|2=
+
[Unit]
+
Requires=<new dependency>
+
After=<new dependency>}}
+
 
+
Then run the following for your changes to take effect:
+
  
 
  # systemctl daemon-reload
 
  # systemctl daemon-reload
# systemctl restart <unit>
 
  
Alternatively you can copy the old unit file from {{ic|/usr/lib/systemd/system/}} to {{ic|/etc/systemd/system/}} and make your changes there. A unit file in {{ic|/etc/systemd/system/}} always overrides the same unit in {{ic|/usr/lib/systemd/system/}}. Note that when the original unit in {{ic|/usr/lib/}} is changed due to a package upgrade, these changes will not automatically apply to your custom unit file in {{ic|/etc/}}. Additionally you will have to manually reenable the unit with {{ic|systemctl reenable <unit>}}. It is therefore recommended to use the {{ic|*.conf}} method described before instead.
+
to reload the configuration.
  
{{Tip|You can use {{ic|systemd-delta}} to see which unit files have been overridden and what exactly has been changed.}} As the provided unit files will be updated from time to time, use systemd-delta for system maintenance.
+
=== Boot time increasing over time ===
  
=== Syntax highlighting for units within Vim ===
+
After using {{ic|systemd-analyze}} a number of users have noticed that their boot time has increased significantly in comparison with what it used to be. After using {{ic|systemd-analyze blame}} [[NetworkManager]] is being reported as taking an unusually large amount of time to start.
  
Syntax highlighting for systemd unit files within [[Vim]] can be enabled by installing {{Pkg|vim-systemd}} from the [[Official Repositories|official repositories]].
+
The problem for some users has been due to {{ic|/var/log/journal}} becoming too large. This may have other impacts on performance, such as for {{ic|systemctl status}} or {{ic|journalctl}}. As such the solution is to remove every file within the folder (ideally making a backup of it somewhere, at least temporarily) and then setting a journal file size limit as described in [[#Journal size limit]].
  
== Targets ==
+
=== systemd-tmpfiles-setup.service fails to start at boot ===
  
Systemd uses ''targets'' which serve a similar purpose as runlevels but act a little different. Each ''target'' is named instead of numbered and is intended to serve a specific purpose with the possibility of having multiple ones active at the same time. Some ''targets'' are implemented by inheriting all of the services of another ''target'' and adding additional services to it. There are systemd ''target''s that mimic the common SystemVinit runlevels so you can still switch ''target''s using the familiar {{ic|telinit RUNLEVEL}} command.
+
Starting with systemd 219, {{ic|/usr/lib/tmpfiles.d/systemd.conf}} specifies ACL attributes for directories under {{ic|/var/log/journal}} and, therefore, requires ACL support to be enabled for the filesystem the journal resides on.
  
=== Get current targets ===
+
See [[Access Control Lists#Enabling ACL]] for instructions on how to enable ACL on the filesystem that houses {{ic|/var/log/journal}}.
  
The following should be used under systemd instead of {{ic|runlevel}}:
+
=== systemctl enable fails for symlinks in /etc/systemd/system ===
  
$ systemctl list-units --type=target
+
If {{ic|/etc/systemd/system/''foo''.service}} is a symlink and {{ic|systemctl enable ''foo''.service}} is run, it will fail with this error:
  
=== Create custom target ===
+
Failed to issue method call: No such file or directory
  
The runlevels that are assigned a specific purpose on vanilla Fedora installs; 0, 1, 3, 5, and 6; have a 1:1 mapping with a specific systemd ''target''. Unfortunately, there is no good way to do the same for the user-defined runlevels like 2 and 4. If you make use of those it is suggested that you make a new named systemd ''target'' as {{ic|/etc/systemd/system/<your target>}} that takes one of the existing runlevels as a base (you can look at {{ic|/usr/lib/systemd/system/graphical.target}} as an example), make a directory {{ic|/etc/systemd/system/<your target>.wants}}, and then symlink the additional services from {{ic|/usr/lib/systemd/system/}} that you wish to enable.
+
This is a [https://bugzilla.redhat.com/show_bug.cgi?id=955379#c14 design choice] of systemd. As a workaround, enabling by absolute path works:
  
=== Targets table ===
+
# systemctl enable ''/absolute/path/foo''.service
  
{| border="1"
+
=== dependent services are not started when starting a service manually===
! SysV Runlevel !! systemd Target !! Notes
+
|-
+
| 0 || runlevel0.target, poweroff.target || Halt the system.
+
|-
+
| 1, s, single || runlevel1.target, rescue.target || Single user mode.
+
|-
+
| 2, 4 || runlevel2.target, runlevel4.target, multi-user.target || User-defined/Site-specific runlevels. By default, identical to 3.
+
|-
+
| 3 || runlevel3.target, multi-user.target || Multi-user, non-graphical. Users can usually login via multiple consoles or via the network.
+
|-
+
| 5 || runlevel5.target, graphical.target || Multi-user, graphical. Usually has all the services of runlevel 3 plus a graphical login.
+
|-
+
| 6 || runlevel6.target, reboot.target || Reboot
+
|-
+
| emergency || emergency.target || Emergency shell
+
|-
+
|}
+
  
=== Change current target ===
+
{{Remove|Guesswork instead of actual research, and bug reports belong to the bug tracker, not to the wiki.|section=Subsection .22dependent services are not started when starting a service manually.22}}
  
In systemd targets are exposed via "target units". You can change them like this:
+
One (in)famomus example is {{ic|libvirtd.service}} which needs the {{ic|virtlogd.socket}} to function properly.  
 
+
# systemctl isolate graphical.target
+
 
+
This will only change the current target, and has no effect on the next boot. This is equivalent to commands such as {{ic|telinit 3}} or {{ic|telinit 5}} in Sysvinit.
+
 
+
=== Change default target to boot into ===
+
 
+
The standard target is {{ic|default.target}}, which is aliased by default to {{ic|graphical.target}} (which roughly corresponds to the old runlevel 5). To change the default target at boot-time, append one of the following [[kernel parameters]] to your bootloader:
+
 
+
{{Tip|The {{ic|.target}} extension can be left out.}}
+
 
+
* {{ic|1=systemd.unit=multi-user.target}} (which roughly corresponds to the old runlevel 3),
+
* {{ic|1=systemd.unit=rescue.target}} (which roughly corresponds to the old runlevel 1).
+
 
+
Alternatively, you may leave the bootloader alone and change {{ic|default.target}}. This can be done using {{ic|systemctl}}:
+
 
+
# systemctl enable multi-user.target
+
 
+
The effect of this command is outputted by {{ic|systemctl}}; a symlink to the new default target is made at {{ic|/etc/systemd/system/default.target}}. This works if, and only if:
+
  
 +
The dependencies in {{ic|/usr/lib/systemd/system/libvirtd.service}} are defined as
 
  [Install]
 
  [Install]
  Alias=default.target
+
  WantedBy=multi-user.target
 
+
  Also=virtlockd.socket
is in the target's configuration file. Currently, {{ic|multi-user.target}} and {{ic|graphical.target}} both have it.
+
  Also=virtlogd.socket
 
+
This only defines the necessary/dependent sockets to be enabled services(i.e. as "autostart"), too - but does not start them whenever the DISABLED (= non-autostarting) service ist started manually e.g. by running {{ic|systemctl start libvirtd}}
== Journal ==
+
 
+
Since version 38, systemd has its own logging system, the journal. Therefore, running a syslog daemon is no longer required. To read the log, use:
+
 
+
  # journalctl
+
 
+
By default (when {{ic|Storage&#61;}} is set to {{ic|auto}} in {{ic|/etc/systemd/journald.conf}}), the journal writes to {{ic|/var/log/journal/}}. The directory {{ic|/var/log/journal/}} is part of core/systemd. If you or some program delete it, systemd will '''not''' recreate it automatically, however it will be recreated during the next update of systemd. Till then, logs will be written to {{ic|/run/systemd/journal}}. This means that logs will be lost on reboot.
+
 
+
=== Filtering output ===
+
 
+
{{ic|journalctl}} allows you to filter the output by specific fields.
+
 
+
Examples:
+
 
+
Show all messages from this boot:
+
   
+
# journalctl -b
+
 
+
However, often one is interested in messages not from the current, but from the previous boot (e.g. if an unrecoverable system crash happened). Currently, this feature is not implemented, though there was a discussion at [http://comments.gmane.org/gmane.comp.sysutils.systemd.devel/6608 systemd-devel@lists.freedesktop.org] (September/October 2012).
+
 
+
As a workaround you can use at the moment:
+
 
+
# journalctl --since=today | tac | sed -n '/-- Reboot --/{n;:r;/-- Reboot --/q;p;n;b r}' | tac
+
 
+
provided, that the previous boot happened today. Be aware that, if there are many messages for the current day, the output of this command can be delayed for quite some time.
+
 
+
Follow new messages:
+
 
+
# journalctl -f
+
 
+
Show all messages by a specific executable:
+
 
+
# journalctl /usr/lib/systemd/systemd
+
 
+
Show all messages by a specific process:
+
 
+
# journalctl _PID=1
+
 
+
Show all messages by a specific unit:
+
 
+
# journalctl -u netcfg
+
 
+
See {{ic|man journalctl}}, {{ic|systemd.journal-fields}} or Lennert's [http://0pointer.de/blog/projects/journalctl.html blog post] for details.
+
 
+
=== Journal size limit ===
+
 
+
If the journal is persistent (non-volatile), its size limit is set to a default value of 10% of the size of the respective file system. For example, with {{ic|/var/log/journal}} located on a 50 GiB root partition this would lead to 5 GiB of journal data. The maximum size of the persistent journal can be controlled by {{ic|SystemMaxUse}} in {{ic|/etc/systemd/journald.conf}}, so to limit it for example to 50 MiB uncomment and edit the corresponding line to:
+
 
+
SystemMaxUse=50M
+
 
+
Refer to {{ic|man journald.conf}} for more info.
+
 
+
=== Journald in conjunction with syslog ===
+
 
+
Compatibility with classic syslog implementations is provided via a socket {{ic|/run/systemd/journal/syslog}}, to which all messages are forwarded. To make the syslog daemon work with the journal, it has to bind to this socket instead of {{ic|/dev/log}} ([http://lwn.net/Articles/474968/ official announcement]). The {{pkg|syslog-ng}} package in the repositories automatically provides the necessary configuration.
+
 
+
# systemctl enable syslog-ng
+
A good {{ic|journalctl}} tutorial is [http://0pointer.de/blog/projects/journalctl.html here].
+
 
+
== Optimization ==
+
 
+
{{merge|Improve Boot Performance|reason=Should be moved to the article covering this topic.}}
+
 
+
See [[Improve Boot Performance]].
+
 
+
=== Analyzing the boot process ===
+
 
+
==== Using systemd-analyze ====
+
 
+
Systemd provides a tool called {{ic|systemd-analyze}} that allows you to analyze your boot process so you can see which unit files are causing your boot process to slow down. You can then optimize your system accordingly.
+
 
+
To see how much time was spent in kernelspace and userspace on boot, simply use:
+
 
+
$ systemd-analyze
+
 
+
{{Tip|
+
* If you append the {{ic|timestamp}} hook to your {{ic|HOOKS}} array in {{ic|/etc/[[mkinitcpio]].conf}} and rebuild your initramfs with {{ic|mkinitcpio -p linux}}, systemd-analyze is also able to show you how much time was spent in the initramfs.
+
* If you boot via [[UEFI]] and use a boot loader which implements systemds' [http://www.freedesktop.org/wiki/Software/systemd/BootLoaderInterface Boot Loader Interface] (which currently only [[Gummiboot]] does), systemd-analyze can additionally show you how much time was spent in the EFI firmware and the boot loader itself.}}
+
 
+
To list the started unit files, sorted by the time each of them took to start up:
+
 
+
$ systemd-analyze blame
+
 
+
You can also create a SVG file which describes your boot process graphically, similiar to [[Bootchart]]:
+
 
+
$ systemd-analyze plot > plot.svg
+
 
+
==== Using systemd-bootchart ====
+
 
+
Bootchart has been merged into systemd since Oct. 17, and you can use it to boot just as you would with the original bootchart. Add this to your kernel line:
+
 
+
initcall_debug printk.time=y init=/usr/lib/systemd/systemd-bootchart
+
 
+
==== Using bootchart2 ====
+
 
+
You could also use a version of bootchart to visualize the boot sequence. Since you are not able to put a second init into the kernel command line you won't be able to use any of the standard bootchart setups. However the {{AUR|bootchart2}} package from [[AUR]] comes with an undocumented systemd service. After you've installed bootchart2 do:
+
 
+
# systemctl enable bootchart
+
 
+
Read the [https://github.com/mmeeks/bootchart bootchart documentation] for further details on using this version of bootchart.
+
 
+
=== Readahead ===
+
 
+
Systemd comes with its own readahead implementation, this should in principle improve boot time. However, depending on your kernel version and the type of your hard drive, your mileage may vary (i.e. it might be slower). To enable, do:
+
 
+
# systemctl enable systemd-readahead-collect systemd-readahead-replay
+
 
+
Remember that in order for the readahead to work its magic, you should reboot a couple of times.
+
 
+
== Troubleshooting ==
+
 
+
=== Shutdown/reboot takes terribly long ===
+
 
+
If the shutdown process takes a very long time (or seems to freeze) most likely a service not exiting is to blame. Systemd waits some time for each service to exit before trying to kill it. To find out if you are affected, see [http://freedesktop.org/wiki/Software/systemd/Debugging#Shutdown_Completes_Eventually this article].
+
 
+
=== Short lived processes don't seem to log any output ===
+
 
+
If {{ic|journalctl -u foounit.service}} doesn't show any output for a short lived service, look at the PID instead. For example, if systemd-modules-load.service fails, and {{ic|systemctl status systemd-modules-load}} shows that it ran as PID 123, then you might be able to see output in the journal for that PID, i.e. {{ic|journalctl -b _PID&#61;123}}. Metadata fields for the journal such as _SYSTEMD_UNIT and _COMM are collected asynchronously and rely on the {{ic|/proc}} directory for the process existing. Fixing this requires fixing the kernel to provide this data via a socket connection, similar to SCM_CREDENTIALS.
+
 
+
=== Diagnosing Boot Problems ===
+
 
+
Boot with these parameters on the kernel command line:
+
{{ic|<nowiki>systemd.log_level=debug systemd.log_target=kmsg log_buf_len=1M</nowiki>}}
+
  
[http://freedesktop.org/wiki/Software/systemd/Debugging More Debugging Information]
+
Thus the correct (?) way to manually start a service with dependent subservices once (instead of at each start of the system) probably is
 +
systemctl enable ServiceWithSubservices
 +
systemctl start ServiceWithSubservices
 +
systemctl disable ServiceWithSubservices
  
 
== See also ==
 
== See also ==
  
*[http://www.freedesktop.org/wiki/Software/systemd Official Web Site]
+
*[http://www.freedesktop.org/wiki/Software/systemd Official web site]
*[http://0pointer.de/public/systemd-man/ Manual Pages]
+
*[[Wikipedia:systemd|Wikipedia article]]
*[http://freedesktop.org/wiki/Software/systemd/Optimizations systemd Optimizations]
+
*[http://0pointer.de/public/systemd-man/ Manual pages]
 +
*[http://freedesktop.org/wiki/Software/systemd/Optimizations systemd optimizations]
 
*[http://www.freedesktop.org/wiki/Software/systemd/FrequentlyAskedQuestions FAQ]
 
*[http://www.freedesktop.org/wiki/Software/systemd/FrequentlyAskedQuestions FAQ]
*[http://www.freedesktop.org/wiki/Software/systemd/TipsAndTricks Tips And Tricks]
+
*[http://www.freedesktop.org/wiki/Software/systemd/TipsAndTricks Tips and tricks]
 
*[http://0pointer.de/public/systemd-ebook-psankar.pdf systemd for Administrators (PDF)]
 
*[http://0pointer.de/public/systemd-ebook-psankar.pdf systemd for Administrators (PDF)]
 
*[http://fedoraproject.org/wiki/Systemd About systemd on Fedora Project]
 
*[http://fedoraproject.org/wiki/Systemd About systemd on Fedora Project]
Line 742: Line 594:
 
*[http://www.h-online.com/open/features/Control-Centre-The-systemd-Linux-init-system-1565543.html Two] [http://www.h-online.com/open/features/Booting-up-Tools-and-tips-for-systemd-1570630.html part] introductory article in ''The H Open'' magazine.
 
*[http://www.h-online.com/open/features/Control-Centre-The-systemd-Linux-init-system-1565543.html Two] [http://www.h-online.com/open/features/Booting-up-Tools-and-tips-for-systemd-1570630.html part] introductory article in ''The H Open'' magazine.
 
*[http://0pointer.de/blog/projects/systemd.html Lennart's blog story]
 
*[http://0pointer.de/blog/projects/systemd.html Lennart's blog story]
*[http://0pointer.de/blog/projects/systemd-update.html status update]
+
*[http://0pointer.de/blog/projects/systemd-update.html Status update]
*[http://0pointer.de/blog/projects/systemd-update-2.html status update2]
+
*[http://0pointer.de/blog/projects/systemd-update-2.html Status update2]
*[http://0pointer.de/blog/projects/systemd-update-3.html status update3]
+
*[http://0pointer.de/blog/projects/systemd-update-3.html Status update3]
*[http://0pointer.de/blog/projects/why.html most recent summary]
+
*[http://0pointer.de/blog/projects/why.html Most recent summary]
 
*[http://fedoraproject.org/wiki/SysVinit_to_Systemd_Cheatsheet Fedora's SysVinit to systemd cheatsheet]
 
*[http://fedoraproject.org/wiki/SysVinit_to_Systemd_Cheatsheet Fedora's SysVinit to systemd cheatsheet]
 +
*[http://wiki.gentoo.org/wiki/Systemd Gentoo Wiki systemd page]
 +
*[[Emacs#Syntax highlighting for systemd Files|Emacs Syntax highlighting for Systemd files]]

Latest revision as of 23:59, 22 May 2016

From the project web page:

systemd is a system and service manager for Linux, compatible with SysV and LSB init scripts. systemd provides aggressive parallelization capabilities, uses socket and D-Bus activation for starting services, offers on-demand starting of daemons, keeps track of processes using Linux control groups, supports snapshotting and restoring of the system state, maintains mount and automount points and implements an elaborate transactional dependency-based service control logic.
Note: For a detailed explanation as to why Arch has moved to systemd, see this forum post.

Basic systemctl usage

The main command used to introspect and control systemd is systemctl. Some of its uses are examining the system state and managing the system and services. See man systemctl for more details.

Tip:
  • You can use all of the following systemctl commands with the -H user@host switch to control a systemd instance on a remote machine. This will use SSH to connect to the remote systemd instance.
  • systemadm is the official graphical frontend for systemctl and is provided by the systemd-ui package.
  • Plasma users can install systemd-kcm as a graphical fronted for systemctl. After installing the module will be added under System administration.

Analyzing the system state

Show system status using:

$ systemctl status

List running units:

$ systemctl

or:

$ systemctl list-units

List failed units:

$ systemctl --failed

The available unit files can be seen in /usr/lib/systemd/system/ and /etc/systemd/system/ (the latter takes precedence). List installed unit files with:

$ systemctl list-unit-files

Using units

Units can be, for example, services (.service), mount points (.mount), devices (.device) or sockets (.socket).

When using systemctl, you generally have to specify the complete name of the unit file, including its suffix, for example sshd.socket. There are however a few short forms when specifying the unit in the following systemctl commands:

  • If you do not specify the suffix, systemctl will assume .service. For example, netctl and netctl.service are equivalent.
  • Mount points will automatically be translated into the appropriate .mount unit. For example, specifying /home is equivalent to home.mount.
  • Similar to mount points, devices are automatically translated into the appropriate .device unit, therefore specifying /dev/sda2 is equivalent to dev-sda2.device.

See man systemd.unit for details.

Note: Some unit names contain an @ sign (e.g. name@string.service): this means that they are instances of a template unit, whose actual file name does not contain the string part (e.g. name@.service). string is called the instance identifier, and is similar to an argument that is passed to the template unit when called with the systemctl command: in the unit file it will substitute the %i specifier.

To be more accurate, before trying to instantiate the name@.suffix template unit, systemd will actually look for a unit with the exact name@string.suffix file name, although by convention such a "clash" happens rarely, i.e. most unit files containing an @ sign are meant to be templates. Also, if a template unit is called without an instance identifier, it will just fail, since the %i specifier cannot be substituted.

Tip:
  • Most of the following commands also work if multiple units are specified, see man systemctl for more information.
  • The --now switch can be used in conjunction with enable, disable, and mask to respectively start, stop, or mask immediately the unit rather than after the next boot.
  • A package may offer units for different purposes. If you just installed a package, pacman -Qql package | grep -Fe .service -e .socket can be used to check and find them.

Start a unit immediately:

# systemctl start unit

Stop a unit immediately:

# systemctl stop unit

Restart a unit:

# systemctl restart unit

Ask a unit to reload its configuration:

# systemctl reload unit

Show the status of a unit, including whether it is running or not:

$ systemctl status unit

Check whether a unit is already enabled or not:

$ systemctl is-enabled unit

Enable a unit to be started on bootup:

# systemctl enable unit

Disable a unit to not start during bootup:

# systemctl disable unit

Mask a unit to make it impossible to start it:

# systemctl mask unit

Unmask a unit:

# systemctl unmask unit

Show the manual page associated with a unit (this has to be supported by the unit file):

$ systemctl help unit

Reload systemd, scanning for new or changed units:

# systemctl daemon-reload

Power management

polkit is necessary for power management as an unprivileged user. If you are in a local systemd-logind user session and no other session is active, the following commands will work without root privileges. If not (for example, because another user is logged into a tty), systemd will automatically ask you for the root password.

Shut down and reboot the system:

$ systemctl reboot

Shut down and power-off the system:

$ systemctl poweroff

Suspend the system:

$ systemctl suspend

Put the system into hibernation:

$ systemctl hibernate

Put the system into hybrid-sleep state (or suspend-to-both):

$ systemctl hybrid-sleep

Writing unit files

The syntax of systemd's unit files is inspired by XDG Desktop Entry Specification .desktop files, which are in turn inspired by Microsoft Windows .ini files. Unit files are loaded from two locations. From lowest to highest precedence they are:

  • /usr/lib/systemd/system/: units provided by installed packages
  • /etc/systemd/system/: units installed by the system administrator
Note:
  • The load paths are completely different when running systemd in user mode.
  • systemd unit names may only contain ASCII alphanumeric characters, underscores and periods. All other characters must be replaced by C-style "\x2d" escapes. See man systemd.unit and man systemd-escape for more information.

Look at the units installed by your packages for examples, as well as the annotated example section of man systemd.service.

Tip: Comments prepended with # may be used in unit-files as well, but only in new lines. Do not use end-line comments after systemd parameters or the unit will fail to activate.

Handling dependencies

With systemd, dependencies can be resolved by designing the unit files correctly. The most typical case is that the unit A requires the unit B to be running before A is started. In that case add Requires=B and After=B to the [Unit] section of A. If the dependency is optional, add Wants=B and After=B instead. Note that Wants= and Requires= do not imply After=, meaning that if After= is not specified, the two units will be started in parallel.

Dependencies are typically placed on services and not on targets. For example, network.target is pulled in by whatever service configures your network interfaces, therefore ordering your custom unit after it is sufficient since network.target is started anyway.

Service types

There are several different start-up types to consider when writing a custom service file. This is set with the Type= parameter in the [Service] section:

  • Type=simple (default): systemd considers the service to be started up immediately. The process must not fork. Do not use this type if other services need to be ordered on this service, unless it is socket activated.
  • Type=forking: systemd considers the service started up once the process forks and the parent has exited. For classic daemons use this type unless you know that it is not necessary. You should specify PIDFile= as well so systemd can keep track of the main process.
  • Type=oneshot: this is useful for scripts that do a single job and then exit. You may want to set RemainAfterExit=yes as well so that systemd still considers the service as active after the process has exited.
  • Type=notify: identical to Type=simple, but with the stipulation that the daemon will send a signal to systemd when it is ready. The reference implementation for this notification is provided by libsystemd-daemon.so.
  • Type=dbus: the service is considered ready when the specified BusName appears on DBus's system bus.
  • Type=idle: systemd will delay execution of the service binary until all jobs are dispatched. Other than that behavior is very similar to Type=simple.

See the systemd.service(5) man page for a more detailed explanation of the Type values.

Editing provided units

To avoid conflicts with pacman, unit files provided by packages should not be directly edited. There are two safe ways to modify a unit without touching the original file: create a new unit file which overwrites the original unit or create drop-in snippets which are applied on top of the original unit. For both methods, you must reload the unit afterwards to apply your changes. This can be done either by editing the unit with systemctl edit (which reloads the unit automatically) or by reloading all units with:

# systemctl daemon-reload
Tip:
  • You can use systemd-delta to see which unit files have been overridden or extended and what exactly has been changed.
  • Use systemctl cat unit to view the content of a unit file and all associated drop-in snippets.
  • Syntax highlighting for systemd unit files within Vim can be enabled by installing vim-systemd.

Replacement unit files

To replace the unit file /usr/lib/systemd/system/unit, create the file /etc/systemd/system/unit and reenable the unit to update the symlinks:

# systemctl reenable unit

Alternatively, run:

# systemctl edit --full unit

This opens /etc/systemd/system/unit in your editor (copying the installed version if it does not exist yet) and automatically reloads it when you finish editing.

Note: Pacman does not update the replacement unit files when the originals are updated, so this method can make system maintenance more difficult. For this reason the next approach is recommended.

Drop-in snippets

To create drop-in snippets for the unit file /usr/lib/systemd/system/unit, create the directory /etc/systemd/system/unit.d/ and place .conf files there to override or add new options. systemd will parse these .conf files and apply them on top of the original unit.

The easiest way to do this is to run:

# systemctl edit unit

This opens the file /etc/systemd/system/unit.d/override.conf in your text editor (creating it if necessary) and automatically reloads the unit when you are done editing.

Examples

For example, if you simply want to add an additional dependency to a unit, you may create the following file:

/etc/systemd/system/unit.d/customdependency.conf
[Unit]
Requires=new dependency
After=new dependency

As another example, in order to replace the ExecStart directive for a unit that is not of type oneshot, create the following file:

/etc/systemd/system/unit.d/customexec.conf
[Service]
ExecStart=
ExecStart=new command

Note how ExecStart must be cleared before being re-assigned ([1]).

One more example to automatically restart a service:

/etc/systemd/system/unit.d/restart.conf
[Service]
Restart=always
RestartSec=30

Targets

Tango-edit-clear.pngThis article or section needs language, wiki syntax or style improvements.Tango-edit-clear.png

Reason: Unclear description, copy-pasted content (explicitly mentions "Fedora"). (Discuss in Talk:Systemd#Make section "Targets" more clearly)

systemd uses targets which serve a similar purpose as runlevels but act a little different. Each target is named instead of numbered and is intended to serve a specific purpose with the possibility of having multiple ones active at the same time. Some targets are implemented by inheriting all of the services of another target and adding additional services to it. There are systemd targets that mimic the common SystemVinit runlevels so you can still switch targets using the familiar telinit RUNLEVEL command.

Get current targets

The following should be used under systemd instead of running runlevel:

$ systemctl list-units --type=target

Create custom target

The runlevels that held a defined meaning under sysvinit (i.e., 0, 1, 3, 5, and 6); have a 1:1 mapping with a specific systemd target. Unfortunately, there is no good way to do the same for the user-defined runlevels like 2 and 4. If you make use of those it is suggested that you make a new named systemd target as /etc/systemd/system/your target that takes one of the existing runlevels as a base (you can look at /usr/lib/systemd/system/graphical.target as an example), make a directory /etc/systemd/system/your target.wants, and then symlink the additional services from /usr/lib/systemd/system/ that you wish to enable.

Targets table

SysV Runlevel systemd Target Notes
0 runlevel0.target, poweroff.target Halt the system.
1, s, single runlevel1.target, rescue.target Single user mode.
2, 4 runlevel2.target, runlevel4.target, multi-user.target User-defined/Site-specific runlevels. By default, identical to 3.
3 runlevel3.target, multi-user.target Multi-user, non-graphical. Users can usually login via multiple consoles or via the network.
5 runlevel5.target, graphical.target Multi-user, graphical. Usually has all the services of runlevel 3 plus a graphical login.
6 runlevel6.target, reboot.target Reboot
emergency emergency.target Emergency shell

Change current target

In systemd targets are exposed via target units. You can change them like this:

# systemctl isolate graphical.target

This will only change the current target, and has no effect on the next boot. This is equivalent to commands such as telinit 3 or telinit 5 in Sysvinit.

Change default target to boot into

The standard target is default.target, which is aliased by default to graphical.target (which roughly corresponds to the old runlevel 5). To change the default target at boot-time, append one of the following kernel parameters to your bootloader:

  • systemd.unit=multi-user.target (which roughly corresponds to the old runlevel 3),
  • systemd.unit=rescue.target (which roughly corresponds to the old runlevel 1).

Alternatively, you may leave the bootloader alone and change default.target. This can be done using systemctl:

# systemctl set-default multi-user.target

To be able to override the previously set default.target, use the force option:

# systemctl set-default -f multi-user.target

The effect of this command is output by systemctl; a symlink to the new default target is made at /etc/systemd/system/default.target.

Temporary files

"systemd-tmpfiles creates, deletes and cleans up volatile and temporary files and directories." It reads configuration files in /etc/tmpfiles.d/ and /usr/lib/tmpfiles.d/ to discover which actions to perform. Configuration files in the former directory take precedence over those in the latter directory.

Configuration files are usually provided together with service files, and they are named in the style of /usr/lib/tmpfiles.d/program.conf. For example, the Samba daemon expects the directory /run/samba to exist and to have the correct permissions. Therefore, the samba package ships with this configuration:

/usr/lib/tmpfiles.d/samba.conf
D /run/samba 0755 root root

Configuration files may also be used to write values into certain files on boot. For example, if you used /etc/rc.local to disable wakeup from USB devices with echo USBE > /proc/acpi/wakeup, you may use the following tmpfile instead:

/etc/tmpfiles.d/disable-usb-wake.conf
w /proc/acpi/wakeup - - - - USBE

See the systemd-tmpfiles(8) and tmpfiles.d(5) man pages for details.

Note: This method may not work to set options in /sys since the systemd-tmpfiles-setup service may run before the appropriate device modules is loaded. In this case you could check whether the module has a parameter for the option you want to set with modinfo module and set this option with a config file in /etc/modprobe.d. Otherwise you will have to write a udev rule to set the appropriate attribute as soon as the device appears.

Timers

A timer is a unit configuration file whose name ends with .timer and encodes information about a timer controlled and supervised by systemd, for timer-based activation. See systemd/Timers.

Note: Timers can replace cron functionality to a great extent. See systemd/Timers#As a cron replacement.

Mounting

Since systemd is a replacement for System V init, it is in charge of the mounts specified in /etc/fstab. In fact, it goes beyond the usual fstab capabilities, implementing special mount options prefixed with x-systemd.. See Fstab#Automount_with_systemd for an example of automounting (mounting on-demand) using these extensions. See [2] for the complete documentation of these extensions.

Journal

systemd has its own logging system called the journal; therefore, running a syslog daemon is no longer required. To read the log, use:

# journalctl

In Arch Linux, the directory /var/log/journal/ is a part of the systemd package, and the journal (when Storage= is set to auto in /etc/systemd/journald.conf) will write to /var/log/journal/. If you or some program delete that directory, systemd will not recreate it automatically and instead will write its logs to /run/systemd/journal in a nonpersistent way. However, the folder will be recreated when you set Storage=persistent and run systemctl restart systemd-journald (or reboot).

Filtering output

journalctl allows you to filter the output by specific fields. Be aware that if there are many messages to display or filtering of large time span has to be done, the output of this command can be delayed for quite some time.

Tip: While the journal is stored in a binary format, the content of stored messages is not modified. This means it is viewable with strings, for example for recovery in an environment which does not have systemd installed. Example command:
$ strings /mnt/arch/var/log/journal/af4967d77fba44c6b093d0e9862f6ddd/system.journal | grep -i message

Examples:

  • Show all messages from this boot:
    # journalctl -b
    However, often one is interested in messages not from the current, but from the previous boot (e.g. if an unrecoverable system crash happened). This is possible through optional offset parameter of the -b flag: journalctl -b -0 shows messages from the current boot, journalctl -b -1 from the previous boot, journalctl -b -2 from the second previous and so on. See man 1 journalctl for full description, the semantics is much more powerful.
  • Show all messages from date (and optional time):
    # journalctl --since="2012-10-30 18:17:16"
  • Show all messages since 20 minutes ago:
    # journalctl --since "20 min ago"
  • Follow new messages:
    # journalctl -f
  • Show all messages by a specific executable:
    # journalctl /usr/lib/systemd/systemd
  • Show all messages by a specific process:
    # journalctl _PID=1
  • Show all messages by a specific unit:
    # journalctl -u netcfg
  • Show kernel ring buffer:
    # journalctl -k
  • Show auth.log equivalent by filtering on syslog facility:
    # journalctl -f -l SYSLOG_FACILITY=10

See man 1 journalctl, man 7 systemd.journal-fields, or Lennart's blog post for details.

Tip: By default, journalctl truncates lines longer than screen width, but in some cases, it may be better to enable wrapping instead of truncating. This can be controlled by the SYSTEMD_LESS environment variable, which contains options passed to less (the default pager) and defaults to FRSXMK (see man 1 less and man 1 journalctl for details).

By omitting the S option, the output will be wrapped instead of truncated. For example, start journalctl as follows:

$ SYSTEMD_LESS=FRXMK journalctl
If you would like to set this behaviour as default, export the variable from ~/.bashrc or ~/.zshrc.

Journal size limit

If the journal is persistent (non-volatile), its size limit is set to a default value of 10% of the size of the respective file system. For example, with /var/log/journal located on a 50 GiB root partition this would lead to 5 GiB of journal data. The maximum size of the persistent journal can be controlled by uncommenting and changing the following:

/etc/systemd/journald.conf
SystemMaxUse=50M

Refer to man journald.conf for more info.

Clean journal files manually

The journal files are located under /var/log/journal, rm will do the work. Or, use journalctl,

Examples:

  • Remove archived journal files until the disk space they use falls below 100M:
    # journalctl --vacuum-size=100M
  • Make all journal files contain no data older than 2 weeks.
    # journalctl --vacuum-time=2weeks

Refer to man journalctl for more info.

Journald in conjunction with syslog

Compatibility with a classic, non-journald aware syslog implementation can be provided by letting systemd forward all messages via the socket /run/systemd/journal/syslog. To make the syslog daemon work with the journal, it has to bind to this socket instead of /dev/log (official announcement).

The default journald.conf for forwarding to the socket is ForwardToSyslog=no to avoid system overhead, because rsyslog or syslog-ng pull the messages from the journal by itself.

See Syslog-ng#Overview and Syslog-ng#syslog-ng and systemd journal, or rsyslog respectively, for details on configuration.

Forward journald to /dev/tty12

Create a drop-in directory /etc/systemd/journald.conf.d and create a fw-tty12.conf file in it:

/etc/systemd/journald.conf.d/fw-tty12.conf
[Journal]
ForwardToConsole=yes
TTYPath=/dev/tty12
MaxLevelConsole=info

Then restart systemd-journald.

Specify a different journal to view

There may be a need to check the logs of another system that is dead in the water, like booting from a live system to recover a production system. In such case, one can mount the disk in e.g. /mnt, and specify the journal path via -D/--directory, like so:

$ journalctl -D /mnt/var/log/journal -xe

Troubleshooting

Investigating systemd errors

As an example, we will investigate an error with systemd-modules-load service:

1. Lets find the systemd services which fail to start:

$ systemctl --failed
systemd-modules-load.service   loaded failed failed  Load Kernel Modules

2. Ok, we found a problem with systemd-modules-load service. We want to know more:

$ systemctl status systemd-modules-load
systemd-modules-load.service - Load Kernel Modules
   Loaded: loaded (/usr/lib/systemd/system/systemd-modules-load.service; static)
   Active: failed (Result: exit-code) since So 2013-08-25 11:48:13 CEST; 32s ago
     Docs: man:systemd-modules-load.service(8).
           man:modules-load.d(5)
  Process: 15630 ExecStart=/usr/lib/systemd/systemd-modules-load (code=exited, status=1/FAILURE)

If the Process ID is not listed, just restart the failed service with systemctl restart systemd-modules-load

3. Now we have the process id (PID) to investigate this error in depth. Enter the following command with the current Process ID (here: 15630):

$ journalctl _PID=15630
-- Logs begin at Sa 2013-05-25 10:31:12 CEST, end at So 2013-08-25 11:51:17 CEST. --
Aug 25 11:48:13 mypc systemd-modules-load[15630]: Failed to find module 'blacklist usblp'
Aug 25 11:48:13 mypc systemd-modules-load[15630]: Failed to find module 'install usblp /bin/false'

4. We see that some of the kernel module configs have wrong settings. Therefore we have a look at these settings in /etc/modules-load.d/:

$ ls -Al /etc/modules-load.d/
...
-rw-r--r--   1 root root    79  1. Dez 2012  blacklist.conf
-rw-r--r--   1 root root     1  2. Mär 14:30 encrypt.conf
-rw-r--r--   1 root root     3  5. Dez 2012  printing.conf
-rw-r--r--   1 root root     6 14. Jul 11:01 realtek.conf
-rw-r--r--   1 root root    65  2. Jun 23:01 virtualbox.conf
...

5. The Failed to find module 'blacklist usblp' error message might be related to a wrong setting inside of blacklist.conf. Lets deactivate it with inserting a trailing # before each option we found via step 3:

/etc/modules-load.d/blacklist.conf
# blacklist usblp
# install usblp /bin/false

6. Now, try to start systemd-modules-load:

$ systemctl start systemd-modules-load

If it was successful, this should not prompt anything. If you see any error, go back to step 3 and use the new PID for solving the errors left.

If everything is ok, you can verify that the service was started successfully with:

$ systemctl status systemd-modules-load
systemd-modules-load.service - Load Kernel Modules
   Loaded: loaded (/usr/lib/systemd/system/systemd-modules-load.service; static)
   Active: active (exited) since So 2013-08-25 12:22:31 CEST; 34s ago
     Docs: man:systemd-modules-load.service(8)
           man:modules-load.d(5)
 Process: 19005 ExecStart=/usr/lib/systemd/systemd-modules-load (code=exited, status=0/SUCCESS)
Aug 25 12:22:31 mypc systemd[1]: Started Load Kernel Modules.

Often you can solve these kind of problems like shown above. For further investigation look at #Diagnosing boot problems.

Diagnosing boot problems

systemd has several options for diagnosing problems with the boot process. See boot debugging and the systemd debugging documentation.

Diagnosing problems with a specific service

Tango-inaccurate.pngThe factual accuracy of this article or section is disputed.Tango-inaccurate.png

Reason: This may not catch all errors such as missing libraries. (Discuss in User talk:Alucryd#Plex)

If some systemd service misbehaves and you want to get more information about what is going on, set the SYSTEMD_LOG_LEVEL environment variable to debug. For example, to run the systemd-networkd daemon in debug mode:

# systemctl stop systemd-networkd
# SYSTEMD_LOG_LEVEL=debug /lib/systemd/systemd-networkd

Or, equivalently, modify the service file temporarily for gathering enough output. For example:

/usr/lib/systemd/system/systemd-networkd.service
[Service]
...
Environment=SYSTEMD_LOG_LEVEL=debug
....

If debug information is required long-term, add the variable the regular way.

Shutdown/reboot takes terribly long

If the shutdown process takes a very long time (or seems to freeze) most likely a service not exiting is to blame. systemd waits some time for each service to exit before trying to kill it. To find out if you are affected, see this article.

Short lived processes do not seem to log any output

If journalctl -u foounit does not show any output for a short lived service, look at the PID instead. For example, if systemd-modules-load.service fails, and systemctl status systemd-modules-load shows that it ran as PID 123, then you might be able to see output in the journal for that PID, i.e. journalctl -b _PID=123. Metadata fields for the journal such as _SYSTEMD_UNIT and _COMM are collected asynchronously and rely on the /proc directory for the process existing. Fixing this requires fixing the kernel to provide this data via a socket connection, similar to SCM_CREDENTIALS.

Disabling application crash dumps journaling

Edit the file /etc/systemd/coredump.conf by adding this line:

 Storage=none

and run:

# systemctl daemon-reload

to reload the configuration.

Boot time increasing over time

After using systemd-analyze a number of users have noticed that their boot time has increased significantly in comparison with what it used to be. After using systemd-analyze blame NetworkManager is being reported as taking an unusually large amount of time to start.

The problem for some users has been due to /var/log/journal becoming too large. This may have other impacts on performance, such as for systemctl status or journalctl. As such the solution is to remove every file within the folder (ideally making a backup of it somewhere, at least temporarily) and then setting a journal file size limit as described in #Journal size limit.

systemd-tmpfiles-setup.service fails to start at boot

Starting with systemd 219, /usr/lib/tmpfiles.d/systemd.conf specifies ACL attributes for directories under /var/log/journal and, therefore, requires ACL support to be enabled for the filesystem the journal resides on.

See Access Control Lists#Enabling ACL for instructions on how to enable ACL on the filesystem that houses /var/log/journal.

systemctl enable fails for symlinks in /etc/systemd/system

If /etc/systemd/system/foo.service is a symlink and systemctl enable foo.service is run, it will fail with this error:

Failed to issue method call: No such file or directory

This is a design choice of systemd. As a workaround, enabling by absolute path works:

# systemctl enable /absolute/path/foo.service

dependent services are not started when starting a service manually

Tango-edit-cut.pngThis section is being considered for removal.Tango-edit-cut.png

Reason: Guesswork instead of actual research, and bug reports belong to the bug tracker, not to the wiki. (Discuss in Talk:Systemd#Subsection .22dependent services are not started when starting a service manually.22)

One (in)famomus example is libvirtd.service which needs the virtlogd.socket to function properly.

The dependencies in /usr/lib/systemd/system/libvirtd.service are defined as

[Install]
WantedBy=multi-user.target
Also=virtlockd.socket
Also=virtlogd.socket

This only defines the necessary/dependent sockets to be enabled services(i.e. as "autostart"), too - but does not start them whenever the DISABLED (= non-autostarting) service ist started manually e.g. by running systemctl start libvirtd

Thus the correct (?) way to manually start a service with dependent subservices once (instead of at each start of the system) probably is

systemctl enable ServiceWithSubservices
systemctl start ServiceWithSubservices
systemctl disable ServiceWithSubservices

See also