#377 Trinidad pro
- Download:
- source codeProject Files in Zip (69.2 KB)
- mp4Full Size H.264 Video (40.8 MB)
- m4vSmaller H.264 Video (19.6 MB)
- webmFull Size VP8 Video (19.6 MB)
- ogvFull Size Theora Video (47.1 MB)
Resources
- Trinidad
- Trinidad Available Extension
- Episode 376: JRuby Basics
- Episode 337: Capistrano Recipes
- Episode 373: Zero-Downtime Deployment
- Episode 365: Thread-Safety
Gotchas
I ran into a few gotchas while recording this episode. Here's an overview.
Highline Version
If you are using JRuby 1.7 and receiving the exception NameError: cannot load Java class jline.ConsoleReader
while running Capistrano commands then try running bundle update highline
. This was fixed in Highline version to 1.6.14. See this issue for details.
SSH Agent Forwarding
If Capistrano hangs while deploying, check to see if the ssh_options[:forward_agent] = true
is in the Capistrano config. This may not work as discussed here. Here are some solutions.
- Authorize the server directly by generating an SSH key and setting it up as the deploy key.
- Consider running Capistrano commands from Ruby MRI on your local.
- Use an alternative deployment method such as "copy"
- Try upgrading to JRuby 7 on your local machine, this has been reported to solve the issue but I have not tested it.
Not Reloading
I experienced an issue where running touch tmp/restart.txt
on the server would not use the latest code. Unfortunately I was unable to reproduce this problem consistently enough to resolve it. If you experience this, please comment on this issue. Special thanks to Karol Bucek for helping me look into this.
Code
ssh root@198.58.96.26 adduser deployer echo "deployer ALL=(ALL:ALL) ALL" >> /etc/sudoers exit ssh-copy-id deployer@198.58.96.26 cap deploy:install cap deploy:setup cap deploy:cold bundle exec rails s trinidad -e production cap nginx:setup cap trinidad:setup touch tmp/restart.txt cap deploy trinidad:restart
platform :jruby do gem 'activerecord-jdbcpostgresql-adapter' gem 'jruby-openssl' gem 'therubyrhino', group: :assets gem 'trinidad', require: false end platform :ruby do gem 'pg' end
load "config/recipes/trinidad" # ... set :deploy_via, :copy set :repository, "." set :copy_exclude, %w[.git log tmp .DS_Store] set :scm, :none
set_default :ruby_version, "jruby-1.7.0-preview2" # ... run "#{sudo} apt-get -y install openjdk-7-jdk jsvc"
set_default(:trinidad_config_path) { "#{shared_path}/config/trinidad.yml" } set_default :trinidad_config do { "environment" => "production", "reload_strategy" => "rolling", "jruby_max_runtimes" => 1 } end set_default :trinidad_init_config do { "run_user" => user, "app_path" => current_path, "trinidad_options" => "--config #{trinidad_config_path}", "ruby_compat_version" => "RUBY1_9", "jsvc_path" => "/usr/bin/jsvc", "java_home" =>"/usr/lib/jvm/java-7-openjdk-i386/jre", "jruby_home" => "/home/#{user}/.rbenv/versions/#{ruby_version}", "pid_file" => "#{shared_path}/pids/trinidad.pid", "log_file" => "#{shared_path}/log/trinidad.log", "output_path" => "/tmp" # move later using sudo } end namespace :trinidad do desc "Setup Trinidad configuration for this application" task :setup, roles: :app do put trinidad_config.to_yaml, trinidad_config_path put trinidad_init_config.to_yaml, "/tmp/trinidad_init.yml" run "gem install trinidad_init_services" run "trinidad_init_service /tmp/trinidad_init.yml" run "#{sudo} mv /tmp/trinidad /etc/init.d/trinidad_#{application}" run "#{sudo} update-rc.d -f trinidad_#{application} defaults" restart end after "deploy:setup", "trinidad:setup" desc "Reload application in Trinidad" task :reload, roles: :app do run "touch #{current_release}/tmp/restart.txt" end after "deploy:restart", "trinidad:reload" %w[start stop restart].each do |command| desc "#{command} Trinidad" task command, roles: :app do run "#{sudo} service trinidad_#{application} #{command}" end end end
try_files $uri/index.html $uri @trinidad; location @trinidad { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://localhost:3000; }