Commit c4dc848a authored by Stan Hu's avatar Stan Hu

Provide more feedback in support/wait-postgresql-ready

We had multiple team members see their `gdk install` fail because psql
wasn't in the PATH or needed to be reinstalled due to readline updates
in their environment. The problem wasn't obvious because
wait-postgresql-ready quietly failed without indicating a reason.

To make this clearer, use `Popen.open3` instead of `system`. We now:

1. Fail hard with an exception if the psql binary doesn't exist
2. Show the last error message to give more feedback
parent 4666fe8c
#!/usr/bin/env ruby #!/usr/bin/env ruby
require 'open3'
PG_HOST = "#{Dir.pwd}/postgresql".freeze PG_HOST = "#{Dir.pwd}/postgresql".freeze
PG_PORT_FILE = File.join(Dir.pwd, 'postgresql_port') PG_PORT_FILE = File.join(Dir.pwd, 'postgresql_port')
PG_PORT = File.exist?(PG_PORT_FILE) ? : 5432 PG_PORT = File.exist?(PG_PORT_FILE) ? : 5432
...@@ -10,12 +12,24 @@ def main ...@@ -10,12 +12,24 @@ def main
end end
def pg_ready? def pg_ready?
last_error = nil
10.times do 10.times do
if system(*%W[psql -h #{PG_HOST} -d template1 -p #{PG_PORT} -c SELECT\ now()], out: '/dev/null', err: '/dev/null') stdin, stdout, stderr, thread = Open3.popen3(*%W[psql -h #{PG_HOST} -d template1 -p #{PG_PORT} -c SELECT\ now()])
last_error = stderr.readlines
exit_status = thread.value.to_i
return true return true
end end
sleep 1 sleep 1
end end
puts last_error
false false
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment