Skip to content

Commit 3ca4f3e

Browse files
committed
wait until runsv is reading from supervise/ok
If the supervise/ok pipe already exists on disk before runsv has started, then existence check here is not enough. Since runsv opens the pipe for reading as part of its startup, we can open it for writing which will block until runsv has called open. A version of this fix has been running in one of our internal projects for some time. Signed-off-by: Steven Danna <[email protected]>
1 parent 37290be commit 3ca4f3e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

libraries/helpers.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,21 @@ def delete_extra_env_files
5555
def wait_for_service
5656
raise 'Runit does not appear to be installed. Include runit::default before using the resource!' unless binary_exists?
5757

58-
sleep 1 until ::FileTest.pipe?(::File.join(service_dir_name, 'supervise', 'ok'))
58+
wait_for_pipe(::File.join(service_dir_name, 'supervise', 'ok'))
5959

6060
if new_resource.log
61-
sleep 1 until ::FileTest.pipe?(::File.join(service_dir_name, 'log', 'supervise', 'ok'))
61+
wait_for_pipe(::File.join(service_dir_name, 'log', 'supervise', 'ok'))
6262
end
6363
end
6464

65+
def wait_for_pipe(path)
66+
sleep 1 until ::FileTest.pipe?(path)
67+
68+
# Opening the pipe for writing should block until the supervisor
69+
# has opened it for reading.
70+
::File.open(path, "w").close()
71+
end
72+
6573
def runit_send_signal(signal, friendly_name = nil)
6674
friendly_name ||= signal
6775
converge_by("send #{friendly_name} to #{new_resource}") do

0 commit comments

Comments
 (0)