#3 ActionCable on Production

Summary

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

Resources

Summary

# 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/config.ru
    require ::File.expand_path('../../config/environment',  __FILE__)
    Rails.application.eager_load!

    require 'action_cable/process/logging'
    Faye::WebSocket.load_adapter('thin')
    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/thin.pid
    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/config.ru

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

    wget http://download.redis.io/releases/redis-stable.tar.gz
    tar xzf redis-stable.tar.gz
    cd redis-stable
    make
    make test
    sudo make install
    cd utils
    sudo ./install_server.sh

    sudo service redis_6379 start
    sudo service redis_6379 stop