ActionCable on Production

Episode #3 by Teacher's Avatar David Kimura


Taking a look at ActionCable and switching from Puma to Thin. On server reboot, spin up the ActionCable service.
streaming rails websockets 6:13



# Gemfile
    gem 'actioncable', github: 'rails/actioncable'
    gem 'thin'
    gem 'whenever', :require => false

One thing that I neglected to mention is that you do need to write to your crontab once you have made your changes to the `schedule.rb` file. You can do this by running `whenever -w` in your application directory on the production machine.

# bash
    touch bin/cable
    chmod +x bin/cable

Change out the `puma` server startup script to `thin`

# bin/cable
    # /bin/bash
    bundle exec thin start -C config/cable.yml

Be sure to add the `thin` adapter to the Faye Websocket.

# cable/
    require ::File.expand_path('../../config/environment',  __FILE__)

    require 'action_cable/process/logging'
    run ActionCable.server

Create your `cable.yml` file and put the appropriate settings for your server.

# config/cable.yml
    chdir: /home/user/drifting_ruby
    environment: production
    port: 8443
    timeout: 30
    log: log/thin.log
    pid: tmp/pids/
    max_conns: 8192
    max_persistent_conns: 8192
    require: []
    wait: 30
    threadpool_size: 4
    servers: 1
    daemonize: true
    ssl: true
    ssl-disable-verify: true
    ssl_key_file: ssl/ssl.key
    ssl_cert_file: ssl/ssl.crt
    rackup: cable/

Some notes for installing Redis. These instructions work on Ubuntu 14.04, but may work on other Debian-based distributions.

# bash
    sudo apt-get update
    sudo apt-get install build-essential
    sudo apt-get install tcl8.5

    tar xzf redis-stable.tar.gz
    cd redis-stable
    make test
    sudo make install
    cd utils
    sudo ./

    sudo service redis_6379 start
    sudo service redis_6379 stop