alphagov/sidekiq-monitoring — pull request #5 by vinayvinay (2014-09-11 07:48:30+00:00)
Title: Fix process term for sidekiq-monitoring rackups

www.agileplannerapp.com/boards/173808/cards/5827

earlier, on receiving TERM foreman terminated a single master process, and left child processes dangling. this caused failure to restart `rackup` after a deploy, as foreman restarted, and dangling `rackup` blocked ports.

##### earlier
```sh
17366 pts/1 Sl+ 0:00 \_ foreman: master
17388 pts/1 S+ 0:00 \_ sh -c /usr/lib/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/foreman-0.63.0/bin/foreman-runner -d '/var/govuk/sidekiq-monitoring' -p -- sh -c 'cd publisher && bun
17389 pts/1 S+ 0:00 | \_ sh -c cd publisher && bundle exec rackup -p 3079
17392 pts/1 Sl+ 0:01 | \_ ruby /usr/lib/rbenv/versions/2.0.0-p353/bin/rackup -p 3079
17390 pts/1 S+ 0:00 \_ sh -c /usr/lib/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/foreman-0.63.0/bin/foreman-runner -d '/var/govuk/sidekiq-monitoring' -p -- sh -c 'cd signon && bundle
17393 pts/1 S+ 0:00 | \_ sh -c cd signon && bundle exec rackup -p 3080
17398 pts/1 Sl+ 0:01 | \_ ruby /usr/lib/rbenv/versions/2.0.0-p353/bin/rackup -p 3080
17391 pts/1 S+ 0:00 \_ sh -c /usr/lib/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/foreman-0.63.0/bin/foreman-runner -d '/var/govuk/sidekiq-monitoring' -p -- sh -c 'cd whitehall && bun
17395 pts/1 S+ 0:00 | \_ sh -c cd whitehall && bundle exec rackup -p 3081
17400 pts/1 Sl+ 0:01 | \_ ruby /usr/lib/rbenv/versions/2.0.0-p353/bin/rackup -p 3081
17394 pts/1 S+ 0:00 \_ sh -c /usr/lib/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/foreman-0.63.0/bin/foreman-runner -d '/var/govuk/sidekiq-monitoring' -p -- sh -c 'cd transition && bu
17397 pts/1 S+ 0:00 \_ sh -c cd transition && bundle exec rackup -p 3086
17402 pts/1 Sl+ 0:01 \_ ruby /usr/lib/rbenv/versions/2.0.0-p353/bin/rackup -p 3086

$ kill -15 17366
17658 pts/1 S 0:00 sh -c cd transition && bundle exec rackup -p 3086
17659 pts/1 Sl 0:01 \_ ruby /usr/lib/rbenv/versions/2.0.0-p353/bin/rackup -p 3086
17655 pts/1 S 0:00 sh -c cd whitehall && bundle exec rackup -p 3081
17657 pts/1 Sl 0:01 \_ ruby /usr/lib/rbenv/versions/2.0.0-p353/bin/rackup -p 3081
17649 pts/1 S 0:00 sh -c cd signon && bundle exec rackup -p 3080
17651 pts/1 Sl 0:01 \_ ruby /usr/lib/rbenv/versions/2.0.0-p353/bin/rackup -p 3080
17646 pts/1 S 0:00 sh -c cd publisher && bundle exec rackup -p 3079
17648 pts/1 Sl 0:01 \_ ruby /usr/lib/rbenv/versions/2.0.0-p353/bin/rackup -p 3079
```

[foreman 0.65.0](https://github.com/ddollar/foreman/blob/master/Changelog.md#0650-2014-04-23) fixed this issue by running the command with exec, and ensured that child processes were asked to TERM when the master process received a TERM: https://github.com/ddollar/foreman/pull/428

hat tip to @alext, for suggesting that we need to run `exec bundle exec`. foreman's exec wrapping only takes care of executing `cd` replacing the current process and `bundle exec` would still create a child process.

##### now
```sh
17509 pts/1 Sl+ 0:00 \_ foreman: master
17533 pts/1 Sl+ 0:01 \_ ruby /usr/lib/rbenv/versions/2.0.0-p353/bin/rackup -p 3079
17534 pts/1 Sl+ 0:01 \_ ruby /usr/lib/rbenv/versions/2.0.0-p353/bin/rackup -p 3080
17535 pts/1 Sl+ 0:01 \_ ruby /usr/lib/rbenv/versions/2.0.0-p353/bin/rackup -p 3081
17538 pts/1 Sl+ 0:01 \_ ruby /usr/lib/rbenv/versions/2.0.0-p353/bin/rackup -p 3086
```