Can a Rails 5 application with ActionCable be deployed on Windows?
Asked Answered
D

1

2

I have a Rails 5 application which I was planning to deploy on Linux, but because we needed some access very specific Windows-only software, I need to deploy it on Windows Server 2012 R2. My software stack (or mix) was supposed to be Nginx/Puma/Rails/PostgreSQL/Redis. Everything installs for me on Windows except Puma, and the Rails documentation says that I need Puma for ActionCable.

How do I get Puma to run on Windows? I have seen and tried snippets of things to try, and I have also seen and tried snippets on what not to do, such as running in daemon mode because fork() is not supported. Does anybody have a repeatable set of instructions on how to get Puma to work on Windows with a Rails application?

Or, if Puma a non-starter for Windows, is there a repeatable alternative for deploying a Rails 5 application with ActionCable to a Windows Server host (e.g. Windows 2012 R2)?

Decoration answered 12/8, 2016 at 15:16 Comment(0)
L
1

According to the readme file from the github page, following things to keep in mind:

  • daemon mode is not supported. so comment out/remove the following, if there is such line.

    daemonize false
    
  • Workers do not work in Windows since it does not support processes. We want the workers to be "0". So comment out following lines:

    workers 2        # The default is "0"
    preload_app!
    
  • server sockets are not seamless on restart, they must be closed and reopened. These platforms have no way to pass descriptors into a new process that is exposed to ruby.

  • Do not use unix socket, instead bind the server to "tcp://". So comment out any line that looks like following:

    bind 'unix:///var/run/puma.sock'
    bind 'unix:///var/run/puma.sock?umask=0111'
    

    Instead use following:

    bind "tcp://127.0.0.1:4001"
    # You don't have to if you don't need to specify a port 
    # since the default is "tcp://0.0.0.0:9292"
    
  • If you see any http parse error (malformed http request) after starting rails server, try this answer. If it doesn't work, then comment out this line from config/environments/production.rb or config/environments/production.rb (depending on which environment you want to run Puma)

    config.force_ssl = true
    

Here is what the puma.rb file might look like:

worker 0     # Not necessary. The default is "0"    

threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i
threads threads_count, threads_count

bind "tcp://127.0.0.1:4001"    # Not necessary. Default is "tcp://0.0.0.0:9292"

environment ENV.fetch("RAILS_ENV") { "development" }

plugin :tmp_restart

Finally run bundle exec puma -C config\puma.rb and it should work.

Lecompte answered 15/8, 2016 at 17:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.