Skip to content

Commit d842b14

Browse files
Merge pull request #25699 from johnschug/main
quadlet: add support for the UpheldBy option in the Install section
2 parents eb99381 + a0cae65 commit d842b14

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

cmd/quadlet/main.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,18 @@ func generateServiceFile(service *parser.UnitFile) error {
449449
return nil
450450
}
451451

452+
func gatherDependentSymlinks(service *parser.UnitFile, key, dir, filename string) []string {
453+
symlinks := make([]string, 0)
454+
groupBy := service.LookupAllStrv(quadlet.InstallGroup, key)
455+
for _, groupByUnit := range groupBy {
456+
// Only allow filenames, not paths
457+
if !strings.Contains(groupByUnit, "/") {
458+
symlinks = append(symlinks, fmt.Sprintf("%s.%s/%s", groupByUnit, dir, filename))
459+
}
460+
}
461+
return symlinks
462+
}
463+
452464
// This parses the `Install` group of the unit file and creates the required
453465
// symlinks to get systemd to start the newly generated file as needed.
454466
// In a traditional setup this is done by "systemctl enable", but that doesn't
@@ -476,21 +488,9 @@ func enableServiceFile(outputPath string, service *parser.UnitFile) {
476488
}
477489

478490
if serviceFilename != "" {
479-
wantedBy := service.LookupAllStrv(quadlet.InstallGroup, "WantedBy")
480-
for _, wantedByUnit := range wantedBy {
481-
// Only allow filenames, not paths
482-
if !strings.Contains(wantedByUnit, "/") {
483-
symlinks = append(symlinks, fmt.Sprintf("%s.wants/%s", wantedByUnit, serviceFilename))
484-
}
485-
}
486-
487-
requiredBy := service.LookupAllStrv(quadlet.InstallGroup, "RequiredBy")
488-
for _, requiredByUnit := range requiredBy {
489-
// Only allow filenames, not paths
490-
if !strings.Contains(requiredByUnit, "/") {
491-
symlinks = append(symlinks, fmt.Sprintf("%s.requires/%s", requiredByUnit, serviceFilename))
492-
}
493-
}
491+
symlinks = append(symlinks, gatherDependentSymlinks(service, "WantedBy", "wants", serviceFilename)...)
492+
symlinks = append(symlinks, gatherDependentSymlinks(service, "RequiredBy", "requires", serviceFilename)...)
493+
symlinks = append(symlinks, gatherDependentSymlinks(service, "UpheldBy", "upholds", serviceFilename)...)
494494
}
495495

496496
for _, symlinkRel := range symlinks {

docs/source/markdown/podman-systemd.unit.5.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ For example, to start a container on boot, add something like this to the file:
129129
WantedBy=default.target
130130
```
131131

132-
Currently, only the `Alias`, `WantedBy` and `RequiredBy` keys are supported.
132+
Currently, only the `Alias`, `WantedBy`, `RequiredBy`, and `UpheldBy` keys are supported.
133133

134134
The Install section can be part of the main file, or it can be in a
135135
separate drop-in file as described above. The latter allows you to

test/e2e/quadlet/install.container

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
## assert-symlink req1.service.requires/install.service ../install.service
88
## assert-symlink req2.service.requires/install.service ../install.service
99
## assert-symlink req3.service.requires/install.service ../install.service
10+
## assert-symlink up1.service.upholds/install.service ../install.service
11+
## assert-symlink up2.service.upholds/install.service ../install.service
12+
## assert-symlink up3.service.upholds/install.service ../install.service
1013

1114
[Container]
1215
Image=localhost/imagename
@@ -19,3 +22,5 @@ WantedBy=want1.service want2.service
1922
WantedBy=want3.service
2023
RequiredBy=req1.service req2.service
2124
RequiredBy=req3.service
25+
UpheldBy=up1.service up2.service
26+
UpheldBy=up3.service

0 commit comments

Comments
 (0)