Skip to content

Commit

Permalink
fix for docker_service not containing a listening socket
Browse files Browse the repository at this point in the history
Signed-off-by: Chase Bolt <[email protected]>
  • Loading branch information
chasebolt committed Aug 4, 2017
1 parent 021080e commit 5262ae1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
10 changes: 7 additions & 3 deletions libraries/docker_service_manager_systemd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ class DockerServiceManagerSystemd < DockerServiceBase
variables(
config: new_resource,
docker_name: docker_name,
docker_socket: connect_socket.sub(%r{unix://|fd://}, '')
docker_socket: connect_socket
)
action connect_socket.nil? ? :delete : :create
not_if { docker_name == 'default' && ::File.exist?('/lib/systemd/system/docker.socket') }
end

Expand All @@ -43,7 +44,8 @@ class DockerServiceManagerSystemd < DockerServiceBase
mode '0644'
variables(
docker_name: docker_name,
docker_daemon_cmd: docker_daemon_cmd
docker_daemon_cmd: docker_daemon_cmd,
docker_socket: connect_socket
)
not_if { docker_name == 'default' && ::File.exist?('/lib/systemd/system/docker.service') }
end
Expand All @@ -58,8 +60,9 @@ class DockerServiceManagerSystemd < DockerServiceBase
variables(
config: new_resource,
docker_name: docker_name,
docker_socket: connect_socket.sub(%r{unix://|fd://}, '')
docker_socket: connect_socket
)
action connect_socket.nil? ? :delete : :create
end

# this overrides the main systemd service
Expand All @@ -72,6 +75,7 @@ class DockerServiceManagerSystemd < DockerServiceBase
variables(
config: new_resource,
docker_name: docker_name,
docker_socket: connect_socket,
docker_daemon_cmd: docker_daemon_cmd,
systemd_args: systemd_args,
docker_wait_ready: "#{libexec_dir}/#{docker_name}-wait-ready"
Expand Down
2 changes: 1 addition & 1 deletion libraries/docker_service_manager_upstart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DockerServiceManagerUpstart < DockerServiceBase
docker_daemon_cmd: [dockerd_bin_link, docker_daemon_arg, docker_daemon_opts].join(' '),
docker_raw_logs_arg: docker_raw_logs_arg,
docker_wait_ready: "#{libexec_dir}/#{docker_name}-wait-ready",
docker_socket: connect_socket.sub(%r{unix://|fd://}, '')
docker_socket: connect_socket
)
notifies :restart, "service[#{docker_name}]", :immediately
end
Expand Down
3 changes: 2 additions & 1 deletion libraries/helpers_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def connect_host

def connect_socket
return "/var/run/#{docker_name}.sock" unless host
return nil if host.grep(%r{unix://|fd://}).empty?
sorted = coerce_host(host).sort do |a, b|
c_a = 1 if a =~ /^unix:/
c_a = 2 if a =~ /^fd:/
Expand All @@ -85,7 +86,7 @@ def connect_socket
c_b = 3 unless c_b
c_a <=> c_b
end
sorted.first
sorted.first.sub(%r{unix://|fd://}, '')
end

def coerce_host(v)
Expand Down
6 changes: 5 additions & 1 deletion templates/default/systemd/docker.service-override.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
<% if @docker_socket.nil? %>
After=network-online.target firewalld.service
<% else %>
After=network-online.target <%= @docker_name %>.socket firewalld.service
Wants=network-online.target
Requires=<%= @docker_name %>.socket
<% end %>
Wants=network-online.target

[Service]
Type=notify
Expand Down
6 changes: 5 additions & 1 deletion templates/default/systemd/docker.service.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
<% if @docker_socket.nil? %>
After=network-online.target firewalld.service
<% else %>
After=network-online.target <%= @docker_name %>.socket firewalld.service
Wants=network-online.target
Requires=<%= @docker_name %>.socket
<% end %>
Wants=network-online.target

[Service]
Type=notify
Expand Down

0 comments on commit 5262ae1

Please sign in to comment.