Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation for systemd unit files #395

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions content/docs/latest/setup/systemd/user-units.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
title: User Units
linktitle: User Units
description: Systemd User Units
weight: 40
---

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.

User units are stored in `~/.config/systemd/user/`. When using Butane to configure these during provisioning you must create this entire path, level by level as demonstrated here. This is adapated from [documentation for Fedora CoreOS](https://docs.fedoraproject.org/en-US/fedora-coreos/tutorial-user-systemd-unit-on-boot/).

```yaml
variant: flatcar
version: 1.0.0
storage:
directories:
# Path for $user's systemd units
- path: /home/$user/.config
mode: 0755
user:
name: $user
group:
name: $user
- path: /home/$user/.config/systemd
mode: 0755
user:
name: $user
group:
name: $user
- path: /home/$user/.config/systemd/user
mode: 0755
user:
name: $user
group:
name: $user

# Path to manually enable $user's systemd units - these are links back to the unit file
- path: /home/$user/.config/systemd/user/default.target.wants
mode: 0755
user:
name: $user
group:
name: $user

# Path for $user's podman quadlets
- path: /home/$user/.config/containers/systemd
mode: 0755
user:
name: $user
group:
name: $user
```

## Network Access

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 `systemd-user-sessions.service` to run after the network is online. This affects all users.

```yaml
variant: flatcar
version: 1.0.0
systemd:
units:
- name: systemd-user-sessions.service
dropins:
- name: users-after-network.conf
contents: |
[Unit]
After=network-online.target
```