Skip to content

Commit

Permalink
Fixes #30252: Make wait for port more resilient
Browse files Browse the repository at this point in the history
The current method can result in journal error messages:

[System] error Error reading socket: Encountered end of file [-5938]

This updated version waits and checks for listening ports
and greps for the port in question to appear before signaling
that the service is ready.
  • Loading branch information
ehelms committed Nov 17, 2020
1 parent 68f944c commit 57b9a12
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions manifests/service.pp
Expand Up @@ -34,8 +34,8 @@
}

if $qpid::ssl {
ensure_packages(['nc'])
Package['nc'] -> Systemd::Dropin_file['wait-for-port.conf']
ensure_packages(['iproute'])
Package['iproute'] -> Systemd::Dropin_file['wait-for-port.conf']
}
}
}
6 changes: 3 additions & 3 deletions spec/classes/qpid_spec.rb
Expand Up @@ -121,12 +121,12 @@
is_expected.to contain_systemd__dropin_file('wait-for-port.conf')
.with_ensure('present')
.that_notifies('Service[qpidd]')
.that_requires('Package[nc]')
is_expected.to contain_package('nc')
.that_requires('Package[iproute]')
is_expected.to contain_package('iproute')
.with_ensure('present')
verify_exact_contents(catalogue, '/etc/systemd/system/qpidd.service.d/wait-for-port.conf', [
"[Service]",
"ExecStartPost=/bin/bash -c 'while ! nc -z localhost 5671; do sleep 1; done'"
"ExecStartPost=/bin/bash -c 'while ! ss --no-header --tcp --listening --numeric sport = :5671 | grep -q \"^LISTEN.*:5671\"; do sleep 1; done'"
])
end
end
Expand Down
2 changes: 1 addition & 1 deletion templates/wait-for-port.conf.erb
@@ -1,2 +1,2 @@
[Service]
ExecStartPost=/bin/bash -c 'while ! nc -z localhost <%= scope['qpid::ssl_port'] %>; do sleep 1; done'
ExecStartPost=/bin/bash -c 'while ! ss --no-header --tcp --listening --numeric sport = :<%= scope['qpid::ssl_port'] %> | grep -q "^LISTEN.*:<%= scope['qpid::ssl_port'] %>"; do sleep 1; done'

0 comments on commit 57b9a12

Please sign in to comment.