@@ -254,10 +254,22 @@ func loadUnitDropins(unit *parser.UnitFile, sourcePaths []string) error {
254
254
prevError = err
255
255
}
256
256
257
- var dropinPaths = make (map [string ]string )
257
+ dropinDirs := []string {}
258
+
258
259
for _ , sourcePath := range sourcePaths {
259
- dropinDir := path .Join (sourcePath , unit .Filename + ".d" )
260
+ dropinDirs = append (dropinDirs , path .Join (sourcePath , unit .Filename + ".d" ))
261
+ }
260
262
263
+ // For instantiated templates, also look in the non-instanced template dropin dirs
264
+ templateBase , templateInstance := unit .GetTemplateParts ()
265
+ if templateBase != "" && templateInstance != "" {
266
+ for _ , sourcePath := range sourcePaths {
267
+ dropinDirs = append (dropinDirs , path .Join (sourcePath , templateBase + ".d" ))
268
+ }
269
+ }
270
+
271
+ var dropinPaths = make (map [string ]string )
272
+ for _ , dropinDir := range dropinDirs {
261
273
dropinFiles , err := os .ReadDir (dropinDir )
262
274
if err != nil {
263
275
if ! errors .Is (err , os .ErrNotExist ) {
@@ -345,19 +357,36 @@ func enableServiceFile(outputPath string, service *parser.UnitFile) {
345
357
symlinks = append (symlinks , filepath .Clean (alias ))
346
358
}
347
359
348
- wantedBy := service .LookupAllStrv (quadlet .InstallGroup , "WantedBy" )
349
- for _ , wantedByUnit := range wantedBy {
350
- // Only allow filenames, not paths
351
- if ! strings .Contains (wantedByUnit , "/" ) {
352
- symlinks = append (symlinks , fmt .Sprintf ("%s.wants/%s" , wantedByUnit , service .Filename ))
360
+ serviceFilename := service .Filename
361
+ templateBase , templateInstance := service .GetTemplateParts ()
362
+
363
+ // For non-instantiated template service we only support installs if a
364
+ // DefaultInstance is given. Otherwise we ignore the Install group, but
365
+ // it is still useful when instantiating the unit via a symlink.
366
+ if templateBase != "" && templateInstance == "" {
367
+ if defaultInstance , ok := service .Lookup (quadlet .InstallGroup , "DefaultInstance" ); ok {
368
+ parts := strings .SplitN (templateBase , "@" , 2 )
369
+ serviceFilename = parts [0 ] + "@" + defaultInstance + parts [1 ]
370
+ } else {
371
+ serviceFilename = ""
353
372
}
354
373
}
355
374
356
- requiredBy := service .LookupAllStrv (quadlet .InstallGroup , "RequiredBy" )
357
- for _ , requiredByUnit := range requiredBy {
358
- // Only allow filenames, not paths
359
- if ! strings .Contains (requiredByUnit , "/" ) {
360
- symlinks = append (symlinks , fmt .Sprintf ("%s.requires/%s" , requiredByUnit , service .Filename ))
375
+ if serviceFilename != "" {
376
+ wantedBy := service .LookupAllStrv (quadlet .InstallGroup , "WantedBy" )
377
+ for _ , wantedByUnit := range wantedBy {
378
+ // Only allow filenames, not paths
379
+ if ! strings .Contains (wantedByUnit , "/" ) {
380
+ symlinks = append (symlinks , fmt .Sprintf ("%s.wants/%s" , wantedByUnit , serviceFilename ))
381
+ }
382
+ }
383
+
384
+ requiredBy := service .LookupAllStrv (quadlet .InstallGroup , "RequiredBy" )
385
+ for _ , requiredByUnit := range requiredBy {
386
+ // Only allow filenames, not paths
387
+ if ! strings .Contains (requiredByUnit , "/" ) {
388
+ symlinks = append (symlinks , fmt .Sprintf ("%s.requires/%s" , requiredByUnit , serviceFilename ))
389
+ }
361
390
}
362
391
}
363
392
0 commit comments