Skip to content

Commit

Permalink
wait until runsv is reading from supervise/ok
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
stevendanna committed Aug 28, 2019
1 parent 37290be commit 3ca4f3e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,21 @@ def delete_extra_env_files
def wait_for_service
raise 'Runit does not appear to be installed. Include runit::default before using the resource!' unless binary_exists?

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

if new_resource.log
sleep 1 until ::FileTest.pipe?(::File.join(service_dir_name, 'log', 'supervise', 'ok'))
wait_for_pipe(::File.join(service_dir_name, 'log', 'supervise', 'ok'))
end
end

def wait_for_pipe(path)
sleep 1 until ::FileTest.pipe?(path)

# Opening the pipe for writing should block until the supervisor
# has opened it for reading.
::File.open(path, "w").close()
end

def runit_send_signal(signal, friendly_name = nil)
friendly_name ||= signal
converge_by("send #{friendly_name} to #{new_resource}") do
Expand Down

0 comments on commit 3ca4f3e

Please sign in to comment.