File tree 3 files changed +55
-2
lines changed
3 files changed +55
-2
lines changed Original file line number Diff line number Diff line change @@ -374,6 +374,7 @@ The following parameters are available in the `systemd::dropin_file` defined typ
374
374
* [ ` group ` ] ( #group )
375
375
* [ ` mode ` ] ( #mode )
376
376
* [ ` show_diff ` ] ( #show_diff )
377
+ * [ ` notify_service ` ] ( #notify_service )
377
378
* [ ` unit ` ] ( #unit )
378
379
* [ ` filename ` ] ( #filename )
379
380
* [ ` ensure ` ] ( #ensure )
@@ -462,6 +463,14 @@ Whether to show the diff when updating dropin file
462
463
463
464
Default value: `` true ``
464
465
466
+ ##### <a name =" notify_service " ></a >` notify_service `
467
+
468
+ Data type: ` Boolean `
469
+
470
+ Notify a service for the unit, if it exists
471
+
472
+ Default value: `` false ``
473
+
465
474
##### <a name =" unit " ></a >` unit `
466
475
467
476
Data type: ` Systemd::Unit `
Original file line number Diff line number Diff line change 40
40
# @param show_diff
41
41
# Whether to show the diff when updating dropin file
42
42
#
43
+ # @param notify_service
44
+ # Notify a service for the unit, if it exists
45
+ #
43
46
define systemd::dropin_file (
44
47
Systemd::Unit $unit ,
45
48
Systemd::Dropin $filename = $name,
53
56
String $group = ' root' ,
54
57
String $mode = ' 0444' ,
55
58
Boolean $show_diff = true ,
59
+ Boolean $notify_service = false ,
56
60
) {
57
61
include systemd
58
62
65
69
}
66
70
}
67
71
72
+ $full_filename = " ${path} /${unit} .d/${filename} "
73
+
68
74
if $ensure != ' absent' {
69
- ensure_resource(' file' , " ${path} / ${unit} .d " , {
75
+ ensure_resource(' file' , dirname( $full_filename ) , {
70
76
ensure => directory ,
71
77
owner => ' root' ,
72
78
group => ' root' ,
76
82
})
77
83
}
78
84
79
- file { "${path}/${unit}.d/${filename}" :
85
+ file { $full_filename :
80
86
ensure => $_ensure,
81
87
content => $content ,
82
88
source => $source ,
87
93
selinux_ignore_defaults => $selinux_ignore_defaults ,
88
94
show_diff => $show_diff ,
89
95
}
96
+
97
+ if $notify_service {
98
+ File [$full_filename ] ~> Service <| title == $unit or name == $unit |>
99
+ if $unit =~ /\.service$/ {
100
+ $short_service_name = regsubst($unit , /\.service$/, ' ' )
101
+ File [$full_filename ] ~> Service <| title == $short_service_name or name == $short_service_name |>
102
+ }
103
+ }
90
104
}
Original file line number Diff line number Diff line change 35
35
)
36
36
}
37
37
38
+ context 'notifies services' do
39
+ let ( :params ) do
40
+ super ( ) . merge ( notify_service : true )
41
+ end
42
+ let ( :filename ) { "/etc/systemd/system/#{ params [ :unit ] } .d/#{ title } " }
43
+ let ( :pre_condition ) do
44
+ <<-PUPPET
45
+ service { ['test', 'test.service']:
46
+ }
47
+ PUPPET
48
+ end
49
+
50
+ it { is_expected . to compile . with_all_deps }
51
+ it { is_expected . to contain_service ( 'test' ) . that_subscribes_to ( "File[#{ filename } ]" ) }
52
+ it { is_expected . to contain_service ( 'test.service' ) . that_subscribes_to ( "File[#{ filename } ]" ) }
53
+
54
+ context 'with overridden name' do
55
+ let ( :pre_condition ) do
56
+ <<-PUPPET
57
+ service { 'myservice':
58
+ name => 'test',
59
+ }
60
+ PUPPET
61
+ end
62
+
63
+ it { is_expected . to compile . with_all_deps }
64
+ it { is_expected . to contain_service ( 'myservice' ) . that_subscribes_to ( "File[#{ filename } ]" ) }
65
+ end
66
+ end
67
+
38
68
context 'with selinux_ignore_defaults set to true' do
39
69
let ( :params ) do
40
70
super ( ) . merge ( selinux_ignore_defaults : true )
You can’t perform that action at this time.
0 commit comments