Інсталюємо GO
1 2 3 |
sudo add-apt-repository ppa:longsleep/golang-backports sudo apt-get update sudo apt-get install golang-go |
Інсталюємо Anycable-go
1 |
go get -u -f github.com/anycable/anycable-go |
За звичай go інсталюється або в ~./go або в /usr/local/go.
інсталюємо Redis сервер
1 |
sudo apt install redis-server |
Додаємо(вносимо зміни) в наступні файли
Gemfile
1 |
gem 'anycable-rails' |
1 2 |
bundle install rails generate anycable |
config/anycable.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
production: # gRPC server host rpc_host: "localhost:50051" # Redis URL (for broadcasting) redis_url: "redis://localhost:6379/2" # Redis channel name redis_channel: "anycable" development: # gRPC server host rpc_host: "localhost:50051" # Redis URL (for broadcasting) redis_url: "redis://localhost:6379/2" # Redis channel name redis_channel: "anycable" |
config/application.rb
1 2 3 4 |
if Anycable.config.debug config.logger = Logger.new(STDOUT) config.log_level = :debug end |
config/environments/development.rb та config/environments/production.rb
1 2 3 4 5 |
Rails.application.configure do ... config.action_cable.url = "ws://localhost:3334/cable" ... end |
Запускаємо в папці з проектом
1 |
./bin/anycable |
та
1 |
./bin/anycable-go -rpc=0.0.0.0:50051 -headers=cookie,x-api-token -redis=redis://localhost:6379/5 -redis_channel=anycable -addr=0.0.0.0:3334 -log |
Для автоматизації запуску anycable та anycable-go використаємо systemd
Створюємо два файли
/etc/systemd/system/anycable.service
1 2 3 4 5 6 7 8 9 10 11 12 |
[Unit] Description = anycable-rails Wants=redis.service [Service] Type=simple PIDFile=/var/run/anycable-rails.pid WorkingDirectory=/home/hekimtap/app ExecStart=/home/hekimtap/app/bin/anycable TimeoutSec=300 [Install] WantedBy=multi-user.target |
/etc/systemd/system/anycable-go.service
1 2 3 4 5 6 7 8 9 10 11 12 |
[Unit] Description = anycable-go Wants=redis.service [Service] Type=simple PIDFile=/var/run/anycable-go.pid WorkingDirectory=/usr/local/go/bin/bin/ ExecStart=/usr/local/go/bin/bin/anycable-go -rpc=0.0.0.0:50051 -headers=cookie,x-api-token -redis=redis://localhost:6379/5 -redis_channel=anycable -addr=0.0.0.0:3334 -log TimeoutSec=300 [Install] WantedBy=multi-user.target |
Також потрібно модифікува bin/anycable вказавши повний шлях замість відносного
1 2 3 4 5 6 7 8 9 10 11 |
#!/usr/bin/env /home/hekimtap/.rbenv/shims/ruby # frozen_string_literal: true require ::File.expand_path('/home/hekimtap/app/config/environment', __FILE__) require "anycable-rails" Anycable.connection_factory = ActionCable.server.config.connection_class.call Rails.application.eager_load! Anycable::Server.start |
Дозволяємо запуск сервісів
1 2 |
systemctl enable anycable.service systemctl enable anycable-go.service |
Старт
1 2 |
systemctl start anycable.service systemctl start anycable-go.service |