2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

特定インスタンスのUnit定義を上書きする

Last updated at Posted at 2019-04-21

TL;DR

/etc/systemd/system/template_name@instance_name.service.d/xxxx.confを作成すればよい。

検証

CentOS 7.xではsystemd管理のデーモンについてlimitsを上書きする場合には/etc/systemd/system/service_name.service.d/custom.confを作成すればよい1が、Tomcat8のマルチインスタンス化のようにテンプレートUnitを利用してインスタンス化した際、インスタンス毎にUnit定義を変更したい場合どうするかが気になったので検証。

  • 対象: systemd-219-62.el7.x86_642

設定

設定変更前の状態は以下の通り。

# grep -e 'Max processes' -e 'Max open files' /proc/$(head -n1 /run/tomcat/tomcats-svr00.pid)/limits
Max processes             31227                31227                processes
Max open files            4096                 4096                 files
# grep -e 'Max processes' -e 'Max open files' /proc/$(head -n1 /run/tomcat/tomcats-svr01.pid)/limits
Max processes             31227                31227                processes
Max open files            4096                 4096                 files

RPMデフォルトでテンプレートUnitが定義されていた場合のカスタマイズも確認する意味で以下の設定ファイルを配置。

/etc/systemd/system/tomcats@.service.d/limits.conf
[Service]
LimitNOFILE=8192
LimitNPROC=8192
/etc/systemd/system/tomcats@svr00.service.d/limits.conf
[Service]
LimitNOFILE=65536
LimitNPROC=65536

systemdに読み込ませてそれぞれのインスタンスを再起動。

# systemctl daemon-reload
# systemctl restart tomcats@svr00.service tomcats@svr01.service

確認

svr00は/etc/systemd/system/tomcats@svr00.service.d/limits.confの設定が反映されている。

# systemctl show tomcats@svr00.service | grep -e LimitNOFILE -e LimitNPROC
LimitNOFILE=65536
LimitNPROC=65536
# grep -e 'Max processes' -e 'Max open files' /proc/$(head -n1 /run/tomcat/tomcats-svr00.pid)/limits
Max processes             65536                65536                processes
Max open files            65536                65536                files

svr01は/etc/systemd/system/tomcats@.service.d/limits.confの設定が反映されている。

# systemctl show tomcats@svr01.service | grep -e LimitNOFILE -e LimitNPROC
LimitNOFILE=8192
LimitNPROC=8192
# grep -e 'Max processes' -e 'Max open files' /proc/$(head -n1 /run/tomcat/tomcats-svr01.pid)/limits
Max processes             8192                 8192                 processes
Max open files            8192                 8192                 files

再起動しても上記の設定は維持されることを確認。

備考

systemd-deltaとかで上書き状況を確認できるらしい。が、インスタンス用のはリストされなかった。残念。

# systemd-delta | grep tomcat
[EXTENDED]   /etc/systemd/system/tomcats@.service → /etc/systemd/system/tomcats@.service.d/limits.conf
  1. systemd時代に困らないためのlimits設定とかを参照

  2. systemdのバージョンが古いとLimitNOFILEの設定は効かないので注意 BZ - 1351415

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?