diff options
author | Ahmad Sherif <ahmad.m.sherif@gmail.com> | 2017-08-07 17:04:23 +0300 |
---|---|---|
committer | Ahmad Sherif <ahmad.m.sherif@gmail.com> | 2017-08-07 17:04:23 +0300 |
commit | 4be20e07c4aaa10ca79b480b83c3a5c1f84a3600 (patch) | |
tree | 2f5cdbf1cc0f3b81c9a466842a7956b0823721b3 | |
parent | ca9c06ab33dc8af4fd32e62f7580956cf8e518a6 (diff) | |
parent | ca9409255712e45e81737c304ea05447da80c89a (diff) |
Merge branch 'ppid-watcher' into 'master'
Don't count on PID 1 to be the reaper
Closes gitlab-ce#35982
See merge request !270
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | internal/rubyserver/rubyserver.go | 3 | ||||
-rwxr-xr-x | ruby/bin/gitaly-ruby | 16 |
3 files changed, 13 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 083487970..a4e8111aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ UNRELEASED - Add GitLab-Shell Path to config https://gitlab.com/gitlab-org/gitaly/merge_requests/267 +- Don't count on PID 1 to be the reaper + https://gitlab.com/gitlab-org/gitaly/merge_requests/270 v0.28.0 diff --git a/internal/rubyserver/rubyserver.go b/internal/rubyserver/rubyserver.go index aff482bb6..558ce174c 100644 --- a/internal/rubyserver/rubyserver.go +++ b/internal/rubyserver/rubyserver.go @@ -1,6 +1,7 @@ package rubyserver import ( + "fmt" "io/ioutil" "net" "os" @@ -59,7 +60,7 @@ func prepareSocketPath() { func Start() (*supervisor.Process, error) { lazyInit.Do(prepareSocketPath) - args := []string{"bundle", "exec", "bin/gitaly-ruby", socketPath} + args := []string{"bundle", "exec", "bin/gitaly-ruby", fmt.Sprintf("%d", os.Getpid()), socketPath} return supervisor.New(nil, args, config.Config.Ruby.Dir) } diff --git a/ruby/bin/gitaly-ruby b/ruby/bin/gitaly-ruby index 184610e5b..8b486601e 100755 --- a/ruby/bin/gitaly-ruby +++ b/ruby/bin/gitaly-ruby @@ -7,13 +7,15 @@ require 'grpc' require_relative '../lib/gitaly_server.rb' def main - if ARGV.length != 1 - abort "Usage: #{$0} /path/to/socket" + if ARGV.length != 2 + abort "Usage: #{$0} PPID /path/to/socket" end + ppid, socket_path = ARGV - start_parent_watcher + ppid_i = ppid.to_i + abort "invalid PPID: #{ppid.inspect}" unless ppid_i > 0 + start_parent_watcher(ppid_i) - socket_path = ARGV.first FileUtils.rm_f(socket_path) socket_dir = File.dirname(socket_path) FileUtils.mkdir_p(socket_dir) @@ -29,11 +31,11 @@ def main s.run_till_terminated end -def start_parent_watcher +def start_parent_watcher(original_ppid) Thread.new do loop do - if Process.ppid == 1 - # If our parent is PID 1, our original parent is gone. Self-terminate. + if Process.ppid != original_ppid + # Our original parent is gone. Self-terminate. Process.kill(9, Process.pid) end |