diff options
-rw-r--r-- | CHANGELOG.md | 5 | ||||
-rwxr-xr-x | ruby/bin/gitaly-ruby | 19 |
2 files changed, 16 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f206169d..6434baaf8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Gitaly changelog +UNRELEASED + +- gitaly-ruby shutdown improvements + https://gitlab.com/gitlab-org/gitaly/merge_requests/500 + v0.59.0 - Restart gitaly-ruby when it uses too much memory diff --git a/ruby/bin/gitaly-ruby b/ruby/bin/gitaly-ruby index 5bbec510e..6f69dabf5 100755 --- a/ruby/bin/gitaly-ruby +++ b/ruby/bin/gitaly-ruby @@ -6,6 +6,8 @@ require 'grpc' require_relative '../lib/gitaly_server.rb' +SHUTDOWN_TIMEOUT = 600 + def main if ARGV.length != 2 abort "Usage: #{$0} PPID /path/to/socket" @@ -14,42 +16,43 @@ def main ppid_i = ppid.to_i abort "invalid PPID: #{ppid.inspect}" unless ppid_i > 0 - start_parent_watcher(ppid_i) FileUtils.rm_f(socket_path) socket_dir = File.dirname(socket_path) FileUtils.mkdir_p(socket_dir) File.chmod(0700, socket_dir) - s = GRPC::RpcServer.new + s = GRPC::RpcServer.new(poll_period: SHUTDOWN_TIMEOUT) port = 'unix:' + socket_path s.add_http2_port(port, :this_port_is_insecure) GRPC.logger.info("... running insecurely on #{port}") GitalyServer.register_handlers(s) - wait_thread = Thread.new do + signal_thread = Thread.new do sleep end - trap('TERM') { wait_thread.kill } + trap('TERM') { signal_thread.kill } + start_parent_watcher(ppid_i, signal_thread) run_thread = Thread.new do s.run - wait_thread.kill + signal_thread.kill end - wait_thread.join + signal_thread.join s.stop run_thread.join end -def start_parent_watcher(original_ppid) +def start_parent_watcher(original_ppid, signal_thread) Thread.new do loop do if Process.ppid != original_ppid # Our original parent is gone. Self-terminate. - Process.kill(9, Process.pid) + signal_thread.kill + break end sleep 1 |