Search code examples
ruby-on-railsruby-on-rails-4daemon

root path issues when server is run as a daemon


i have several views, as well as some gems, that access the filesystem. this seems to work fine until i run the server as a daemon. rails (4.2.3)

for example in one of my views I access the README file in the root of the app

File.read('README.md')

when running as a daemon, i get the error No such file or directory @ rb_sysopen - README.md

the error page shows the Rails.root path, which is correct. i CAN fix this problem by doing:

File.read("#{Rails.root}/README.md")

however this issue breaks more than just my views. It would seem an issue with the rails server.


Solution

  • This is how daemonized process works - chdir to / or another working directory. Some programs allow you to specify working directory for daemon process. For example puma server uses current directory by default so it might work for you.