How to daemonize Peatio with rails server?


I’m trying to run Peatio on boot but running the app as a daemon like so rails s -d, in a development environment, gives:

Errno::ENOENT in Private::MarketsController#show
No such file or directory @ rb_sysopen - app/views/private/markets/show.json.jbuilder
Extracted source (around line #32):
31      set_member_data if current_user
32      gon.jbuilder
33      render json: trading_ui_variables
34    end

And in production I simply get 500 Internal Server Error

It seems related to this issue.


The issue has to do with the working directory not being set properly when the app is running in daemon mode. A workaround is to chdir to the root directory of the application in set_gon like so:


def set_gon
  Dir.chdir(defined?(::Rails) ? ::Rails.root : Dir.pwd)
  gon.environment = Rails.env
  # ...