<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Using Systemd on Flatcar Container Linux on Flatcar Container Linux</title>
    <link>/docs/latest/setup/systemd/</link>
    <description>Recent content in Using Systemd on Flatcar Container Linux on Flatcar Container Linux</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <copyright>Copyright © The Flatcar Project Contributors.

Copyright © Flatcar a Series of LF Projects, LLC.

For website terms of use, trademark policy and other project policies please see &lt;a href=&#34;https://lfprojects.org/policies/&#34;&gt;lfprojects.org/policies&lt;/a&gt;.
</copyright>
    <atom:link href="/docs/latest/setup/systemd/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Getting started with systemd</title>
      <link>/docs/latest/setup/systemd/getting-started/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>/docs/latest/setup/systemd/getting-started/</guid>
      <description>&lt;p&gt;systemd is an init system that provides many powerful features for starting, stopping, and managing processes. Within Flatcar Container Linux, you will almost exclusively use systemd to manage the lifecycle of your Docker containers.&lt;/p&gt;&#xA;&lt;h2 id=&#34;terminology&#34;&gt;Terminology&lt;/h2&gt;&#xA;&lt;p&gt;systemd consists of two main concepts: a unit and a target. A unit is a configuration file that describes the properties of the process that you&amp;rsquo;d like to run. This is normally a &lt;code&gt;docker run&lt;/code&gt; command or something similar. A target is a grouping mechanism that allows systemd to start up groups of processes at the same time. This happens at every boot as processes are started at different run levels.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Overview of systemctl</title>
      <link>/docs/latest/setup/systemd/systemctl/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>/docs/latest/setup/systemd/systemctl/</guid>
      <description>&lt;p&gt;&lt;code&gt;systemctl&lt;/code&gt; is your interface to systemd, the init system used in Flatcar Container Linux. All processes on a single machine are started and managed by systemd, including your Docker containers. You can learn more in our &#xA;&#xA;&#xA;&lt;a href=&#34;/docs/latest/setup/systemd/getting-started/&#34;&gt;Getting Started with systemd&lt;/a&gt;&#xA; guide. Let&amp;rsquo;s explore a few helpful &lt;code&gt;systemctl&lt;/code&gt; commands. You must run all of these commands locally on the Flatcar Container Linux machine:&lt;/p&gt;&#xA;&lt;h2 id=&#34;find-the-status-of-a-container&#34;&gt;Find the status of a container&lt;/h2&gt;&#xA;&lt;p&gt;The first step to troubleshooting with &lt;code&gt;systemctl&lt;/code&gt; is to find the status of the item in question. If you have multiple &lt;code&gt;Exec&lt;/code&gt; commands in your service file, you can see which one of them is failing and view the exit code. Here&amp;rsquo;s a failing service that starts a private Docker registry in a container:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Using systemd drop-in units</title>
      <link>/docs/latest/setup/systemd/drop-in-units/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>/docs/latest/setup/systemd/drop-in-units/</guid>
      <description>&lt;p&gt;There are two methods of overriding default Flatcar Container Linux settings in unit files: copying the unit file from &lt;code&gt;/usr/lib64/systemd/system&lt;/code&gt; to &lt;code&gt;/etc/systemd/system&lt;/code&gt; and modifying the chosen settings. Alternatively, one can create a directory named &lt;code&gt;unit.d&lt;/code&gt; within &lt;code&gt;/etc/systemd/system&lt;/code&gt; and place a drop-in file &lt;code&gt;name.conf&lt;/code&gt; there that only changes the specific settings one is interested in. Note that multiple such drop-in files are read if present.&lt;/p&gt;&#xA;&lt;p&gt;The advantage of the first method is that one easily overrides the complete unit, the default Flatcar Container Linux unit is not parsed at all anymore. It has the disadvantage that improvements to the unit file supplied by Flatcar Container Linux are not automatically incorporated on updates.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Scheduling tasks with systemd timers</title>
      <link>/docs/latest/setup/systemd/timers/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>/docs/latest/setup/systemd/timers/</guid>
      <description>&lt;p&gt;Flatcar Container Linux uses systemd timers (&lt;code&gt;cron&lt;/code&gt; replacement) to schedule tasks. Here we will show you how you can schedule a periodic job.&lt;/p&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s create an alternative for this &lt;code&gt;crontab&lt;/code&gt; job:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;*/10 * * * * /usr/bin/date &amp;gt;&amp;gt; /tmp/date&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Timers work directly with services&amp;rsquo; units. So we have to create &lt;code&gt;/etc/systemd/system/date.service&lt;/code&gt; first:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-ini&#34; data-lang=&#34;ini&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#00f&#34;&gt;[Unit]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Description=&lt;span style=&#34;color:#a31515&#34;&gt;Prints date into /tmp/date file&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#00f&#34;&gt;[Service]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Type=&lt;span style=&#34;color:#a31515&#34;&gt;oneshot&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;ExecStart=&lt;span style=&#34;color:#a31515&#34;&gt;/usr/bin/sh -c &amp;#39;/usr/bin/date &amp;gt;&amp;gt; /tmp/date&amp;#39;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then we have to create timer unit with the same name but with &lt;code&gt;*.timer&lt;/code&gt; suffix &lt;code&gt;/etc/systemd/system/date.timer&lt;/code&gt;:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Using environment variables in systemd units</title>
      <link>/docs/latest/setup/systemd/environment-variables/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>/docs/latest/setup/systemd/environment-variables/</guid>
      <description>&lt;h2 id=&#34;environment-directive&#34;&gt;Environment directive&lt;/h2&gt;&#xA;&lt;p&gt;systemd has an Environment directive which sets environment variables for executed processes. It takes a space-separated list of variable assignments. This option may be specified more than once in which case all listed variables will be set. If the same variable is set twice, the later setting will override the earlier setting. If the empty string is assigned to this option, the list of environment variables is reset, all prior assignments have no effect. Environments directives are used in built-in Flatcar Container Linux systemd units, for example in etcd2 and flannel.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Using systemd and udev rules</title>
      <link>/docs/latest/setup/systemd/udev-rules/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>/docs/latest/setup/systemd/udev-rules/</guid>
      <description>&lt;p&gt;In our example we will use libvirt VM with Flatcar Container Linux and run systemd unit on disk attach event. First of all we have to create systemd unit file &lt;code&gt;/etc/systemd/system/device-attach.service&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-ini&#34; data-lang=&#34;ini&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#00f&#34;&gt;[Service]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Type=&lt;span style=&#34;color:#a31515&#34;&gt;oneshot&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;ExecStart=&lt;span style=&#34;color:#a31515&#34;&gt;/usr/bin/echo &amp;#39;device has been attached&amp;#39;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This unit file will be triggered by our udev rule.&lt;/p&gt;&#xA;&lt;p&gt;Then we have to start &lt;code&gt;udevadm monitor --environment&lt;/code&gt; to monitor kernel events.&lt;/p&gt;&#xA;&lt;p&gt;Once you&amp;rsquo;ve attached virtio libvirt device (i.e. &lt;code&gt;virsh attach-disk coreos /dev/VG/test vdc&lt;/code&gt;) you&amp;rsquo;ll see similar &lt;code&gt;udevadm&lt;/code&gt; output:&lt;/p&gt;</description>
    </item>
    <item>
      <title>User Units</title>
      <link>/docs/latest/setup/systemd/user-units/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>/docs/latest/setup/systemd/user-units/</guid>
      <description>&lt;p&gt;Flatcar Container Linux supports the use of systemd user units.  These are unit files located in a users home directory, managed by the user, and executed with their permission.&lt;/p&gt;&#xA;&lt;p&gt;User units are stored in &lt;code&gt;~/.config/systemd/user/&lt;/code&gt;.  When using Butane to configure these during provisioning you must create this entire path, level by level as demonstrated here.  This is adapated from &#xA;&#xA;&#xA;&lt;a href=&#34;https://docs.fedoraproject.org/en-US/fedora-coreos/tutorial-user-systemd-unit-on-boot/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;documentation for Fedora CoreOS&lt;/a&gt;&#xA;.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-yaml&#34; data-lang=&#34;yaml&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;variant: flatcar&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;version: 1.0.0&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;storage:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  directories:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#008000&#34;&gt;# Path for $user&amp;#39;s systemd units&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    - path: /home/$user/.config&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      mode: 0755&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      user:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        name: $user&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      group:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        name: $user&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    - path: /home/$user/.config/systemd&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      mode: 0755&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      user:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        name: $user&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      group:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        name: $user&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    - path: /home/$user/.config/systemd/user&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      mode: 0755&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      user:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        name: $user&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      group:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        name: $user&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#008000&#34;&gt;# Path to manually enable $user&amp;#39;s systemd units - these are links back to the unit file&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    - path: /home/$user/.config/systemd/user/default.target.wants&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      mode: 0755&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      user:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        name: $user&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      group:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        name: $user&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#008000&#34;&gt;# Path for $user&amp;#39;s podman quadlets&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    - path: /home/$user/.config/containers/systemd&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      mode: 0755&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      user:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        name: $user&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      group:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        name: $user&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;network-access&#34;&gt;Network Access&lt;/h2&gt;&#xA;&lt;p&gt;In some cases the network will not be online when the user units are executed.  This may happen when there is no network requiring component in the boot process.  For example, requiring a network mounted home directory would cause user units to execute after the network was online.  If you have no such requirements or wish to gurantee that the network is online before user units are excuted you can use the following systemd dropin to modify the &lt;code&gt;systemd-user-sessions.service&lt;/code&gt; to run after the network is online.  This affects all users.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
