11. サービスが止まらない? 罠(1)
● OpenSource なので自前でなんとかする
--- a/registrator.go
+++ b/registrator.go
@@ -172,6 +172,10 @@ func main() {
go b.Add(msg.ID)
case "die":
go b.RemoveOnExit(msg.ID)
+ case "kill":
+ if signal, ok := msg.Actor.Attributes["signal"]; ok && signal == "15" {
+ go b.RemoveOnExit(msg.ID)
+ }
}
}
12. サービスが止まらない? 罠(2)
● コンテナの停止処理
● SIGTERM で良いの?
unicorn の場合
○ INT/TERM
■ quick shutdown, kills all workers immediately
○ QUIT
■ graceful shutdown, waits for workers to finish their current request before finishing.
● SIGQUIT が正解
● nginx も QUIT が Graceful shutdown
● 使うソフトウェアに合わせましょう、signal だけじゃないかも
13. サービスが止まらない? 罠(2)
● SIGQUIT を送るには?
● dumb-init https://github.com/Yelp/dumb-init には Signal rewriting 機能がある
○ For example, to rewrite the signal SIGTERM (number 15) to SIGQUIT (number 3), just add
--rewrite 15:3 on the command line.
● まさにコレ!!
● ENTRYPOINT [ “/dumb-init”, “-r”, “15:3”, “--” ]
CMD [ “...”, “...” ]