Docker コンテナ内で Discourse の nginx サービスを再起動する方法は?

Discourse Docker コンテナ内で nginx を再起動する正しい方法はありますか?

Docker コンテナは Debian 10 で動作しているようですが、通常の systemd を使った nginx の再起動は失敗します。

[root@osestaging1 discourse]# ./launcher enter discourse_ose
root@osestaging1-discourse-ose:/var/www/discourse# cat /etc/issue
Debian GNU/Linux 10 \n \l

root@osestaging1-discourse-ose:/var/www/discourse# systemctl restart nginx
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
root@osestaging1-discourse-ose:/var/www/discourse# 

init.d スクリプトがあるようですが、実行しても失敗します。ログを見ると、アドレスが既に使用されているためバインドできないことが原因のようです。

root@osestaging1-discourse-ose:/etc/nginx/conf.d# /etc/init.d/nginx restart
[FAIL] Restarting nginx: nginx failed!
root@osestaging1-discourse-ose:/etc/nginx/conf.d# tail /var/log/nginx/error.log
2019/11/12 10:32:45 [emerg] 1123#1123: bind() to unix:/shared/nginx.http.sock failed (98: Address already in use)
2019/11/12 10:32:45 [emerg] 1123#1123: bind() to unix:/shared/nginx.http.sock failed (98: Address already in use)
2019/11/12 10:32:45 [emerg] 1123#1123: bind() to unix:/shared/nginx.http.sock failed (98: Address already in use)
2019/11/12 10:32:45 [emerg] 1123#1123: bind() to unix:/shared/nginx.http.sock failed (98: Address already in use)
2019/11/12 10:32:45 [emerg] 1123#1123: bind() to unix:/shared/nginx.http.sock failed (98: Address already in use)
2019/11/12 10:32:45 [emerg] 1123#1123: still could not bind()
2019/11/12 10:32:47 [emerg] 1127#1127: bind() to unix:/shared/nginx.http.sock failed (98: Address already in use)
2019/11/12 10:32:47 [emerg] 1127#1127: bind() to unix:/shared/nginx.http.sock failed (98: Address already in use)
2019/11/12 10:32:47 [emerg] 1127#1127: bind() to unix:/shared/nginx.http.sock failed (98: Address already in use)
2019/11/12 10:32:47 [emerg] 1127#1127: bind() to unix:/shared/nginx.http.sock failed (98: Address already in use)

実際、nginx は既に実行されています。

root@osestaging1-discourse-ose:/etc/nginx/conf.d# ps -ef | grep -i nginx
root        46    40  0 10:19 ?        00:00:00 runsv nginx
root      1174    46  1 10:33 ?        00:00:00 /usr/sbin/nginx
root      1177   108  0 10:33 pts/1    00:00:00 grep -i nginx
root@osestaging1-discourse-ose:/etc/nginx/conf.d# 

上記の nginx プロセスを適切に終了し、再度起動するにはどうすればよいでしょうか?

Discourse Docker コンテナ内で nginx を再起動する正しい方法は、runit サービススーパーバイザーの一部である sv コマンドを使用することです。

root@osestaging1-discourse-ose:/var/www/discourse# sv stop nginx
ok: down: nginx: 1s, normally up
root@osestaging1-discourse-ose:/var/www/discourse# sv start nginx
ok: run: nginx: (pid 269) 0s
root@osestaging1-discourse-ose:/var/www/discourse# 

つまり、Ruby on Rails は runit を使用しているようです。

sv コマンドは、templates/web.template.yml ファイル で参照されているため、それを見つけました。

少し違います… Ruby on Rails は、使用する仕組みについて非依存です。systemd、Docker 内の単純な pid 1、あるいは無数の他のツールを使い分けることができます。

公式の Docker イメージで runit を採用したのは、軽量で動作の理解が容易だからです。これは、とにかくうまく機能するツールです。