Skip to content

Commit

Permalink
Merge pull request #23366 from rhatdan/quadlet
Browse files Browse the repository at this point in the history
Add /run/containers/systemd, ${XDG_RUNTIME_DIR}/containers/systemd quadlet dirs
  • Loading branch information
openshift-merge-bot[bot] authored Jul 24, 2024
2 parents 85358ae + ce7dded commit 7ee2cfa
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
8 changes: 7 additions & 1 deletion cmd/quadlet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func Debugf(format string, a ...interface{}) {
// This returns the directories where we read quadlet .container and .volumes from
// For system generators these are in /usr/share/containers/systemd (for distro files)
// and /etc/containers/systemd (for sysadmin files).
// For user generators these can live in /etc/containers/systemd/users, /etc/containers/systemd/users/$UID, and $XDG_CONFIG_HOME/containers/systemd
// For user generators these can live in $XDG_RUNTIME_DIR/containers/systemd, /etc/containers/systemd/users, /etc/containers/systemd/users/$UID, and $XDG_CONFIG_HOME/containers/systemd
func getUnitDirs(rootless bool) []string {
// Allow overriding source dir, this is mainly for the CI tests
unitDirsEnv := os.Getenv("QUADLET_UNIT_DIRS")
Expand All @@ -127,6 +127,11 @@ func getUnitDirs(rootless bool) []string {
}

if rootless {
runtimeDir, found := os.LookupEnv("XDG_RUNTIME_DIR")
if found {
dirs = appendSubPaths(dirs, path.Join(runtimeDir, "containers/systemd"), false, nil)
}

configDir, err := os.UserConfigDir()
if err != nil {
fmt.Fprintf(os.Stderr, "Warning: %v", err)
Expand All @@ -143,6 +148,7 @@ func getUnitDirs(rootless bool) []string {
return append(dirs, filepath.Join(quadlet.UnitDirAdmin, "users"))
}

dirs = appendSubPaths(dirs, quadlet.UnitDirTemp, false, userLevelFilter)
dirs = appendSubPaths(dirs, quadlet.UnitDirAdmin, false, userLevelFilter)
return appendSubPaths(dirs, quadlet.UnitDirDistro, false, nil)
}
Expand Down
5 changes: 5 additions & 0 deletions cmd/quadlet/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func TestIsUnambiguousName(t *testing.T) {

func TestUnitDirs(t *testing.T) {
rootDirs := []string{}
rootDirs = appendSubPaths(rootDirs, quadlet.UnitDirTemp, false, userLevelFilter)
rootDirs = appendSubPaths(rootDirs, quadlet.UnitDirAdmin, false, userLevelFilter)
rootDirs = appendSubPaths(rootDirs, quadlet.UnitDirDistro, false, userLevelFilter)
unitDirs := getUnitDirs(false)
Expand All @@ -60,6 +61,10 @@ func TestUnitDirs(t *testing.T) {

rootlessDirs := []string{}

runtimeDir, found := os.LookupEnv("XDG_RUNTIME_DIR")
if found {
rootlessDirs = appendSubPaths(rootlessDirs, path.Join(runtimeDir, "containers/systemd"), false, nil)
}
rootlessDirs = appendSubPaths(rootlessDirs, path.Join(configDir, "containers/systemd"), false, nil)
rootlessDirs = appendSubPaths(rootlessDirs, filepath.Join(quadlet.UnitDirAdmin, "users"), true, nonNumericFilter)
rootlessDirs = appendSubPaths(rootlessDirs, filepath.Join(quadlet.UnitDirAdmin, "users", u.Uid), true, userLevelFilter)
Expand Down
16 changes: 13 additions & 3 deletions docs/source/markdown/podman-systemd.unit.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,25 @@ podman\-systemd.unit - systemd units using Podman Quadlet

### Podman rootful unit search path

Quadlet files for the root user can be placed in the following two directories:
Quadlet files for the root user can be placed in the following directories ordered in precedence. Meaning duplicate named quadlets found under /run take precedence over ones in /etc, as well as those in /usr:

* /etc/containers/systemd/
* /usr/share/containers/systemd/
Temporary quadlets, usually used for testing:

* /run/containers/systemd/

System administrator's defined quadlets:

* /etc/containers/systemd/

Distribution defined quadlets:

* /usr/share/containers/systemd/

### Podman rootless unit search path

Quadlet files for non-root users can be placed in the following directories

* $XDG_RUNTIME_DIR/containers/systemd/
* $XDG_CONFIG_HOME/containers/systemd/ or ~/.config/containers/systemd/
* /etc/containers/systemd/users/$(UID)
* /etc/containers/systemd/users/
Expand Down
2 changes: 2 additions & 0 deletions pkg/systemd/quadlet/quadlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const (
// github.com/containers/podman/v5/libpod/define.AutoUpdateLabel
// but it is causing bloat
autoUpdateLabel = "io.containers.autoupdate"
// Directory for temporary Quadlet files (sysadmin owned)
UnitDirTemp = "/run/containers/systemd"
// Directory for global Quadlet files (sysadmin owned)
UnitDirAdmin = "/etc/containers/systemd"
// Directory for global Quadlet files (distro owned)
Expand Down

0 comments on commit 7ee2cfa

Please sign in to comment.