@@ -449,6 +449,18 @@ func generateServiceFile(service *parser.UnitFile) error {
449
449
return nil
450
450
}
451
451
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
+
452
464
// This parses the `Install` group of the unit file and creates the required
453
465
// symlinks to get systemd to start the newly generated file as needed.
454
466
// 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) {
476
488
}
477
489
478
490
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 )... )
494
494
}
495
495
496
496
for _ , symlinkRel := range symlinks {
0 commit comments