Skip to content

Commit 3690107

Browse files
jameslikeslinuxdavejrt
authored andcommitted
docker::run: Support depend_services with full systemd unit names (#383)
To support depending non-service systemd unit types, the docker-run service template was modified to detect when a full systemd unit name is passed. This allows you to depend on targets like 'remote-fs.target' or 'network-online.target' if the container needs it.
1 parent fc67e28 commit 3690107

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

spec/defines/run_spec.rb

+10
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@
9595
it { should contain_file(initscript).with_content(/After=(.*\s+)?bar.service/) }
9696
it { should contain_file(initscript).with_content(/Requires=(.*\s+)?foo.service/) }
9797
it { should contain_file(initscript).with_content(/Requires=(.*\s+)?bar.service/) }
98+
99+
context 'with full systemd unit names' do
100+
let(:params) { {'command' => 'command', 'image' => 'base', 'depend_services' => ['foo', 'bar.service', 'baz.target']} }
101+
it { should contain_file(initscript).with_content(/After=(.*\s+)?foo.service(\s+|$)/) }
102+
it { should contain_file(initscript).with_content(/After=(.*\s+)?bar.service(\s+|$)/) }
103+
it { should contain_file(initscript).with_content(/After=(.*\s+)?baz.target(\s+|$)/) }
104+
it { should contain_file(initscript).with_content(/Requires=(.*\s+)?foo.service(\s+|$)/) }
105+
it { should contain_file(initscript).with_content(/Requires=(.*\s+)?bar.service(\s+|$)/) }
106+
it { should contain_file(initscript).with_content(/Requires=(.*\s+)?baz.target(\s+|$)/) }
107+
end
98108
else
99109
it { should contain_file(initscript).with_content(/Required-Start:.*\s+foo/) }
100110
it { should contain_file(initscript).with_content(/Required-Start:.*\s+bar/) }

templates/etc/systemd/system/docker-run.erb

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<%-
2+
depend_services = @depend_services_array.map{|s| s =~ /\.[a-z]+$/ ? s : "#{s}.service"}
23
@after = [@service_name+".service"] +
34
@sanitised_after_array.map{ |s| "#{@service_prefix}#{s}.service"} +
45
@sanitised_depends_array.map{ |s| "#{@service_prefix}#{s}.service"} +
5-
@depend_services_array.map{|s| "#{s}.service"}
6+
depend_services
67
@wants = @sanitised_after_array.map{ |a| "#{@service_prefix}#{a}.service"}
78
@requires = [@service_name+".service"] +
89
@sanitised_depends_array.map{ |d| "#{@service_prefix}#{d}.service"} +
9-
@depend_services_array.map{|s| "#{s}.service"}
10+
depend_services
1011
-%>
1112
# This file is managed by Puppet and local changes
1213
# may be overwritten

0 commit comments

Comments
 (0)