LoginSignup
3
3

More than 5 years have passed since last update.

upstartで管理するサービスの最大ファイルディスクリプタ数の設定

Last updated at Posted at 2015-11-15

はじめに

プログラムがファイルやソケットを作りすぎるとtoo many open fileのようなエラーが出て、最大ファイルディスクリプタ数を増やしたくなることがあります。
Linuxだとデフォルトが1024などの値になっていて、以下のようにulimitコマンドで増やしたりします。

# デフォルト値を確認
$ ulimit -n
1024

# 2048に増やす
$ ulimit -n 2048

これだとログアウトすると設定は残りません。
サービスごとにこれを設定したくなりますね。

upstartで管理するサービスの最大ファイルディスクリプタ数を設定する

ubuntuではupstartでサービスを管理することがありますが、その場合は /etc/init以下にあるスクリプトの中で以下のように記述をすると、そのサービスについて最大ファイルディスクリプタ数を設定できます。

description "test service"
start on startup
stop on shutdown
# set max file descriptors to 4096
limit nofile 4096 4096

script
/path/to/test/script
end script

limit nofileの行で指定してます。
ulimitで設定できる他の項目についても同様です。

参考:

なお、/etc/init.d/以下に起動スクリプトを置く場合には、その中でulimit -n 2048などとすればOKです。

3
3
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
3
3