0

I'm following this tutorial http://blog.mccartie.com/2014/08/28/digital-ocean.html to deploy my existing rails app to digital ocean with Mina, but my deploy fails, and looking into the errors logs I've found this error in the var/log/nginx/app_name.log:

connect() to unix:/home/deployer/rahmchicago/shared/sockets/unicorn.sock failed (2: No such file or directory) while connecting to upstream

These are my config files:

/etc/nginx/nginx.conf

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
 worker_connections 768;
}

http {

  ##
  # Basic Settings
  ##

  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  keepalive_timeout 65;
  types_hash_max_size 2048;

  server_name_in_redirect off;

  include /etc/nginx/mime.types;
  default_type application/octet-stream;

  ##
  # Logging Settings
  ##

  access_log /var/log/nginx/access.log;
  error_log /var/log/nginx/error.log;

  ##
  # Gzip Settings
  ##

  gzip on;
  gzip_disable "msie6";

  ##
  # Virtual Host Configs
  ##

  include /etc/nginx/conf.d/*.conf;
  include /etc/nginx/sites-enabled/*;
}

etc/nginx/sites-enabled/default

upstream app {
  # Path to Unicorn SOCK file, as defined previously
  server unix:/home/deployer/YOUR_APP_NAME/shared/sockets/unicorn.sock fail_timeout=0;
}

server {
  listen         80;
  # Application root, as defined previously
  root /home/deployer/YOUR_APP_NAME/current/public;

  server_name www.YOUR_APP_NAME.com YOUR_APP_NAME.com;

  try_files $uri/index.html $uri @app;

  access_log /var/log/nginx/YOUR_APP_NAME_access.log combined;
  error_log /var/log/nginx/YOUR_APP_NAME_error.log;

location @app {
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://app;
}

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}

config/unicorn.rb in the app

# Set your full path to application.
app_dir = File.expand_path('../../', __FILE__)
shared_dir = File.expand_path('../../../shared/', __FILE__)

# Set unicorn options
worker_processes 2
preload_app true
timeout 30

# Fill path to your app
working_directory app_dir

# Set up socket location
listen "#{shared_dir}/sockets/unicorn.sock", :backlog => 64

# Loging
stderr_path "#{shared_dir}/log/unicorn.stderr.log"
stdout_path "#{shared_dir}/log/unicorn.stdout.log"

# Set master PID location
pid "#{shared_dir}/pids/unicorn.pid"

before_fork do |server, worker|
  defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!
  old_pid = "#{server.config[:pid]}.oldbin"
  if File.exists?(old_pid) && server.pid != old_pid
    begin
      sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
      Process.kill(sig, File.read(old_pid).to_i)
    rescue Errno::ENOENT, Errno::ESRCH
      # someone else did our job for us
    end
  end
end

after_fork do |server, worker|
  defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
end

before_exec do |server|
  ENV['BUNDLE_GEMFILE'] = "#{app_dir}/Gemfile"
end

config/deploy.rb

require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
require 'mina/rvm'
require 'mina_sidekiq/tasks'
require 'mina/unicorn'

# Basic settings:
#   domain       - The hostname to SSH to.
#   deploy_to    - Path to deploy into.
#   repository   - Git repo to clone from. (needed by mina/git)
#   branch       - Branch name to deploy. (needed by mina/git)

set :domain, 'YOUR DROPLETS IP'
set :deploy_to, '/home/deployer/rahmchicago'
set :repository,     'YOUR GIT REPO URL'
set :branch, 'develop'
set :user, 'deployer'
set :forward_agent, true
set :port, '22'
set :unicorn_pid, "#{deploy_to}/shared/pids/unicorn.pid"

# Manually create these paths in shared/ (eg: shared/config/database.yml) in your server.
# They will be linked in the 'deploy:link_shared_paths' step.
set :shared_paths, ['config/database.yml', 'log', 'config/secrets.yml']


# This task is the environment that is loaded for most commands, such as
# `mina deploy` or `mina rake`.
task :environment do
  queue %{echo "-----> Loading environment" #{echo_cmd %[source ~/.bashrc]} }
  invoke :'rvm:use[ruby-2.0.0-p353@default]'
  # If you're using rbenv, use this to load the rbenv environment.
  # Be sure to commit your .rbenv-version to your repository.
end

# Put any custom mkdir's in here for when `mina setup` is ran.
# For Rails apps, we'll make some of the shared paths that are shared between
# all releases.
task :setup => :environment do
  queue! %[mkdir -p "#{deploy_to}/shared/log"]
  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/log"]

  queue! %[mkdir -p "#{deploy_to}/shared/config"]
  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/config"]

  queue! %[touch "#{deploy_to}/shared/config/database.yml"]
  queue  %[echo "-----> Be sure to edit 'shared/config/database.yml'."]

  queue! %[touch "#{deploy_to}/shared/config/secrets.yml"]
  queue  %[echo "-----> Be sure to edit 'shared/config/secrets.yml'."]

  # sidekiq needs a place to store its pid file and log file
  queue! %[mkdir -p "#{deploy_to}/shared/pids/"]
  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/pids"]
end



desc "Deploys the current version to the server."
task :deploy => :environment do
  deploy do

    # stop accepting new workers
    invoke :'sidekiq:quiet'

    invoke :'git:clone'
    invoke :'deploy:link_shared_paths'
    invoke :'bundle:install'
    invoke :'rails:db_migrate'
    invoke :'rails:assets_precompile'

    to :launch do
      invoke :'unicorn:restart'
      invoke :'sidekiq:restart' 
    end
  end
end

I found that the deploy fails when mina execute this line invoke :'unicorn:restart' (in the deploy.rb file), all the other commands execute with success. Thanks for the help!

reVerse
  • 35,075
  • 22
  • 89
  • 84
  • check nginx logs and unicorn logs, the answer will be there ;) – itsnikolay Oct 22 '14 at 16:08
  • @itsnikolay the nginx logs are the one that I mentioned before : `connect() to unix:/home/deployer/rahmchicago/shared/sockets/unicorn.sock failed (2: No such file or directory) while connecting to upstream ` , and there are not unicorn logs. – Juan David Giraldo Oct 22 '14 at 16:20
  • this means that unicorn workers had not been started. Check it `$> ps aux | grep unicorn` – itsnikolay Oct 22 '14 at 16:23
  • @itsnikolay Correct, there are no unicorn worker started in the server, but i'm following this tutorial(I'm noobie with server things): (http://blog.mccartie.com/2014/08/28/digital-ocean.html) They don't install unicorn in the server, they use the mina-unicorn gem, do you thing this is the problem? – Juan David Giraldo Oct 22 '14 at 16:29
  • run command on your computer in application directory `$> mina deploy` and copy its output to gist. I will see what's wrong with unicorn. – itsnikolay Oct 22 '14 at 16:33
  • Hey @itsnikolay this is the gist: https://gist.github.com/JuandGirald/994ba4dc528f69aa70e3 Thanks for the help men! – Juan David Giraldo Oct 22 '14 at 16:39
  • could you upload unicorn.log file /home/deployer/rahmchicago/shared/logs/unicorn.stderr.log (and unicorn.stdout.log) – itsnikolay Oct 22 '14 at 16:58
  • @itsnikolay this is the problem, those files are not generated, it's supposed to be generated when mina run `invoke :'unicorn:restart'` but no. The problem could be in the unicorn.rb file? – Juan David Giraldo Oct 22 '14 at 17:06
  • without unicorn.log to difficult understand what's gone wrong. I think database was not created `production_database` on the server like it described on codeblock `postgres=# CREATE DATABASE yourapp_production;` – itsnikolay Oct 22 '14 at 17:15
  • @itsnikolay you're right but those file are not generated, all my migrations succeed when mina `invoke :'rails:db_migrate'` is not a database problem. Thanks for your help and time, I appreciate it. – Juan David Giraldo Oct 22 '14 at 17:26
  • also try to remove files `/shared/pids/unicorn.pid` and `/shared/sockets/unicorn.sock` and then run `$> sudo service nginx restart` then try to deploy again – itsnikolay Oct 22 '14 at 17:29
  • @itsnikolay I just did it, and doesn't work. By the way, the unicorn.sock and unicorn.pid file are not generated too. – Juan David Giraldo Oct 22 '14 at 17:40
  • probably is there any logs in `/shared/logs/*` directory ? – itsnikolay Oct 22 '14 at 17:42
  • @itsnikolay there are three files : development.log production.log sidekiq.log but there the three files are empty. – Juan David Giraldo Oct 22 '14 at 17:49
  • If you want to get up and running quickly, you may just want to try using a gem that sets everything up for you. Ex: https://github.com/npearson72/rails-ahoy – Nathan Jan 28 '15 at 23:03

0 Answers0