LoginSignup
6
2

More than 5 years have passed since last update.

多数ゲストOS上のrails serverでToo many open filesエラーが出たときの対処

Last updated at Posted at 2017-07-25

ホスト上に、仮想化などして多数のRails Serverを起動しようとすると、以下のようなエラーがでることがある。

# rails s

/root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rb-inotify-0.9.8/lib/rb-inotify/notifier.rb:58:in `initialize': Too many open files - Failed to initialize inotify: the user limit on the total number of inotify instances has been reached. (Errno::EMFILE)
    from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/listen-3.0.8/lib/listen/adapter/linux.rb:31:in `new'
    from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/listen-3.0.8/lib/listen/adapter/linux.rb:31:in `_configure'
    (以下略)

/rb-inotify/notifier.rb で上限以上のファイルを開いているということなので、上限の設定を変更する。
例えば

# cat /proc/sys/fs/inotify/max_user_instances
128

とかだとしたら、

# echo 256 > /proc/sys/fs/inotify/max_user_instances

などとしてみる。

これでrails sを試して、成功したらいちいち上記の変更を行わずに済むように/etc/sysctl.confに以下を追記する。

# echo fs.inotify.max_user_instances = 256 >> /etc/sysctl.conf
6
2
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
6
2