capistrano-resque error with remote Redis DB - ruby-on-rails

Hey I'm configuring my capistrano-resque, and I have a remote redis DB.
This is how my capistrano-resque configuration looks in deploy.rb:
set :resque_environment_task, true
role :resque_worker, ENV['REDIS_SERVER']
role :resque_scheduler, ENV['REDIS_SERVER']
set :workers, { "*" => 1 }
When I try to run cap production git:check, deploy:check I get the following error:
INFO [1df5c9be] Running /usr/bin/env mkdir -p /tmp/mk/ as deploy#ipaddress
INFO [b91cbf1f] Running /usr/bin/env mkdir -p /tmp/mk/ as redis#//x
DEBUG [1df5c9be] Command: /usr/bin/env mkdir -p /tmp/mk/
DEBUG [b91cbf1f] Command: /usr/bin/env mkdir -p /tmp/mk/
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as redis#//x: getaddrinfo: nodename nor servname provided, or not known
SocketError: getaddrinfo: nodename nor servname provided, or not known
It seems like there is something with redis#//x ? I have the full connection string stored as a local env both locally and in production:
redis://x:[password]#aws-eu-west.0.dblayer.com:10156
Anybody have an idea on what's wrong?

The problem is that you're supplying a Redis address instead of an SSH address. Capistrano uses SSHKit to execute remote SSH commands on the server -- whatever you set as the role will be the server it uses. The role :resque_worker line isn't anything fancy we added in capistrano-resque, it's just assigning another role for Capistrano/SSHKit to use (in addition to the default app/web/db roles Capistrano includes by default).
In other words, the :resque_worker setting isn't to specify which Redis server contains your job queue, it's to specify which server to run commands like rake resque:work on.
So in a single-server scenario, your :resque_worker role should probably be the same as your role :app ... line, for example:
role :app, "me#example.com"
role :resque_worker, "me#example.com"
Doing so would connect via SSH to to the me account at example.com and execute the commands.
See http://capistranorb.com/documentation/getting-started/preparing-your-application/ (Section 4) for more info on how roles are defined/used.

Related

Deploying Rails App with Capistrano - "ERROR: Repository not found."

I'm having trouble using Capistrano to deploy a Rails app to an EC2 instance. I am developing the new app for my work on my personal laptop. I have two Github accounts (personal and work). I tried to add my personal public key but Github refused because my personal Github account was already associated with it. So, as a result I have two sets of private/public keys on my laptop.
I added my work public key (~/.ssh/work_rsa.pub) to my work Github account. I created a new private repository under a Github Organization (referred to as WorkOrg) that my work Github account owns (I'm an admin user in that org).
Then I had to create an alias so that git would use my work private key when pushing to Github. Here's how my ~/.ssh/config looks:
# work account
Host github.com-work
HostName github.com
User git
IdentityFile ~/.ssh/work_rsa
I then had to change the remote origin url to: git#github.com-work:WorkOrg/work_reports.git so that I could run $ git push without having to supply my username and password info every time. So, I can now push/pull just fine in this new repo (work_reports) on my laptop.
I also setup an EC2 instance (ubuntu 14.04) and created a user deploy that I can SSH into (using the same ~/.ssh/work_rsa key). I copied over my work_rsa into /home/deploy/.ssh/work_rsa so that I could push/pull from that EC2 instance.
I'm now ready to use Capistrano to setup automated deployments to my EC2 instance. When I run $ cap production deploy:check --trace it fails after this:
INFO [bb69f764] Running /usr/bin/env chmod +x /tmp/work_reports/git-ssh.sh as deploy#xx.xxx.xxx.xxx
DEBUG [bb69f764] Command: ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.2.2 /usr/bin/env chmod +x /tmp/work_reports/git-ssh.sh )
INFO [bb69f764] Finished in 0.046 seconds with exit status 0 (successful).
** Execute git:check
DEBUG [943f7c42] Running /usr/bin/env git ls-remote -h git#github.com:WorkOrg/work_reports.git as deploy#xx.xxx.xxx.xxx
DEBUG [943f7c42] Command: ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.2.2 GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/work_reports/git-ssh.sh /usr/bin/env git ls-remote -h git#github.com:WorkOrg/work_reports.git )
DEBUG [943f7c42] Error: Repository not found.
DEBUG [943f7c42] fatal: Could not read from remote repository.
DEBUG [943f7c42]
DEBUG [943f7c42] Please make sure you have the correct access rights
DEBUG [943f7c42] and the repository exists.
Here's my Capfile:
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/bundler'
require 'capistrano/rails'
require 'capistrano/rbenv'
set :rbenv_type, :user
set :rbenv_ruby, '2.2.2'
Here's my /config/deploy.rb file:
lock '3.2.1'
set :application, 'work_reports'
set :deploy_user, 'deploy'
set :scm, :git
#set :repo_url, 'git#github.com-work:WorkOrg/work_reports.git'
set :repo_url, 'git#github.com:WorkOrg/work_reports.git'
set :branch, ENV['REVISION'] || ENV['BRANCH'] || "master"
set :ssh_options, { forward_agent: true, paranoid: true, keys: "~/.ssh/work_rsa" }
set :deploy_to, '/home/deploy/work_reports'
set :linked_files, %w{config/database.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
execute :touch, release_path.join('tmp/restart.txt')
end
end
after :publishing, 'deploy:restart'
after :finishing, 'deploy:cleanup'
end
And here's my /config/deploy/production.rb file:
set :stage, :production
server 'xx.xxx.xxx.xxx', user: 'deploy', roles: %w{web app db}
I even tried using the aliased remote origin url (set :repo_url, 'git#github.com-work:WorkOrg/work_reports.git') in the deploy.rb file but I got the same error.
Is there something I'm not configuring properly so that I can deploy my Rails app to EC2 using Capistrano?
I had to change my /config/deploy.rb file in order for Capistrano to actually use the work_rsa private key :
set :ssh_options, { forward_agent: false, paranoid: true, keys: "~/.ssh/work_rsa" }
Late in the train here.
My problem turned out to be changed repo name. This was fixed when I SSH'd to the server, then changed the repo URI in git config located at /to/project/repo/config.
Weird thing that this was only happening in Travis CI build. Also, no problem when I checked with capistrano-ssh-doctor.

create an EC2 using Chef / knife socket error

I am trying to create an EC2 using knife and knife-ec2 gem
command example :
knife ec2 server create --image ami-f7f03d80 -i --flavor t2.micro -x root -i /root/europe.pem —sud —groups chef-client -Z eu-west-1a -r “role[xmpp]”
Error output :
ERROR: Excon::Errors::SocketError: getaddrinfo: Name or service not known (SocketError)
knife.rb :
log_level :info
log_location STDOUT
node_name 'ec2-user'
client_key '/root/.chef/ec2-user.pem'
validation_client_name 'chef-validator'
validation_key '/etc/chef-server/chef-validator.pem'
chef_server_url 'https://ip-****.eu-west-1.compute.internal:443'
syntax_check_cache_path '/root/.chef/syntax_check_cache'
knife[:aws_access_key_id] = '*****'
knife[:aws_secret_access_key] = '*****'
knife[:region] = 'eu-west-1a'
--
gem list knife-ec2
*** LOCAL GEMS ***
knife-ec2 (0.8.0)
Can any one put me on the right direction, i a m suspecting an issue with the ruby gems.
PS :
for some reason knife ec2 flavor list works fine.
Thanks in advance.
regards,
Amine
>
SOLUTION :
fixed by : - reinstalling the ruby gems - reusing the patched version of ec2 create .rb
That error means it's not able to resolve the hostname I believe. I'd start there.

How do I set up git in deploy.rb in a rails 4 app using mina?

I am trying to use mina to deploy my app to a digital ocean server and have a git repo on bitbucket. I was able to run mina setup' just fine, but when I runmina deploy` I get an error.
my deploy.rb
require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
require 'mina/rbenv' # for rbenv support. (http://rbenv.org)
# require 'mina/rvm' # for rvm support. (http://rvm.io)
# 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 :rails_env, 'production'
set :domain, 'my.server'
set :deploy_to, '/home/deployer/mysite'
set :repository, 'git#bitbucket.org:me/myproject.git'
set :branch, 'master'
set :user, 'deployer'
set :forward_agent, true
set :port, '22'
# 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']
# Optional settings:
# set :user, 'foobar' # Username in the server to SSH to.
# set :port, '30000' # SSH port number.
# This task is the environment that is loaded for most commands, such as
# `mina deploy` or `mina rake`.
task :environment do
# If you're using rbenv, use this to load the rbenv environment.
# Be sure to commit your .rbenv-version to your repository.
queue %{
echo "-----> Loading environment"
#{echo_cmd %[source ~/.bashrc]}
}
invoke :'rbenv:load'
# For those using RVM, use this to load an RVM version#gemset.
# invoke :'rvm:use[ruby-1.9.3-p125#default]'
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'."]
end
desc "Deploys the current version to the server."
task :deploy => :environment do
deploy do
# Put things that will set up an empty directory into a fully set-up
# instance of your project.
invoke :'git:clone'
invoke :'deploy:link_shared_paths'
invoke :'bundle:install'
invoke :'rails:db_migrate'
invoke :'rails:assets_precompile'
to :launch do
invoke :'passenger:restart'
end
end
end
desc "Restarts the nginx server."
task :restart do
invoke :'passenger:restart'
end
namespace :passenger do
task :restart do
queue "mkdir #{deploy_to}/current/tmp; touch #{deploy_to}/current/tmp/restart.txt"
end
end
# For help in making your deploy script, see the Mina documentation:
#
# - http://nadarei.co/mina
# - http://nadarei.co/mina/tasks
# - http://nadarei.co/mina/settings
# - http://nadarei.co/mina/helpers
When I do "mina deploy", I get this error
-----> Loading environment
-----> Loading rbenv
-----> Creating a temporary build path
-----> Cloning the Git repository
Cloning into bare repository '/home/deployer/mysite/scm'...
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
! ERROR: Deploy failed.
-----> Cleaning up build
Unlinking current
OK
! Command failed.
Failed with status 19
I have ssh keys set up on bitbucket and Im able to push my repo to it just fine from my computer, I also have an ssh key from my server set up on bitbucket (not sure if it is needed, but I thought i would try it). What could be wrong?
add this in your deploy.rb file
set :term_mode, nil
make sure that you have added server SSH public key on github
You can use your local ssh keys for this.
Use the -A setting of SSH. and set it in mina like set :port, '22 -A' this will append the -A to the ssh command issued by Mina.
Basically it forwards the authentication you use on your deployment server. (like set :forward_agent, true does in Capistrano)
I think best practice however, is to generate a ssh key on the server and set it as a deploy key in your hosted SCM solution.
Your server tries to git from git#bitbucket.org:me/myproject.git, but there is host key at your server.
You can copy your id_rsa.pub and known_hosts file through scp command on server and then run it again. It will work.

Gitlab API Access Connection timed out

I just installed Gitlab and I have an error during the gitlab-shell self check.
The command returns :
root#git:/home/git/gitlab# sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
Checking Environment ...
Git configured for git user? ... yes
Checking Environment ... Finished
Checking GitLab Shell ...
GitLab Shell version >= 1.9.3 ? ... OK (1.9.3)
Repo base directory exists? ... yes
Repo base directory is a symlink? ... no
Repo base owned by git:git? ... yes
Repo base access is drwxrws---? ... yes
Satellites access is drwxr-x---? ... yes
update hook up-to-date? ... yes
update hooks in repos are links: ...
Thibaud / thibaud-dauce ... repository is empty
Running /home/git/gitlab-shell/bin/check
Check GitLab API access: /usr/local/lib/ruby/2.0.0/net/http.rb:878:in `initialize': Connection timed out - connect(2) (Errno::ETIMEDOUT)
from /usr/local/lib/ruby/2.0.0/net/http.rb:878:in `open'
from /usr/local/lib/ruby/2.0.0/net/http.rb:878:in `block in connect'
from /usr/local/lib/ruby/2.0.0/timeout.rb:52:in `timeout'
from /usr/local/lib/ruby/2.0.0/net/http.rb:877:in `connect'
from /usr/local/lib/ruby/2.0.0/net/http.rb:862:in `do_start'
from /usr/local/lib/ruby/2.0.0/net/http.rb:851:in `start'
from /home/git/gitlab-shell/lib/gitlab_net.rb:76:in `get'
from /home/git/gitlab-shell/lib/gitlab_net.rb:43:in `check'
from /home/git/gitlab-shell/bin/check:11:in `<main>'
gitlab-shell self-check failed
Try fixing it:
Make sure GitLab is running;
Check the gitlab-shell configuration file:
sudo -u git -H editor /home/git/gitlab-shell/config.yml
Please fix the error above and rerun the checks.
Checking GitLab Shell ... Finished
Checking Sidekiq ...
Running? ... yes
Number of Sidekiq processes ... 1
Checking Sidekiq ... Finished
Checking LDAP ...
LDAP is disabled in config/gitlab.yml
Checking LDAP ... Finished
Checking GitLab ...
Database config exists? ... yes
Database is SQLite ... no
All migrations up? ... yes
Database contains orphaned UsersGroups? ... no
GitLab config exists? ... yes
GitLab config outdated? ... no
Log directory writable? ... yes
Tmp directory writable? ... yes
Init script exists? ... yes
Init script up-to-date? ... yes
projects have namespace: ...
Thibaud / thibaud-dauce ... yes
Projects have satellites? ...
Thibaud / thibaud-dauce ... can't create, repository is empty
Redis version >= 2.0.0? ... yes
Your git bin path is "/usr/bin/git"
Git version >= 1.7.10 ? ... yes (1.7.10)
Checking GitLab ... Finished
Of course, Gitlab is running :
root#git:/home/git/gitlab# service gitlab status
The GitLab Unicorn web server with pid 1543 is running.
The GitLab Sidekiq job dispatcher with pid 1736 is running.
GitLab and all its components are up and running.
And my config file :
root#git:/home/git/gitlab# sudo -u git -H cat /home/git/gitlab-shell/config.yml
# GitLab user. git by default
user: git
# Url to gitlab instance. Used for api calls. Should end with a slash.
gitlab_url: "http://git.thibaud-dauce.fr/"
http_settings:
# user: someone
# password: somepass
# ca_file: /etc/ssl/cert.pem
# ca_path: /etc/pki/tls/certs
self_signed_cert: false
# Repositories path
# Give the canonicalized absolute pathname,
# REPOS_PATH MUST NOT CONTAIN ANY SYMLINK!!!
# Check twice that none of the components is a symlink, including "/home".
repos_path: "/home/git/repositories"
# File used as authorized_keys for gitlab user
auth_file: "/home/git/.ssh/authorized_keys"
# Redis settings used for pushing commit notices to gitlab
redis:
bin: /usr/bin/redis-cli
host: 89.234.146.59
port: 6379
# socket: /tmp/redis.socket # Only define this if you want to use sockets
namespace: resque:gitlab
# Log file.
# Default is gitlab-shell.log in the root directory.
# log_file: "/home/git/gitlab-shell/gitlab-shell.log"
# Log level. INFO by default
log_level: INFO
# Audit usernames.
# Set to true to see real usernames in the logs instead of key ids, which is easier to follow, but
# incurs an extra API call on every gitlab-shell command.
audit_usernames: false
I already try to replace in Redis conf host: 127.0.0.1 to host: 89.234.146.59
I also try to add 89.234.146.59 git.thibaud-dauce.fr in /etc/hosts
I have a server running Debian 7 32bits with a container LXC for Gitlab, Ruby is version 2.0.0. I have the same error when I try to push a repo (but I can create one online with the web app)
Do you have any idea ? I really look everywhere and found no solution...

GitHub Deploy via Capistrano. Public Repo and SSH works, but Private doesn't

i really need your help. I have a Ruby on Rails Application on my local machine, a Repository at GitHub and an Ubuntu Server, which hosts the application with Nginx.
I had my repo for a lot of time public and the deployment via capistrano worked just fine. Now I converted my repo to a private one and the deployment just doesn't work. When i try to deploy it, i get the following error:
* executing `deploy'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
updating the cached checkout on all servers
executing locally: "git ls-remote git://github.com/GIT_USER/APPLICATION.git master"
fatal: The remote end hung up unexpectedly
*** [deploy:update_code] rolling back
* executing "rm -rf /var/www/APPLICATION/releases/DATE_OF_DEPLOY; true"
servers: ["DOMAIN"]
[DOMAIN] executing command
command finished in 424ms
So, my guess would be, that the authentication doesn't work, but it does. I copied my public key to GitHub and can even SSH there. I can SSH from the server to GitHub and it says that I am successfully authenticated. I can even see which key works. But "git ls-remote [...]" does not work and I get no info running it with trace, besides the information i already got.
So, my main problem is that i don't no where to look for the error. If you know how to solve this or can point my in any direction that would be nice.
And this is the main part of my deploy.rb:
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require "rvm/capistrano"
require 'bundler/capistrano'
default_run_options[:pty] = true
set :user, "DEPLOY_USER"
set :domain, "DOMAIN"
set :application, "APPLICATION"
set :repository, "git#github.com:GIT_USER/APPLICATION.git"
set :deploy_to, "/var/www/#{application}"
set :deploy_via, :remote_cache
set :scm, :git
set :git_account, "GIT_USER"
set :branch, "master"
set :git_shallow_clone, 1
set :scm_verbose, true
set :use_sudo, false
set :rvm_bin_path, "/usr/local/rvm/bin"
set :rvm_ruby_string, '1.9.2'
set :rvm_type, :user # Don't use system-wide RVM
ssh_options[:port] = PORT_NUMBER
set :user, user
ssh_options[:keys] = %w(/home/DEPLOY_USER/.ssh/id_rsa)
set :ssh_options, { :forward_agent => true}
server domain, :app, :web
# Your HTTP server, Apache/etc
role :web, domain
# This may be the same as your `Web` server
role :app, domain
# This is where Rails migrations will run
role :db, domain, :primary => true
Sorry that this thing looks so cluttered, but i tried like a thousand hints, tipps and tutorials.
Thanks for every help!
And by the Way: Yes, all the things written in Capslock are just for privacy reasons and are, of course, not the real settings I use.
I seem to remember having a similar issue with deploying using a private github repo. I don't thinkg we ever quite worked out the cause of the problem but in the end I think we solved the issue using ssh-add to add the github key to ssh-agent - might be worth a try
Since this is now a non-public repo, you should be using git#... address.
I see you have this in your deploy.rb file, but ls-remote is still executed on git://...
The problem may be a cached-copy of the repository you have on a server. Check if you have correct origin address in shared/cached-copy/.git/config file. You should have git#... instead of git://... there
for private repos you have to use the https style:
set :repository, "https://github.com/git_name/repo_name.git"
.. but you have to type in your username and password twice on every deploy!
so I write a little Expect-script to do that for me
have a look at this gist
.. or as a walkthrough:
1 - make a file in your home directory ($ cat > ~/git_cap)
#!/usr/bin/expect -f
# Expect script to supply username/password to cap deploy to git private repository
# This script needs username and password as arguments to connect to git server:
# ------------------------------------------------------------------------
# ./git_cap gituser gitpwd
# -------------------------------------------------------------------------
# set Variables
set g_user [lrange $argv 0 0]
set g_pwd [lrange $argv 1 1]
set timeout -1
spawn cap deploy
match_max 100000
# Look for user prompt
expect "*?sername:*"
send -- "$g_user\r"
send -- "\r"
# Look for passwod prompt
expect "*?assword:*"
send -- "$g_pwd\r"
send -- "\r"
# Look for user prompt
expect "*?sername:*"
send -- "$g_user\r"
send -- "\r"
# Look for passwod prompt
expect "*?assword:*"
send -- "$g_pwd\r"
send -- "\r"
expect eof
2 - make it executable
$ chmod 755 ~/git_cap
$ chmod +x ~/git_cap
3 - add a alias in your .profile / .bashrc .. (optional)
alias gcap='~/git_cap gitname gitpwd'
4 - add your sudo-pwd to deploy.rb or extend the expect-script for sudo-pwd
( for that reason username & password expected 2 times, even if it where possible to use it more times .. but this way you can add a line for password with exp_continue so every next password will send the sudo-pwd and not your git-pwd)
5 - deploy with gcap
rails_root$ gcap

Resources