Difference between revisions of "Systemd"

From ArchWiki
Jump to: navigation, search
(Supplementary information: Moved explanation of systemd-sysvcompat from install instructions to the Note.)
m (Editing provided units: As can be seen within a few paragraphs, it doesn't overwrites in the simplest meaning. It overrides by taking precedence)
 
(931 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]]
 +
[[pt:Systemd]]
 
[[ru:Systemd]]
 
[[ru:Systemd]]
 
[[zh-CN:Systemd]]
 
[[zh-CN:Systemd]]
{{Article summary start}}
+
[[zh-TW:Systemd]]
{{Article summary text|Covers how to install and configure systemd.}}
+
{{Related articles start}}
{{Article summary heading|Related}}
+
{{Related|systemd/User}}
{{Article summary wiki|Systemd/Services}}
+
{{Related|systemd/Timers}}
{{Article summary end}}
+
{{Related|systemd FAQ}}
'''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]], 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.
+
{{Related|init}}
 +
{{Related|init Rosetta}}
 +
{{Related|Daemons#List of daemons}}
 +
{{Related|udev}}
 +
{{Related|Improve boot performance}}
 +
{{Related|Allow users to shutdown}}
 +
{{Related articles end}}
  
{{Note|For a detailed explanation as to why Arch is switching to systemd, see: [https://bbs.archlinux.org/viewtopic.php?pid=1149530#p1149530 this forum post].}}
+
From the [http://freedesktop.org/wiki/Software/systemd project web page]:
  
See also the [http://en.wikipedia.org/wiki/Systemd Wikipedia article] and 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 [[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.
  
== Things to consider before you switch ==
+
{{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].}}
  
* It is highly recommended to switch to the new '''initscripts''' configuration system described in the [[rc.conf|rc.conf article]]. Once you have this configuration established, you will have done most of the work needed to make the switch to systemd.
+
== Basic systemctl usage ==
* Do [http://freedesktop.org/wiki/Software/systemd/ some reading] about systemd.
+
* Note the fact that systemd has a '''journal''' system that replaces '''syslog''', although the two can co-exist.  See the [[#Journald_in_conjunction_with_a_classic_syslog_daemon|section on the journal]] below.
+
* Do not worry about systemd's plans to replace the functionality of '''cron''', '''acpid''', or '''xinetd'''.  These are not things you need to worry about just yet.  For now, you can continue to use your traditional daemons for these tasks.
+
  
== Installation ==
+
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.
Systemd can be installed side-by-side with the regular Arch Linux initscripts, and they can be toggled by adding/removing the {{Ic|1=init=/bin/systemd}} [[kernel parameters]].
+
  
=== A pure systemd installation ===
+
{{Tip|
 +
* 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.
 +
* ''systemadm'' is the official graphical frontend for ''systemctl'' and is provided by the {{Pkg|systemd-ui}} package.
 +
* [[Plasma]] users can install {{Pkg|systemd-kcm}} as a graphical fronted for ''systemctl''. After installing the module will be added under ''System administration''.}}
  
# Install {{Pkg|systemd}} from [core].
+
=== Analyzing the system state ===
# The {{Pkg|systemd-arch-units}} package has some extra systemd unit files (services) which you may find useful.
+
# Add {{ic|1=init=/bin/systemd}} to the [[Kernel parameters|kernel parameters]] in your bootloader.
+
# Create [[#Native systemd configuration files|systemd configuration files]].
+
# Reboot and install {{Pkg|systemd-sysvcompat}}.  Now you can remove the kernel parameters from step 3 if you like.
+
# [[#Using_Units|Enable services]] with {{ic|systemctl enable ...}}.  Services replace the daemons from rc.conf.
+
# If you miss {{ic|pidof}} or {{ic|sulogin}}, install [https://aur.archlinux.org/packages.php?ID=60061 systemd-sysvinit] from AUR.
+
  
=== A mixed systemd installation ===
+
Show '''system status''' using:
  
# Install {{Pkg|systemd}} from [core]
+
$ systemctl status
# Add {{ic|1=init=/bin/systemd}} to the [[Kernel parameters|kernel parameters]] in your bootloader.
+
# We recommend that you use [[#Native systemd configuration files|native systemd configuration files]] instead of Arch's classic configuration files. You can still use {{ic|/etc/rc.conf}} to configure a few variables if the native configuration files do not exist, but support will be dropped in the future.
+
# The {{Pkg|systemd-arch-units}} package has some extra systemd unit files (services) which you may find useful, notably for network configuration.
+
# If you want to keep using syslog log files alongside the systemd journal, follow the instructions described in the [[#Journald_in_conjunction_with_a_classic_syslog_daemon|section on the journal]], below.
+
  
=== Supplementary information ===
+
'''List running''' units:
{{Note|In a pure systemd installation, installing {{pkg|systemd-sysvcompat}} removes {{pkg|initscripts}} and {{pkg|sysvinit}}, and permits the export of LANG in /etc/locale.conf and create symlinks to halt, reboot, etc.}}
+
{{Tip|Purely filesystem-based commands (like {{ic|list-unit-files}}, {{ic|enable}}, {{ic|mask}}, etc) should work immediately after installation. However, multiple people have reported needing to reboot with systemd before even these commands begin working.}}
+
{{Tip|If you have {{ic|quiet}} in your kernel parameters, you should remove it for your first couple of systemd boots, to assist with identifying any issues during boot.}}
+
{{Warning|{{ic|/usr}} must be mounted and available at bootup (this is not particular to systemd). If your {{ic|/usr}} is on a separate partition, you will need to make accommodations to mount it from the initramfs and unmount it from a pivoted root on shutdown. See [[Mkinitcpio#/usr_as_a_separate_partition|the mkinitcpio wiki page]] and [http://www.freedesktop.org/wiki/Software/systemd/separate-usr-is-broken freedesktop.org#separate-usr-is-broken]}}
+
  
== Native systemd configuration files ==
+
$ systemctl
{{Pkg|systemd}} will use {{ic|/etc/rc.conf}} if these files are absent (Note this is temporary and not a long-term solution. It is strongly advised to use the systemd configuration files on any system, since initscripts can use them).
+
{{Note|You may need to create these files.}}
+
=== Hostname ===
+
{{hc|/etc/hostname|myhostname}}
+
  
=== Console and keymap ===
+
or:
The {{ic|/etc/vconsole.conf}} file configures the virtual console, i.e. keyboard mapping and console font.
+
{{hc|/etc/vconsole.conf|<nowiki>
+
KEYMAP=us
+
FONT=lat9w-16
+
FONT_MAP=8859-1_to_uni</nowiki>}}
+
  
For more info see: [[Fonts#Console_fonts|Console fonts]]
+
$ systemctl list-units
  
=== Locale ===
+
'''List failed''' units:
Read {{ic|man locale.conf}} for more options
+
{{hc|/etc/locale.conf|<nowiki>
+
LANG=en_US.UTF-8
+
LC_COLLATE=C</nowiki>}}
+
{{Note| {{Ic|1=/etc/profile.d/locale.sh}} from {{Pkg|systemd-sysvcompat}} or {{Pkg|initscripts}} is necessary to be able to set users' locale correctly}}
+
  
=== Timezone ===
+
$ systemctl --failed
Read {{ic|man 5 timezone}} for more options
+
{{hc|/etc/timezone|Europe/Minsk}}
+
{{Note|This file does not obviate the need for {{ic|/etc/localtime}}.}}
+
  
=== Hardware clock time ===
+
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:
Systemd will use UTC for the hardware clock by default and this is recommended. 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 without using {{ic|hwclock}}, the kernel will always assume that the RTC is in UTC. This means that if the RTC is in local time, the the system time will first be set up wrongly and then corrected shortly afterwards on every boot. This is possibly the reason for certain weird bugs (time going backwards is rarely a good thing).
+
  
The 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 who uses localtime]). Windows is able to deal with the RTC being in UTC by setting the following DWORD registry key to {{ic|1}}:
+
$ systemctl list-unit-files
{{bc|HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\RealTimeIsUniversal}}
+
  
{{Warning|On recent systems (Windows 7, Vista SP2) this setting prevents Windows from being able to update the system clock at all, and earlier versions do not work correctly when [http://social.msdn.microsoft.com/forums/en-US/tabletandtouch/thread/0b872d8a-69e9-40a6-a71f-45de90c6e243/ resuming from suspend or hibernate]. In addition, recent systems [http://support.microsoft.com/kb/2687252 may become unresponsive during Daylight Saving Time (DST) changeover] if RealTimeIsUniversal is set.}}
+
=== Using units ===
  
If you run into issues on dual boot with Windows, you can set the hardware clock to local time. Contrary to popular belief, systemd supports this:
+
Units can be, for example, services (''.service''), mount points (''.mount''), devices (''.device'') or sockets (''.socket'').
{{hc|/etc/adjtime|<nowiki>
+
0.0 0.0 0.0
+
0
+
LOCAL</nowiki>}}
+
{{Note|The other parameters are still needed but are ignored by systemd.}}
+
{{Note|It is generally advised to have a [[NTP|Network Time Protocol daemon]] running to keep the hardware clock synchronized with the system time.}}
+
  
=== Kernel modules loaded during boot ===
+
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:
systemd uses {{ic|/etc/modules-load.d/}} to configure kernel modules to load during boot in a static list. Each configuration file is named in the style of {{ic|/etc/modules-load.d/<program>.conf}}. The configuration files should 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. Example:
+
{{hc|/etc/modules-load.d/virtio-net.conf|<nowiki>
+
# Load virtio-net.ko at boot
+
virtio-net</nowiki>}}
+
See also [[Modprobe#Options]]
+
  
=== Kernel modules blacklist ===
+
* If you do not specify the suffix, systemctl will assume ''.service''. For example, {{ic|netctl}} and {{ic|netctl.service}} are equivalent.
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.
+
* 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}}.
  
=== Temporary files ===
+
See {{ic|man systemd.unit}} for details.
Systemd-tmpfiles uses the 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.
+
  
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|/var/run/samba}} to exist and to have the correct permissions. The corresponding tmpfile looks like this:
+
{{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|/usr/lib/tmpfiles.d/samba.conf|
+
D /var/run/samba 0755 root root
+
}}
+
  
However, 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:
+
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.
{{hc|/etc/tmpfiles.d/disable-usb-wake.conf|
+
w /proc/acpi/wakeup - - - - USBE
+
 
}}
 
}}
The tmpfiles method is recommended in this case since systemd doesn't actually support {{ic|/etc/rc.local}}.
 
  
See {{ic|man tmpfiles.d}} for details.
+
{{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.}}
  
=== Remote filesystem mounts ===
+
'''Start''' a unit immediately:
systemd automatically makes sure that remote filesystem mounts like [[NFS]] or [[Samba]] are only started after the network has been set up. Therefore remote filesystem mounts specified in {{ic|/etc/fstab}} should work out of the box.
+
  
You may however want to use [[#Automount|Automount]] for remote filesystem mounts to mount them only upon access. Furthermore you can use the {{ic|1=x-systemd.device-timeout=#}} option in {{ic|/etc/fstab}} to specify a timeout in case the network resource is not available.
+
# systemctl start ''unit''
  
See {{ic|man systemd.mount}} for details.
+
'''Stop''' a unit immediately:
  
=== Replacing acpid with systemd ===
+
# systemctl stop ''unit''
Systemd can handle some power-related ACPI events. This is configured via the following options in {{ic|/etc/systemd/logind.conf}}:
+
* {{ic|HandlePowerKey}} : Power off the system when the power button is pressed
+
* {{ic|HandleSleepKey}} : Suspend the system when the sleep key is pressed
+
* {{ic|HandleLidSwitch}} : Suspend the system when the laptop lid is closed
+
Depending on the value of these options, these events may for example only be triggered when no user is logged in ({{ic|no-session}}) or when only a single user session is active ({{ic|any-session}}). See {{ic|man logind.conf}} for details.
+
  
These options should not be used on desktop environments like [[Gnome]] and [[XFCE]] since these handle ACPI events by themselves. However, 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.
+
'''Restart''' a unit:
  
=== Sleep hooks ===
+
# systemctl restart ''unit''
  
Systemd does not use [[pm-utils]] to put the machine to sleep when using {{ic|systemctl suspend}} or {{ic|systemctl hibernate}}, therefore [[pm-utils]] hooks including any [[Pm-utils#Creating_your_own_hooks|custom hooks]] created will not be run.  However, systemd provides a similar mechanism to run custom scripts on these events. Systemd runs all executables in {{ic|/usr/lib/systemd/system-sleep/}} and passes two arguments to each of them:
+
Ask a unit to '''reload''' its configuration:
  
* Argument 1: either {{ic|pre}} or {{ic|post}}, depending on whether the machine is going to sleep or waking up
+
# systemctl reload ''unit''
* Argument 2: either {{ic|suspend}} or {{ic|hibernate}}, depending on what has been invoked
+
  
In contrast to [[pm-utils]], systemd will run these scripts in parallel and not one after another.
+
Show the '''status''' of a unit, including whether it is running or not:
  
The output of your script will be logged by {{ic|systemd-suspend.service}} or {{ic|systemd-hibernate.service}} so you can see its output in the [[Systemd#Systemd Journal|journal]].
+
$ systemctl status ''unit''
  
Note that you can also use {{ic|sleep.target}}, {{ic|suspend.target}} or {{ic|hibernate.target}} to hook units into the sleep state logic instead of using scripts.
+
'''Check''' whether a unit is already enabled or not:
  
See {{ic|man systemd.special}} and {{ic|man systemd-sleep}} for more information.
+
$ systemctl is-enabled ''unit''
  
==== Example ====
+
'''Enable''' a unit to be started on '''bootup''':
{{hc|/usr/lib/systemd/system-sleep/example.sh|<nowiki>
+
case "$1" in
+
  pre )
+
    echo going to $2 ...
+
    ;;
+
  post )
+
    echo waking up from $2 ...
+
    ;;
+
esac</nowiki>}}
+
  
=== Unit ===
+
# systemctl enable ''unit''
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. See {{ic|man systemd.unit}} for more info.
+
  
== Systemd commands ==
+
'''Disable''' a unit to not start during bootup:
  
*{{ic|systemctl}}: used to introspect and control the state of the systemd system and service manager.
+
# systemctl disable ''unit''
*{{ic|systemd-cgls}}: recursively shows the contents of the selected Linux control group hierarchy in a tree
+
*{{ic|systemadm}}: a graphical frontend for the systemd system and service manager that allows introspection and control of systemd (avaiable via the {{AUR|systemd-ui-git}} package from the [[AUR]]).
+
  
View the man pages for more details.
+
'''Mask''' a unit to make it impossible to start it:
  
{{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.}}
+
# systemctl mask ''unit''
  
=== Analyzing the system state ===
+
'''Unmask''' a unit:
  
List running units:
+
# systemctl unmask ''unit''
  
{{bc|$ systemctl}}
+
Show the '''manual page''' associated with a unit (this has to be supported by the unit file):
  
or:
+
$ systemctl help ''unit''
  
{{bc|$ systemctl list-units}}
+
Reload ''systemd'', scanning for '''new or changed units''':
  
List failed units:
+
# systemctl daemon-reload
  
{{bc|$ systemctl --failed}}
+
=== Power management ===
  
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:
+
[[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.
{{bc|$ systemctl list-unit-files}}
+
  
=== Using Units ===
+
Shut down and reboot the system:
  
Units can be, for example, services ({{ic|.service}}), mount points ({{ic|.mount}}), devices ({{ic|.device}}) or sockets ({{ic|.socket}}).
+
$ systemctl reboot
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:
+
* If you don't specify the suffix, systemctl will assume {{ic|.service}}. For example, {{ic|netcfg}} and {{ic|netcfg.service}} are treated equivalent. {{Note|This currently does not work with the commands {{ic|enable}} and {{ic|disable}}.}}
+
* 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.
+
Shut down and power-off the system:
  
Activate a unit immediately:
+
$ systemctl poweroff
  
{{bc|# systemctl start <unit>}}
+
Suspend the system:
  
Deactivate a unit immediately:
+
$ systemctl suspend
  
{{bc|# systemctl stop <unit>}}
+
Put the system into hibernation:
  
Restart a unit:
+
$ systemctl hibernate
  
{{bc|# systemctl restart <unit>}}
+
Put the system into hybrid-sleep state (or suspend-to-both):
  
Ask a unit to reload its configuration:
+
$ systemctl hybrid-sleep
  
{{bc|# systemctl reload <unit>}}
+
== Writing unit files ==
  
Show the status of a unit, including whether it is running or not:
+
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:
  
{{bc|$ systemctl status <unit>}}
+
* {{ic|/usr/lib/systemd/system/}}: units provided by installed packages
 +
* {{ic|/etc/systemd/system/}}: units installed by the system administrator
  
Check whether a unit is already enabled or not:
+
{{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.}}
  
{{bc|$ systemctl is-enabled <unit>}}
+
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}}.
  
Enable a unit to be started on bootup:
+
{{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.}}
  
{{bc|# systemctl enable <unit>}}
+
=== Handling dependencies ===
  
{{Note| If services do not have an Install section, it usually means they are called automatically by other services.  But if you need to install them manually, use the following command, replacing "foo" with the name of the service.
+
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.
  
{{bc|# ln -s /usr/lib/systemd/system/foo.service /etc/systemd/system/graphical.target.wants/}}
+
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.
  
 +
=== Service types ===
 +
 +
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:
 +
 +
* {{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}}.
 +
 +
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.
 +
 +
=== 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 overrides 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:
 +
 +
# 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 {{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}}.
 
}}
 
}}
  
Disable a unit to not start during bootup:
+
==== Replacement unit files ====
  
{{bc|# systemctl disable <unit>}}
+
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:
  
Show the manual page associated with a unit (this has to be supported by the unit file):
+
# systemctl reenable ''unit''
  
{{bc|$ systemctl help <unit>}}
+
Alternatively, run:
  
=== Power Management ===
+
# systemctl edit --full ''unit''
  
If you are in a local ConsoleKit 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.
+
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.
  
Shut down and reboot the system:
+
{{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.}}
  
{{bc|$ systemctl reboot}}
+
==== Drop-in files ====
  
Shut down and power-off the system:
+
To create drop-in files 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.
  
{{bc|$ systemctl poweroff}}
+
The easiest way to do this is to run:
  
Shut down and halt the system:
+
# systemctl edit ''unit''
  
{{bc|$ systemctl halt}}
+
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.
  
Suspend the system:
+
==== Examples ====
  
{{bc|$ systemctl suspend}}
+
For example, if you simply want to add an additional dependency to a unit, you may create the following file:
  
Hibernate the system:
+
{{hc|/etc/systemd/system/''unit''.d/customdependency.conf|2=
 +
[Unit]
 +
Requires=''new dependency''
 +
After=''new dependency''
 +
}}
  
{{bc|$ systemctl hibernate}}
+
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:
  
== Runlevels/targets ==
+
{{hc|/etc/systemd/system/''unit''.d/customexec.conf|2=
Runlevels is a legacy concept in systemd. 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.  
+
[Service]
 +
ExecStart=
 +
ExecStart=''new command''
 +
}}
 +
 
 +
Note how {{ic|ExecStart}} must be cleared before being re-assigned ([https://bugzilla.redhat.com/show_bug.cgi?id=756787#c9]). The same holds for every item that can be specified multiple times, e.g. {{ic|OnCalendar}} for timers.
 +
 
 +
One more example to automatically restart a service:
 +
 
 +
{{hc|/etc/systemd/system/''unit''.d/restart.conf|2=
 +
[Service]
 +
Restart=always
 +
RestartSec=30
 +
}}
 +
 
 +
== Targets ==
 +
 
 +
{{Style|Unclear description, copy-pasted content (explicitly mentions "Fedora").|section=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 ''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.
 +
 
 +
=== Get current targets ===
 +
 
 +
The following should be used under ''systemd'' instead of running {{ic|runlevel}}:
  
=== Get current runlevel/targets ===
+
$ systemctl list-units --type=target
The following should be used under systemd instead of {{ic|runlevel}}:
+
{{bc|1=# systemctl list-units --type=target}}
+
  
 
=== Create custom target ===
 
=== Create custom target ===
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.
+
 
 +
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.
  
 
=== Targets table ===
 
=== Targets table ===
{| border="1"
+
 
!SysV Runlevel!!Systemd Target!!Notes
+
{| class="wikitable"
 +
! SysV Runlevel !! systemd Target !! Notes
 
|-
 
|-
 
| 0 || runlevel0.target, poweroff.target || Halt the system.
 
| 0 || runlevel0.target, poweroff.target || Halt the system.
Line 299: Line 292:
 
|}
 
|}
  
=== Change current runlevels ===
+
=== Change current target ===
In systemd runlevels are exposed via "target units". You can change them like this:
+
{{bc|# systemctl isolate graphical.target}}
+
This will only change the current runlevel, 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 runlevel/target to boot into ===
+
In ''systemd'' targets are exposed via ''target units''. You can change them like this:
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:
+
* {{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 isolate graphical.target
{{bc|# 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:
+
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.
[Install]
+
Alias=default.target
+
is in the target's configuration file. Currently, {{ic|multi-user.target}} and {{ic|graphical.target}} both have it.
+
  
== Running DEs under systemd ==
+
=== Change default target to boot into ===
  
=== Using display manager ===
+
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:
To enable graphical login, run your preferred [[Display Manager]] daemon (e.g. [[KDM]]). At the moment, service files exist for [[GDM]], [[KDM]], [[SLiM]], [[XDM]] and [[LXDM]].
+
  
{{bc|# systemctl enable kdm.service}}
+
* {{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).
  
This should work out of the box. If not, you might have a {{ic|default.target}} set manually or from a older install:
+
Alternatively, you may leave the bootloader alone and change {{ic|default.target}}. This can be done using ''systemctl'':
  
{{hc|# ls -l /etc/systemd/system/default.target|/etc/systemd/system/default.target -> /usr/lib/systemd/system/graphical.target}}
+
# systemctl set-default multi-user.target
  
Simply delete the symlink and systemd will use its stock {{ic|default.target}} (i.e. {{ic|graphical.target}}).
+
To be able to override the previously set {{ic|default.target}}, use the force option:
  
{{bc|# rm /etc/systemd/system/default.target}}
+
# systemctl set-default -f multi-user.target
  
If {{ic|/etc/locale.conf}} is used for setting the locale, add an entry to {{ic|/etc/environment}}:
+
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}}.
{{hc|/etc/environment|<nowiki>
+
LANG=en_US.utf8</nowiki>}}
+
  
=== Using service file ===
+
== Temporary files ==
{{Note|Using this method there will be no PAM session created for your user. Therefore ConsoleKit (which gives you access to shutdown/reboot, audio devices etc.) will not work properly. For the recommended way, see: [[Automatic_login_to_virtual_console#With_systemd]].}}
+
If you are only looking for a simple way to start X directly without a display manager, you can create a service file similar to this:
+
  
{{hc|/etc/systemd/system/graphical.target.wants/xinit.service|<nowiki>
+
"''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.
[Unit]
+
Description=Direct login to X
+
After=systemd-user-sessions.service
+
  
[Service]
+
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:
ExecStart=/bin/su <username> -l -c "/bin/bash --login -c xinit"
+
  
[Install]
+
{{hc|/usr/lib/tmpfiles.d/samba.conf|
WantedBy=graphical.target
+
D /run/samba 0755 root root}}
</nowiki>}}
+
  
== Systemd Journal ==
+
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:
Since version 38 systemd has an own logging system, the journal.
+
  
By default, running a syslog daemon is no longer required. To read the log, use:
+
{{hc|/etc/tmpfiles.d/disable-usb-wake.conf|
{{bc|# journalctl}}
+
w /proc/acpi/wakeup - - - - USBE}}
The journal writes to {{ic|/run/systemd/journal}}, meaning logs will be lost on reboot. For non-volatile logs, create {{ic|/var/log/journal/}}:
+
{{bc|# mkdir /var/log/journal/}}
+
  
=== Filtering output ===
+
See the {{ic|systemd-tmpfiles(8)}} and {{ic|tmpfiles.d(5)}} man pages for details.
  
{{ic|journalctl}} allows you to filter the output by specific fields.
+
{{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.}}
  
Examples:
+
== Timers ==
  
Show all messages by a specific executable:
+
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]].
{{bc|# journalctl /usr/lib/systemd/systemd}}
+
  
Show all messages by a specific process:
+
{{Note|Timers can replace ''cron'' functionality to a great extent. See [[systemd/Timers#As a cron replacement]].}}
{{bc|1=# journalctl _PID=1}}
+
  
Show all messages by a specific unit:
+
== Mounting ==
{{bc|1=# journalctl _SYSTEMD_UNIT=netcfg.service}}
+
  
See {{ic|man journalctl}} and {{ic|systemd.journal-fields}} for details.
+
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.
  
=== journal size limit ===
+
== Journal ==
  
If the journal is made non-volatile, its size limit is set to a default value of 10% of the size of the respective file system. E.g. with {{ic|/var/log/journal}} located on a 50GiB root partition this would lead to 5GiB 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 50MiB uncomment and edit the corresponding line to:
+
''systemd'' has its own logging system called the journal; therefore, running a {{ic|syslog}} daemon is no longer required. To read the log, use:
{{bc|1=SystemMaxUse=50M}}
+
Look at {{ic|man journald.conf}} for more info.
+
  
===Journald in conjunction with a classic syslog daemon===
+
# journalctl
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]). For syslog-ng, change the {{ic|source src}} section in {{ic|/etc/syslog-ng/syslog-ng.conf}} to:
+
{{bc|<nowiki>
+
source src {
+
    unix-dgram("/run/systemd/journal/syslog");
+
    internal();
+
    file("/proc/kmsg");
+
};</nowiki>}}
+
  
and enable syslog-ng:
+
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).
{{bc|# systemctl enable syslog-ng.service}}
+
  
== Network ==
+
The systemd journal event notification message logging classification corresponds to classical BSD syslog protocol style ([[wikipedia:Syslog|Wikipedia]], [https://tools.ietf.org/html/rfc5424 RFC 5424]). For more info see subsections [[#Facility|Facility]], [[#Priority level|Priority level]], and for examples on how to use it in [[#Filtering output|Filtering output]].
=== Dynamic (DHCP) with dhcpcd ===
+
If you simply want to use DHCP for your ethernet connection, you can use {{ic|dhcpcd@.service}} (provided by the {{Pkg|dhcpcd}} package).
+
To enable DHCP for {{ic|eth0}}, simply use:
+
# systemctl start dhcpcd@eth0.service
+
  
You can enable the service to automatically start at boot with:
+
===Facility===
# systemctl enable dhcpcd@eth0.service
+
  
=== Other configurations ===
+
A syslog facility code is used to specify the type of program that is logging the message [https://tools.ietf.org/html/rfc5424#section-6.2.1 RFC 5424 Section 6.2.1].
For static, wireless or advanced network configuration like bridging you can use [[Netcfg#systemd_support|netcfg]] or [[NetworkManager#Enable_NetworkManager_under_Native_systemd_system|NetworkManager]] which both provide systemd service files.
+
{{Note|If you want to use netcfg, networkmanager or another software for managing the network you don't need to start/enable dhcpcd as seen on the previous paragraph.}}
+
  
If you need a static ethernet configuration, but don't want to use [[netcfg]], there is a custom service file available on the [[Systemd/Services#Network|Systemd/Services page]].
+
{| class="wikitable"
 +
! Facility code !! Keyword !! Description !! Info
 +
|-
 +
| 0 || kern || kernel messages
 +
|-
 +
| 1 || user || user-level messages
 +
|-
 +
| 2 || mail || mail system || Archaic POSIX still supported and sometimes used system, for more {{ic|man mail}})
 +
|-
 +
| 3 || daemon || system daemons || All deamons, including systemd and its subsystems
 +
|-
 +
| 4 || auth || security/authorization messages || Also watch for different facility 10
 +
|-
 +
| 5 || syslog || messages generated internally by syslogd || As it standartized for syslogd, not used by systemd (see facility 3)
 +
|-
 +
| 6 || lpr || line printer subsystem (archaic subsystem)
 +
|-
 +
| 7 || news || network news subsystem (archaic subsystem)
 +
|-
 +
| 8 || uucp || UUCP subsystem (archaic subsystem)
 +
|-
 +
| 9 || || clock daemon || systemd-timesyncd
 +
|-
 +
| 10 || authpriv || security/authorization messages || Also watch for different facility 4
 +
|-
 +
| 11 || ftp || FTP daemon
 +
|-
 +
| 12 || - || NTP subsystem
 +
|-
 +
| 13 || - || log audit
 +
|-
 +
| 14 || - || log alert
 +
|-
 +
| 15 || cron || scheduling daemon
 +
|-
 +
| 16 || local0 || local use 0  (local0)
 +
|-
 +
| 17 || local1 || local use 1  (local1)
 +
|-
 +
| 18 || local2 || local use 2  (local2)
 +
|-
 +
| 19 || local3 || local use 3  (local3)
 +
|-
 +
| 20 || local4 || local use 4  (local4)
 +
|-
 +
| 21 || local5 || local use 5  (local5)
 +
|-
 +
| 22 || local6 || local use 6  (local6)
 +
|-
 +
| 23 || local7 || local use 7  (local7)
 +
|}
  
== Arch integration ==
+
So, useful facilities to watch: 0,1,3,4,9,10,15.
=== Initscripts emulation ===
+
Integration with Arch's classic configuration is provided by the {{Pkg|initscripts}} package. This is simply meant as a transitional measure to ease users' move to systemd.
+
  
{{Note|{{ic|/etc/inittab}} is not used at all.}}
+
===Priority level===
  
If you disabeled STGR-ALT-DEL to reboot in /etc/inittab, you will have to reconfigure this setting for systemd by doing {{ic|systemctl mask ctrl-alt-del.target}} as root.
+
A syslog severity code (in systemd called priority) is used to mark the importance of a message [https://tools.ietf.org/html/rfc5424#section-6.2.1 RFC 5424 Section 6.2.1].
  
==== rc.conf ====
 
Some variables in {{ic|/etc/rc.conf}} are respected by this glue work. For a pure systemd setup it is recommended to use the [[Systemd#Native_systemd_configuration_files|native systemd configuration files]] which will take precedence over {{ic|/etc/rc.conf}}.
 
 
Supported variables:
 
* LOCALE
 
* KEYMAP
 
* CONSOLEFONT
 
* CONSOLEMAP
 
* HOSTNAME
 
* DAEMONS
 
 
Not supported variables and systemd configuration:
 
* TIMEZONE: Please symlink {{Ic|/etc/localtime}} to your zoneinfo file manually.
 
* HARDWARECLOCK: See [[Systemd#Hardware clock time|Hardware clock time]].
 
* USELVM: use {{ic|lvm.service}} provided by {{Pkg|lvm2}} instead.
 
* USECOLOR
 
* MODULES
 
 
=== Total conversion to native systemd ===
 
{{Note|This is the preferred method, where the system does not rely on {{ic|rc.conf}} centralised configuration anymore, but uses native systemd configuration files.}}
 
 
Follow system configuration as explained in [[#Native_systemd_configuration_files]]. Each file replaces one section of {{ic|/etc/rc.conf}} as shown in that table:
 
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
! scope="col"| Configuration
+
! Value !! Severity !! Keyword  !! Description || Examples
! scope="col"| Configuration file(s)
+
! scope="col"| Legacy {{ic|/etc/rc.conf}} section
+
 
|-
 
|-
| align="center"|Hostname
+
| 0 || Emergency || emerg || System is unusable || Severe Kernel BUG, systemd dumped core.<br>This level should not be used by applications.
| align="left"|{{ic|/etc/hostname}}
+
{{ic|/etc/hosts}}
+
| align="center"|{{ic|NETWORKING}}
+
 
|-
 
|-
| align="center"|Console fonts and Keymap
+
| 1 || Alert || alert || Should be corrected immediately || Vital subsystem goes out of work. Data loss. <br>{{ic|kernel: BUG: unable to handle kernel paging request at ffffc90403238ffc|}}.
| align="left"|{{ic|/etc/vconsole.conf}}
+
| align="center"|{{ic|LOCALIZATION}}
+
 
|-
 
|-
| align="center"|Locale
+
| 2 || Critical || crit || Critical conditions || Crashes, coredumps. Like familiar flash:<br>{{ic|systemd-coredump[25319]: Process 25310 (plugin-containe) of user 1000 dumped core}}<br>Failure in the system primary application, like X11.
| align="left"|{{ic|/etc/locale.conf}}
+
{{ic|/etc/locale.gen}}
+
| align="center"|{{ic|LOCALIZATION}}
+
 
|-
 
|-
| align="center"|Timezone
+
| 3 || Error || err || Error conditions || Not severe error reported:<br>{{ic|kernel: usb 1-3: 3:1: cannot get freq at ep 0x84}},<br>{{ic|systemd[1]: Failed unmounting /var.}},<br>{{ic|libvirtd[1720]: internal error: Failed to initialize a valid firewall backend}}).
| align="left"|{{ic|/etc/timezone}}
+
{{ic|/etc/localtime}}
+
| align="center"|{{ic|LOCALIZATION}}
+
 
|-
 
|-
| align="center"|Hardware clock
+
| 4 || Warning || warning || May indicate that an error will occur if action is not taken. || A non-root file system has only 1GB free.<br>{{ic|org.freedesktop. Notifications[1860]: (process:5999): Gtk-WARNING **: Locale not supported by C library. Using the fallback 'C' locale}}.
| align="left"|{{ic|/etc/adjtime}}
+
| align="center"|{{ic|LOCALIZATION}}
+
 
|-
 
|-
| align="center"|Kernel modules
+
| 5 || Notice || notice || Events that are unusual, but not error conditions. || {{ic|systemd[1]: var.mount: Directory /var to mount over is not empty, mounting anyway}}. {{ic|gcr-prompter[4997]: Gtk: GtkDialog mapped without a transient parent. This is discouraged}}.
| align="left"|{{ic|/etc/modules-load.d/}}
+
|-
| align="center"|{{ic|HARDWARE}}
+
| 6 || Informational || info ||  Normal operational messages that require no action. || {{ic|lvm[585]:  7 logical volume(s) in volume group "archvg" now active}}.
 +
|-
 +
| 7 || Debug || debug || Information useful to developers for debugging the application. || {{ic|kdeinit5[1900]: powerdevil: Scheduling inhibition from ":1.14" "firefox" with cookie 13 and reason "screen"}}.
 
|}
 
|}
  
For legacy purposes, the '''DAEMONS''' section in {{ic|/etc/rc.conf}} is still compatible with systemd and can be used to start services at boot, even with a "pure" systemd service management. Alternatively, you may remove the {{ic|/etc/rc.conf}} file entirely and enable services in systemd. For each {{ic|<service_name>}} in the '''DAEMONS''' array in {{ic|/etc/rc.conf}}, type:
+
If issue you are looking for, was not found on according level, search it on couple of priority levels above and below. This rules are recommendations. Some errors considered a normal occasion for program so they marked low in priority by developer, and on the contrary, sometimes too many messages plaques too high priorities for them, but often it's an arguable situation. And often you really should solve an issue, also to understand architecture and adopt best practices.
# systemctl enable <service_name>.service
+
 
{{Tip|For a list of commonly used daemons with their initscripts and systemd equivalents, see [[Daemon#List_of_Daemons|this table]].}}
+
Examples:
 +
* Info message:  {{bc|pulseaudio[2047]: W: [pulseaudio] alsa-mixer.c: Volume element Master has 8 channels. That's too much! I can't handle that!}} It is an warning or error by definition.
 +
* Plaguing alert message: {{bc|1=sudo[21711]:    user : a password is required ; TTY=pts/0 ; PWD=/home/user ; USER=root ; COMMAND=list /usr/bin/pacman --color auto -Sy}} The [https://bbs.archlinux.org/viewtopic.php?id=184455 reason] - user was manually added to sudoers file, not to wheel group, which is arguably normal action, but sudo produced an alert on every occasion.
 +
 
 +
=== 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.
  
If {{ic|<service_name>.service}} does not exist:
+
{{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:
* the service file may not be available for systemd. In that case, you'll need to keep {{ic|rc.conf}} to start the service during boot up.
+
{{bc|$ strings /mnt/arch/var/log/journal/af4967d77fba44c6b093d0e9862f6ddd/system.journal <nowiki>| grep -i</nowiki> ''message''}}
* systemd may name services differently, e.g. {{ic|cronie.service}} replaces {{ic|crond}} init daemon; {{ic|alsa-store.service}} and {{ic|alsa-restore.service}} replace the {{ic|alsa}} init daemon. Another important instance is the {{ic|network}} daemon, which is replaced with another set of service files (see [[#Network]] for more details.)
+
{{Tip|you may look inside a package that contains daemon start scripts for service names. For instance:
+
$ pacman -Ql cronie
+
[...]
+
cronie /etc/rc.d/crond                            #<-- daemon initscript listed in the DAEMONS array (unused in a "pure" systemd configuration)
+
[...]
+
cronie /usr/lib/systemd/system/cronie.service    #<-- corresponding systemd daemon service
+
[...]
+
 
}}
 
}}
* systemd will automatically handle the start order of these daemons.
 
* some services do not need to be explicitely enabled by the user. For instance, {{ic|dbus.service}} will automatically be enabled when {{ic|dbus-core}} is installed. Check the list of available services and their state using the {{ic|systemctl}} command.
 
  
== FAQ ==
+
Examples:
For an up-to-date list of known issues, look at the upstream [http://cgit.freedesktop.org/systemd/systemd/tree/TODO TODO].
+
  
{{FAQ
+
* 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.
|question=Why are my console fonts ugly?
+
* Show all messages from date (and optional time): {{bc|1=# journalctl --since="2012-10-30 18:17:16"}}
|answer=If no font is set in {{ic|/etc/vconsole.conf}} (or alternatively {{ic|/etc/rc.conf}}), then a standard font will be used. The standard font is chosen due to it supporting a wide range of character sets. Set your preferred font to fix the issue.}}
+
* 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 SYSLOG_FACILITY=10}}
 +
* Show only error, critical, and alert priority messages {{bc|# journalctl -p err..alert}} Numbers also can be used, {{ic|journalctl -p 3..1}}. If single number/keyword used, {{ic|journalctl -p 3}} - all higher priority levels also included.
  
{{FAQ
+
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.
|question=Why do I get log messages on my console?
+
|answer=You must set the kernel loglevel yourself. Historically, {{ic|/etc/rc.sysinit}} did this for us and set dmesg loglevel to {{ic|3}}, which was a reasonably quiet loglevel. Either add {{ic|1=loglevel=3}} or {{ic|quiet}} to your [[kernel parameters]].}}
+
  
{{FAQ
+
{{Tip|1=
|question=How do I make a custom unit file?
+
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).
|answer=The unit files in {{ic|/etc/systemd/system/}} take precedence over the ones in {{ic|/usr/lib/systemd/system/}}. To make your own version of a unit (which will not be destroyed by an upgrade), copy the old unit file from {{ic|/usr/lib/}} to {{ic|/etc/}} and make your changes there. Alternatively you can use {{ic|.include}} to parse an existing service file and then override or add new options. For example, if you simply want to add an additional dependency to a service file, you may use:
+
{{hc|/etc/systemd/system/<service-name>.service|
+
<nowiki>
+
.include /usr/lib/systemd/system/<service-name>.service
+
  
[Unit]
+
By omitting the {{ic|S}} option, the output will be wrapped instead of truncated. For example, start ''journalctl'' as follows:
Requires=<new dependency>
+
 
After=<new dependency>
+
  $ SYSTEMD_LESS=FRXMK journalctl
</nowiki>}}
+
 
Then run the following for your changes to take effect:
+
If you would like to set this behaviour as default, [[Environment variables#Per_user|export]] the variable from {{ic|~/.bashrc}} or {{ic|~/.zshrc}}.
# systemctl reenable <unit>
+
  # systemctl restart <unit>
+
{{Tip|You can use {{ic|systemd-delta}} to see which unit files have been overriden and what exactly has been changed.}}
+
 
}}
 
}}
{{FAQ
 
|question=How do I change the number of gettys running by default?
 
|answer=To add another getty:
 
  
Simply place another symlink for instantiating another getty in the {{ic|/etc/systemd/system/getty.target.wants/}} directory:
+
=== Journal size limit ===
  
{{bc|<nowiki># ln -sf /usr/lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@tty9.service
+
If the journal is persistent (non-volatile), its size limit is set to a default value of 10% of the size of the underlying file system but capped to 4 GiB. For example, with {{ic|/var/log/journal/}} located on a 20 GiB partition, journal data may take up to 2 GiB. On a 50 GiB partition, it would max at 4 GiB.
# systemctl daemon-reload
+
# systemctl start getty@tty9.service</nowiki>}}
+
  
To remove a getty:
+
The maximum size of the persistent journal can be controlled by uncommenting and changing the following:
  
Simply remove the getty symlinks you want to get rid of in the {{ic|/etc/systemd/system/getty.target.wants/}} directory:
+
{{hc|/etc/systemd/journald.conf|2=
 +
SystemMaxUse=50M
 +
}}
  
{{bc|<nowiki># rm /etc/systemd/system/getty.target.wants/getty@tty5.service /etc/systemd/system/getty.target.wants/getty@tty6.service
+
It is also possible to use the drop-in snippets configuration override mechanism rather than editing the global configuration file. In this case do not forget to place the overrides under the {{ic|[Journal]}} header:
# systemctl daemon-reload
+
# systemctl stop getty@tty5.service getty@tty6.service</nowiki>}}
+
  
systemd does not use the {{ic|/etc/inittab}} file.
+
{{hc|/etc/systemd/journald.conf.d/00-journal-size.conf|2=
 +
[Journal]
 +
SystemMaxUse=50M
 +
}}
  
{{Note|As of systemd 30, only 1 getty will be launched by default. If you switch to another tty, a getty will be launched there (socket-activation style). You can still force additional agetty processes to start using the above methods.}}}}
+
See {{ic|man journald.conf}} for more info.
  
{{FAQ
+
=== Clean journal files manually ===
|question=How do I get more verbose output during boot?
+
|answer=If you see no output at all in console after the initram message, this means you have the {{ic|quiet}} parameter in your kernel line. It's best to remove it, at least the first time you boot with systemd, to see if everything is ok. Then, You will see a list {{ic|[ OK ]}} in green or {{ic|[ FAILED ]}} in red.
+
  
Any messages are logged to the system log and if you want to find out about the status of your system run {{ic|$ systemctl}} or look at the boot/system log with {{ic|journalctl}}.
+
Journal files can be globally removed from {{ic|/var/log/journal/}} using ''e.g.'' {{ic|rm}}, or can be trimmed according to various criteria using {{ic|journalctl}}. Examples:
 +
 
 +
* 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}}
 +
 
 +
See {{ic|man journalctl}} for more info.
 +
 
 +
=== Journald in conjunction with syslog ===
 +
 
 +
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]).
 +
 
 +
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].
 +
 
 +
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 [[#Editing provided units|drop-in directory]] {{ic|/etc/systemd/journald.conf.d}} and create a {{ic|fw-tty12.conf}} file in it:
 +
 
 +
{{hc|1=/etc/systemd/journald.conf.d/fw-tty12.conf|2=
 +
[Journal]
 +
ForwardToConsole=yes
 +
TTYPath=/dev/tty12
 +
MaxLevelConsole=info
 
}}
 
}}
  
{{FAQ
+
Then [[restart]] systemd-journald.
|question=How do I avoid clearing the console after boot?
+
 
|answer=Create a custom {{ic|getty@tty1.service}} file by copying {{ic|/usr/lib/systemd/system/getty@.service}} to {{ic|/etc/systemd/system/getty.target.wants/getty@tty1.service}} and change {{ic|TTYVTDisallocate}} to {{ic|no}}.
+
=== 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:
 +
 
 +
$ journalctl -D ''/mnt''/var/log/journal -xe
 +
 
 +
== Tips and tricks ==
 +
 
 +
=== Enable installed units by default ===
 +
 
 +
{{Expansion|How does it work with instantiated units?}}
 +
 
 +
Arch Linux ships with {{ic|/usr/lib/systemd/system-preset/99-default.preset}} containing {{ic|disable *}}. This causes ''systemctl preset'' to disable all units by default, such that when a new package is installed, the user must manually enable the unit.
 +
 
 +
If this behavior is not desired, simply create a symlink from {{ic|/etc/systemd/system-preset/99-default.preset}} to {{ic|/dev/null}} in order to override the configuration file. This will cause ''systemctl preset'' to enable all units that get installed—regardless of unit type—unless specified in another file in one ''systemctl preset'''s configuration directories. User units are not affected. See the manpage for {{ic|systemd.preset}} for more information.
 +
 
 +
{{Note|Enabling all units by default may cause problems with packages that contain two or more mutually exclusive units. ''systemctl preset'' is designed to be used by distributions and spins or system administrators. In the case where two conflicting units would be enabled, you should explicitly specify which one is to be disabled in a preset configuration file as specified in the manpage for {{ic|systemd.preset}}.}}
 +
 
 +
== Troubleshooting ==
 +
 
 +
=== Investigating systemd errors ===
 +
 
 +
As an example, we will investigate an error with {{ic|systemd-modules-load}} service:
 +
 
 +
'''1.''' Lets find the ''systemd'' services which fail to start:
 +
 
 +
{{hc|1=$ systemctl --failed|2=
 +
systemd-modules-load.service  loaded '''failed failed'''  Load Kernel Modules
 
}}
 
}}
  
{{FAQ
+
'''2.''' Ok, we found a problem with {{ic|systemd-modules-load}} service. We want to know more:
|question=What kernel options do I need to enable in my kernel in case I do not use the official Arch kernel?
+
{{hc|$ systemctl status systemd-modules-load|2=
|answer=Kernels prior to 2.6.39 are unsupported.
+
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}}
  
This is a partial list of required/recommended options, there might be more:
+
'''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''''
 +
}}
  
{{bc|<nowiki>
+
'''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/}}:
CONFIG_AUDIT=y (recommended)
+
{{hc|$ ls -Al /etc/modules-load.d/|
CONFIG_AUDIT_LOGINUID_IMMUTABLE=y (not required, may break sysvinit compat)
+
...
CONFIG_CGROUPS=y
+
-rw-r--r--  1 root root    79  1. Dez 2012  blacklist.conf
CONFIG_IPV6=[y|m] (highly recommended)
+
-rw-r--r--  1 root root    1  2. Mär 14:30 encrypt.conf
CONFIG_UEVENT_HELPER_PATH="" (if you don't use an initramfs)
+
-rw-r--r--  1 root root    3  5. Dez 2012  printing.conf
CONFIG_DEVTMPFS=y
+
-rw-r--r--  1 root root    6 14. Jul 11:01 realtek.conf
CONFIG_DEVTMPFS_MOUNT=y (recommended, if you don't use an initramfs)
+
-rw-r--r--  1 root root    65  2. Jun 23:01 virtualbox.conf
CONFIG_RTC_DRV_CMOS=y (highly recommended)
+
...
CONFIG_FANOTIFY=y (required for readahead)
+
}}
CONFIG_AUTOFS4_FS=[y|m]
+
CONFIG_TMPFS_POSIX_ACL=y (recommended, if you want to use pam_systemd.so)
+
</nowiki>}}}}
+
  
{{FAQ
+
'''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:
|question=What other units does a unit depend on?
+
{{hc|/etc/modules-load.d/blacklist.conf|
|answer=For example, if you want to figure out which services a target like {{ic|multi-user.target}} pulls in, use something like this:  
+
'''#''' blacklist usblp
{{hc|$ systemctl show -p "Wants" multi-user.target|2=Wants=rc-local.service avahi-daemon.service rpcbind.service NetworkManager.service acpid.service dbus.service atd.service crond.service auditd.service ntpd.service udisks.service bluetooth.service cups.service wpa_supplicant.service getty.target modem-manager.service portreserve.service abrtd.service yum-updatesd.service upowerd.service test-first.service pcscd.service rsyslog.service haldaemon.service remote-fs.target plymouth-quit.service systemd-update-utmp-runlevel.service sendmail.service lvm2-monitor.service cpuspeed.service udev-post.service mdmonitor.service iscsid.service livesys.service livesys-late.service irqbalance.service iscsi.service}}
+
'''#''' install usblp /bin/false
 +
}}
  
Instead of {{ic|Wants}} you might also try {{ic|WantedBy}}, {{ic|Requires}}, {{ic|RequiredBy}}, {{ic|Conflicts}}, {{ic|ConflictedBy}}, {{ic|Before}}, {{ic|After}} for the respective types of dependencies and their inverse.}}
+
'''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.
  
{{FAQ
+
If everything is ok, you can verify that the service was started successfully with:
|question=My computer shuts down, but the power stays on.
+
{{hc|$ systemctl status systemd-modules-load|2=
|answer=Use:
+
systemd-modules-load.service - Load Kernel Modules
  $ systemctl poweroff
+
  Loaded: '''loaded''' (/usr/lib/systemd/system/systemd-modules-load.service; static)
Instead of {{ic|systemctl halt}}.}}
+
  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'''.
 +
}}
  
== Optimization ==
+
Often you can solve these kind of problems like shown above. For further investigation look at [[#Diagnosing boot problems]].
=== 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. You have to install {{Pkg|python2-dbus}} and {{Pkg|python2-cairo}} to use it.
+
  
To see how much time was spent in kernel-/userspace on boot, simply use:
+
=== Diagnosing boot problems ===
{{bc|$ systemd-analyze}}
+
{{Tip|If you add the {{ic|timestamp}} hook to your {{ic|HOOKS}} array in {{ic|/etc/mkinitcpio.conf}} and rebuild your initramfs, {{ic|systemd-analyze}} will also be able to show you how much time was spent in the initramfs.}}
+
  
To list the started unit files, sorted by the time each of them took to start up:
+
''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].
{{bc|$ systemd-analyze blame}}
+
  
You can also create a SVG file which describes your boot process grapically, similiar to [[Bootchart]]:
+
=== Diagnosing problems with a specific service ===
{{bc|$ systemd-analyze plot > plot.svg}}
+
  
====Enabling bootchart in conjunction with systemd====
+
{{Accuracy|This may not catch all errors such as missing libraries.|User talk:Alucryd#Plex}}
You can use a version of bootchart to visualize the boot sequence.
+
Since you are not able to put a second init into the kernel cmdline 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:
+
{{bc|# systemctl enable bootchart.service}}
+
Read the [https://github.com/mmeeks/bootchart bootchart documentation] for further details on using this version of bootchart.
+
  
=== Shell Shortcuts ===
+
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:
Systemd daemon management requires a bit more text entry to accomplish tasks such as start, stopped, enabling, checking status, etc. The following functions can be added one's {{ic|~/.bashrc}} to help streamline interactions with systemd and to improve the overall experience.
+
  
<pre>if ! systemd-notify --booted; then # not using systemd
+
# systemctl stop systemd-networkd
  start() {
+
# SYSTEMD_LOG_LEVEL=debug /lib/systemd/systemd-networkd
    sudo rc.d start $1
+
  }
+
  
  restart() {
+
Or, equivalently, modify the service file temporarily for gathering enough output. For example:
    sudo rc.d restart $1
+
  }
+
  
  stop() {
+
{{hc|/usr/lib/systemd/system/systemd-networkd.service|2=
    sudo rc.d stop $1
+
[Service]
  }
+
...
else
+
Environment=SYSTEMD_LOG_LEVEL=debug
  start() {
+
....
    sudo systemctl start $1
+
}}
  }
+
  
  restart() {
+
If debug information is required long-term, add the variable the [[#Editing provided units|regular]] way.
    sudo systemctl restart $1
+
  }
+
  
  stop() {
+
=== Shutdown/reboot takes terribly long ===
    sudo systemctl stop $1
+
  }
+
  
  enable() {
+
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].
    sudo systemctl enable $1
+
  }
+
  
  status() {
+
=== Short lived processes do not seem to log any output ===
    sudo systemctl status $1
+
  }
+
  
  disable() {
+
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}}.
    sudo systemctl disable $1
+
  }
+
fi
+
</pre>
+
  
=== Less output ===
+
=== Boot time increasing over time ===
Change {{ic|verbose}} to {{ic|quiet}} on the kernel line in GRUB. For some systems, particularly those with an SSD, the slow performance of the TTY is actually a bottleneck, and so less output means faster booting.
+
  
=== Early start ===
+
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.  
One central feature of systemd is dbus and socket activation, this causes services to be started when they are first accessed, and is generally a good thing. However, if you know that a service (like console-kit) will always be started during boot, then the overall boot time might be reduced by starting it as early as possible. This can be achieved (if the service file is set up for it, which in most cases it is) by issuing:
+
  
{{bc|# systemctl enable console-kit-daemon.service}}
+
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]].
  
This will cause systemd to start console-kit as soon as possible, without causing races with the socket or dbus activation.
+
=== systemd-tmpfiles-setup.service fails to start at boot ===
  
=== Automount ===
+
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.
The default setup will fsck and mount all filesystems before starting most daemons and services. 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 being fsck'ed. This can be achieved by adding the following options to the fstab entry of your {{ic|/home}} partition:
+
  
noauto,x-systemd.automount
+
See [[Access Control Lists#Enabling ACL]] for instructions on how to enable ACL on the filesystem that houses {{ic|/var/log/journal}}.
  
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.
+
=== systemctl enable fails for symlinks in /etc/systemd/system ===
  
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:
+
If {{ic|/etc/systemd/system/''foo''.service}} is a symlink and {{ic|systemctl enable ''foo''.service}} is run, it will fail with this error:
{{hc|/etc/crypttab|data /dev/md0 /root/key noauto}}
+
  
=== Readahead ===
+
Failed to issue method call: No such file or directory
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:
+
  
{{bc|<nowiki># systemctl enable systemd-readahead-collect.service systemd-readahead-replay.service</nowiki>}}
+
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:
  
Remember that in order for the readahead to work its magic, you should reboot a couple of times.
+
# systemctl enable ''/absolute/path/foo''.service
  
=== User sessions ===
+
=== dependent services are not started when starting a service manually===
systemd can divide user sessions into cgroups. Add {{ic|session optional pam_systemd.so}} to your relevant {{ic|/etc/pam.d/}} files (e.g., {{ic|login}} for tty logins, {{ic|sshd}} for remote access, {{ic|kde}} for password kdm logins, {{ic|kde-np}} for automatic kdm logins).
+
  
Before:
+
{{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}}
{{hc|$ systemd-cgls systemd:/system/getty@.service|
+
systemd:/system/getty@.service:
+
├ tty5
+
│ └ 904 /sbin/agetty tty5 38400
+
├ tty2
+
│ ├ 13312 /bin/login --
+
│ └ 15765 -zsh
+
[…]}}
+
After:
+
{{hc|$ systemd-cgls systemd:/user/example/|
+
systemd:/user/example/:
+
├ 4
+
│ ├  902 /bin/login --
+
│ └ 16016 -zsh
+
[…]}}
+
  
Further, you can replace [[ConsoleKit]]'s functionality with systemd. To do this, {{Pkg|polkit}} needs to be rebuilt from [[ABS]] with systemd enabled ({{ic|--enable-systemd}}), and stuff like USB automounting will work without consolekit. DBus supports systemd since version 1.6.0, so there's no longer need to build it from Git.
+
One (in)famous example is {{ic|libvirtd.service}} which needs the {{ic|virtlogd.socket}} to function properly.  
  
== Troubleshooting ==
+
The dependencies in {{ic|/usr/lib/systemd/system/libvirtd.service}} are defined as
=== Shutdown/Reboot takes terribly long ===
+
[Install]
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.
+
WantedBy=multi-user.target
To find out if you are affected see [http://freedesktop.org/wiki/Software/systemd/Debugging#Shutdown_Completes_Eventually this article].
+
Also=virtlockd.socket
==== SLiM and xfce-session ====
+
Also=virtlogd.socket
One setup that can produce a shutdown freeze is Xfce in conjunction with SLiM: Shutting down/rebooting using xfce-session will cause slim.service to hang for half a minute until systemd kills it the hard way.
+
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}}
One workaround is to create a modified slim.service:
+
{{hc|/etc/systemd/system/slim.service|<nowiki>
+
[Unit]
+
Description=SLiM Simple Login Manager
+
After=systemd-user-sessions.service
+
  
[Service]
+
Thus the correct (?) way to manually start a service with dependent subservices once (instead of at each start of the system) probably is
Type=forking
+
systemctl enable ServiceWithSubservices
PIDFile=/var/lock/slim.lock
+
systemctl start ServiceWithSubservices
ExecStart=/usr/bin/slim -d
+
systemctl disable ServiceWithSubservices
ExecStop=/bin/kill -9 $MAINPID
+
 
ExecStopPost=/bin/rm /var/lock/slim.lock
+
=== systemd version printed on boot is not the same as installed package version ===
  
[Install]
+
You need to [[Mkinitcpio#Image_creation_and_activation|regenerate your initramfs]] and the versions should match.  
WantedBy=graphical.target</nowiki>}}
+
This causes SLiM to be terminated using SIGKILL. Since the lock file is also removed this does not cause a problem.
+
  
=== If the CUPS service isn't starting on demand ===
+
{{Tip|1=A pacman hook can be used to automatically regenerate the initramfs every time {{pkg|systemd}} is upgraded. See [https://bbs.archlinux.org/viewtopic.php?id=215411 this forum thread] and [[Pacman#Hooks]].}}
I found on my machine, even after running "systemctl enable cups.service", cups would never work until I manually issued "systemctl start cups.service". To remedy this you can manually symlink the cups service so its automatically started at boot: {{bc|<nowiki># sudo ln -s '/usr/lib/systemd/system/cups.service' '/etc/systemd/system/multi-user.target.wants/cups.service'</nowiki>}}
+
I found that "systemctl enable cupsd.service" fails with a complaint about not finding the file. I'm guessing this is because it is a symlink to cups.service. Apparently systemctl doesn't like symlinks. I'm not sure if this is user error (I wasn't meant to use the symlink for this purpose) or a bug but either way, specifying cups.service seemed to work although I haven't tested it yet.
+
  
=== Disable warning bell ===
+
== See also ==
Add command xset -b to .xinitrc file.
+
Discussion on [https://bbs.archlinux.org/viewtopic.php?pid=1148781 forum]
+
  
== See also==
+
*[http://www.freedesktop.org/wiki/Software/systemd Official web site]
*[http://www.freedesktop.org/wiki/Software/systemd Official Web Site]
+
*[[Wikipedia:systemd|Wikipedia article]]
*[http://0pointer.de/public/systemd-man/ Manual Pages]
+
*[http://0pointer.de/public/systemd-man/ Manual pages]
*[http://freedesktop.org/wiki/Software/systemd/Optimizations systemd Optimizations]
+
*[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]
*[http://fedoraproject.org/wiki/How_to_debug_Systemd_problems How to debug Systemd problems]
+
*[http://fedoraproject.org/wiki/How_to_debug_Systemd_problems How to debug systemd problems]
*[http://www.h-online.com/open/features/Booting-up-Tools-and-tips-for-systemd-1570630.html Booting up: Tools and tips for systemd, a Linux init tool. In The H]
+
*[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://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 17:27, 17 August 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 overrides 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 files

To create drop-in files 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]). The same holds for every item that can be specified multiple times, e.g. OnCalendar for timers.

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).

The systemd journal event notification message logging classification corresponds to classical BSD syslog protocol style (Wikipedia, RFC 5424). For more info see subsections Facility, Priority level, and for examples on how to use it in Filtering output.

Facility

A syslog facility code is used to specify the type of program that is logging the message RFC 5424 Section 6.2.1.

Facility code Keyword Description Info
0 kern kernel messages
1 user user-level messages
2 mail mail system Archaic POSIX still supported and sometimes used system, for more man mail)
3 daemon system daemons All deamons, including systemd and its subsystems
4 auth security/authorization messages Also watch for different facility 10
5 syslog messages generated internally by syslogd As it standartized for syslogd, not used by systemd (see facility 3)
6 lpr line printer subsystem (archaic subsystem)
7 news network news subsystem (archaic subsystem)
8 uucp UUCP subsystem (archaic subsystem)
9 clock daemon systemd-timesyncd
10 authpriv security/authorization messages Also watch for different facility 4
11 ftp FTP daemon
12 - NTP subsystem
13 - log audit
14 - log alert
15 cron scheduling daemon
16 local0 local use 0 (local0)
17 local1 local use 1 (local1)
18 local2 local use 2 (local2)
19 local3 local use 3 (local3)
20 local4 local use 4 (local4)
21 local5 local use 5 (local5)
22 local6 local use 6 (local6)
23 local7 local use 7 (local7)

So, useful facilities to watch: 0,1,3,4,9,10,15.

Priority level

A syslog severity code (in systemd called priority) is used to mark the importance of a message RFC 5424 Section 6.2.1.

Value Severity Keyword Description Examples
0 Emergency emerg System is unusable Severe Kernel BUG, systemd dumped core.
This level should not be used by applications.
1 Alert alert Should be corrected immediately Vital subsystem goes out of work. Data loss.
kernel: BUG: unable to handle kernel paging request at ffffc90403238ffc.
2 Critical crit Critical conditions Crashes, coredumps. Like familiar flash:
systemd-coredump[25319]: Process 25310 (plugin-containe) of user 1000 dumped core
Failure in the system primary application, like X11.
3 Error err Error conditions Not severe error reported:
kernel: usb 1-3: 3:1: cannot get freq at ep 0x84,
systemd[1]: Failed unmounting /var.,
libvirtd[1720]: internal error: Failed to initialize a valid firewall backend).
4 Warning warning May indicate that an error will occur if action is not taken. A non-root file system has only 1GB free.
org.freedesktop. Notifications[1860]: (process:5999): Gtk-WARNING **: Locale not supported by C library. Using the fallback 'C' locale.
5 Notice notice Events that are unusual, but not error conditions. systemd[1]: var.mount: Directory /var to mount over is not empty, mounting anyway. gcr-prompter[4997]: Gtk: GtkDialog mapped without a transient parent. This is discouraged.
6 Informational info Normal operational messages that require no action. lvm[585]: 7 logical volume(s) in volume group "archvg" now active.
7 Debug debug Information useful to developers for debugging the application. kdeinit5[1900]: powerdevil: Scheduling inhibition from ":1.14" "firefox" with cookie 13 and reason "screen".

If issue you are looking for, was not found on according level, search it on couple of priority levels above and below. This rules are recommendations. Some errors considered a normal occasion for program so they marked low in priority by developer, and on the contrary, sometimes too many messages plaques too high priorities for them, but often it's an arguable situation. And often you really should solve an issue, also to understand architecture and adopt best practices.

Examples:

  • Info message:
    pulseaudio[2047]: W: [pulseaudio] alsa-mixer.c: Volume element Master has 8 channels. That's too much! I can't handle that!
    It is an warning or error by definition.
  • Plaguing alert message:
    sudo[21711]:     user : a password is required ; TTY=pts/0 ; PWD=/home/user ; USER=root ; COMMAND=list /usr/bin/pacman --color auto -Sy
    The reason - user was manually added to sudoers file, not to wheel group, which is arguably normal action, but sudo produced an alert on every occasion.

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 SYSLOG_FACILITY=10
  • Show only error, critical, and alert priority messages
    # journalctl -p err..alert
    Numbers also can be used, journalctl -p 3..1. If single number/keyword used, journalctl -p 3 - all higher priority levels also included.

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 underlying file system but capped to 4 GiB. For example, with /var/log/journal/ located on a 20 GiB partition, journal data may take up to 2 GiB. On a 50 GiB partition, it would max at 4 GiB.

The maximum size of the persistent journal can be controlled by uncommenting and changing the following:

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

It is also possible to use the drop-in snippets configuration override mechanism rather than editing the global configuration file. In this case do not forget to place the overrides under the [Journal] header:

/etc/systemd/journald.conf.d/00-journal-size.conf
[Journal]
SystemMaxUse=50M

See man journald.conf for more info.

Clean journal files manually

Journal files can be globally removed from /var/log/journal/ using e.g. rm, or can be trimmed according to various criteria using 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

See 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

Tips and tricks

Enable installed units by default

Tango-view-fullscreen.pngThis article or section needs expansion.Tango-view-fullscreen.png

Reason: How does it work with instantiated units? (Discuss in Talk:Systemd#)

Arch Linux ships with /usr/lib/systemd/system-preset/99-default.preset containing disable *. This causes systemctl preset to disable all units by default, such that when a new package is installed, the user must manually enable the unit.

If this behavior is not desired, simply create a symlink from /etc/systemd/system-preset/99-default.preset to /dev/null in order to override the configuration file. This will cause systemctl preset to enable all units that get installed—regardless of unit type—unless specified in another file in one systemctl preset's configuration directories. User units are not affected. See the manpage for systemd.preset for more information.

Note: Enabling all units by default may cause problems with packages that contain two or more mutually exclusive units. systemctl preset is designed to be used by distributions and spins or system administrators. In the case where two conflicting units would be enabled, you should explicitly specify which one is to be disabled in a preset configuration file as specified in the manpage for systemd.preset.

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.

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)famous 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

systemd version printed on boot is not the same as installed package version

You need to regenerate your initramfs and the versions should match.

Tip: A pacman hook can be used to automatically regenerate the initramfs every time systemd is upgraded. See this forum thread and Pacman#Hooks.

See also