capistrano deploy using jruby - deployment

I have a server that holds multiple rails apps, the majority of them are ruby, wheras there is one app that we use jruby
I always get this error after deploy under passenger:
Could not find rake-10.1.0 in any of the sources (Bundler::GemNotFound)
However, I don't get this when I locally rails s using WEBrick
the deploy script as following:
#server details
default_run_options[:pty] = true
set :user, "xxxxx"
set :scm_passphrase, "yyyyyy"
set :domain, "abc.abc.com"
set :application, "project_adsadsa"
#file path
set :repository, "git#github.com:jjjjjjjj/aaaaaaaa.git"
set :deploy_to, "/var/www/html/jdbc"
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
role :web, "ip_address" # Your HTTP server, Apache/etc
role :app, "ip_address" # This may be the same as your `Web` server
role :db, "ip_address", :primary => true # This is where Rails migrations will run
#miscellaneous options
set :rails_env, :development
set :deploy_via, :remote_cache
set :scm, 'git'
set :branch, 'master'
set :scm_verbose, true
set :use_sudo, false
ssh_options[:forward_agent] = true
namespace :deploy do
desc "cause Passenger to initiate a restart"
task :restart do
run "touch #{current_path}/tmp/restart.txt"
end
end
after "deploy:update_code", :bundle_install
after "deploy", :create_symlink
desc "do symlink the db"
task :create_symlink, :roles => :app do
run "ln -s #{shared_path}/development.sqlite3 #{current_path}/db/development.sqlite3"
end
desc "install the necessary prerequisites"
task :bundle_install, :roles => :app do
run "cd #{release_path} && bundle install --without production"
end

Related

capistrano(3) deployment with use_sudo=true - undefined local variable or method default_run_options for main:Object

I want to cap production deploy:check, but I got the error message mkdir: cannot create directory /var/www: Permission denied.
I'm using Capistrano3 and Rails4.
I think the sudo couldn't work in my case.
deploy.rb
set :application, 'appname.com'
set :repo_url, 'git#bitbucket.org:user/myapp.git'
set :user, 'username'
set :use_sudo, true
set :branch, 'master'
set :deploy_to, '/var/www/myapp'
set :pty, true
set :keep_releases, 5
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
end
end
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
end
end
after :finishing, 'deploy:cleanup'
end
production.rb
set :stage, :production
set :branch, 'master'
role :all, %w{appname.com}
server 'appname.com', user: 'username', port: 'port_number', roles: %w{web app db}, my_property: :my_value
I read these articles.
Capistrano is hanging when prompting for SUDO password to an Ubuntu box
capistrano deployment with use_sudo=true - permissions problem
So I added default_run_options[:pty] = true to deploy.rb, but I got just undefined local variable or method default_run_options for main:Object
Thank you for your advice.

how to run a script on rails server using capistrano?

I have written a script named mailman_server using gem "mailman" placed in 'script/mailman_server'
#!/usr/bin/env ruby
require "rubygems"
require "bundler/setup"
require "mailman"
#Mailman.config.logger = Logger.new("log/mailman.log")
Mailman.config.poll_interval = 3
Mailman.config.pop3 = {
server: 'server', port: 110,
username: "loginid",
password: "password"
}
Mailman::Application.run do
default do
p "Found a new message"
# 'perform some action here'
end
end
It fetches all the emails from my account and then i do processing on them.
I have my deploy.rb file as
set :stages, %w(production) #various environments
load "deploy/assets" #precompile all the css, js and images... before deployment..
require "bundler/capistrano" # install all the new missing plugins...
require 'delayed/recipes' # load this for delayed job..
require 'capistrano/ext/multistage' # deploy on all the servers..
require "rvm/capistrano" # if you are using rvm on your server..
require './config/boot'
require 'airbrake/capistrano' # using airbrake in your application for crash notifications..
set :delayed_job_args, "-n 2" # number of delayed job workers
before "deploy:assets:symlink", "deploy:copy_database_file"
before "deploy:update_code", "delayed_job:stop" # stop the previous deployed job workers...
after "deploy:start", "delayed_job:start" #start the delayed job
after "deploy:restart", "delayed_job:restart" # restart it..
after "deploy:update", "deploy:cleanup" #clean up temp files etc.
set :rvm_ruby_string, '1.9.3' # ruby version you are using...
set :rvm_type, :user
server "my_server_ip", :app, :web, :db, :primary => true
set(:application) { "my_application_name" }
set (:deploy_to) { "/home/user/#{application}/#{stage}" }
set :user, 'user'
set :keep_releases, 3
set :repository, "git#bitbucket.org:my_random_git_repo_url"
set :use_sudo, false
set :scm, :git
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
set :deploy_via, :remote_cache
set :git_shallow_clone, 1
set :git_enable_submodules, 1
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
task :copy_database_file do
run "ln -sf #{shared_path}/database.yml #{release_path}/config/database.yml"
end
end
I want to execute this script every time I deploy to the server. Also I need to stop this script whenever I am deploying the code.
I am unable to figure out how can we start or stop this script using capistrano on server.
You could try to save pid of process on start with something like this
run "cd #{deploy_to}/current; ./script/mailman_server &; echo &! > /var/run/mailman_server.pid" #untested
and stop it with
run "kill `cat /var/run/mailman_server.pid`; rm /var/run/mailman_server.pid"
But I think you should check out Foreman, it provides handy way to run jobs in development and supports exporting your jobs to upstart or inid.d scripts for production, so you will need just to start or stop corresponding service with
run "sudo /etc/init.d/mailman_server start"
run "sudo /etc/init.d/mailman_server stop"

Capifony & Symfony 2 error: php bin/vendors install --reinstall

I have a big problem.
I had a configuration which worked properly till today.
I don't know why I have now this error
*** [err :: server.com] Could not open input file: bin/vendors
command finished in 312ms
*** [deploy:update_code] rolling back
* executing "rm -rf /home/server/deploy/releases/20120301143822; true"
servers: ["server.com"]
[server.com] executing command
command finished in 208ms
failed: "sh -c 'cd /home/server/deploy/releases/20120301143822 && php bin/vendors install --reinstall'" on server.com
I precise that I deploy my local work to production
here is my deploy file
set :application, "MyApp"
set :deploy_to, "/home/server/deploy"
set :serverName, "myServer.com" # The server's hostname
set :domain, "server.com"
set :scm, :git
set :repository, "file:///Applications/MAMP/htdocs/localWorkDev"
set :deploy_via, :rsync_with_remote_cache
role :web, domain
role :app, domain
role :db, domain, :primary => true
set :use_sudo, false
set :keep_releases, 3
set :user, "root"
set :shared_files, ["app/config/parameters.ini"]
set :shared_children, [app_path + "/logs", web_path + "/uploads", "vendor"]
set :update_vendors, true
Please help me
Thanks
Sam
ALL is right now. I have just done a
php bin/vendors install --reinstall
and now it works.
In my case, it was very important to add --reinstall command.
Hope it would be usefull
Sam

Bundle install failing when deploying a Rails 3 app to Dreamhost with Capistrano

I am trying to deploy a locally working Rails 3 app to Dreamhost with Capistrano.
When I run 'cap deploy -v' in my local app root I get so far before it chokes on 'bundle install'. The following is the end of the error message:
** transaction: start **
[abunchofletters.co.uk :: out] my_username#abunchofletters.co.uk's password:
Password: **
[abunchofletters.co.uk :: out] **
[abunchofletters.co.uk :: out] HEAD is now at 62f9cdb Initial deploy to Dreamhost
** [out :: abunchofletters.co.uk] sh: bundle: command not found
* [deploy:update_code] rolling back
failed: "sh -c 'bundle install --gemfile /home/my_username/abunchofletters.co.uk/releases/20110111100145/Gemfile --path /home/my_username/abunchofletters.co.uk/shared/bundle --deployment --quiet --without development test'" on abunchofletters.co.uk
Yet when I SSH into my server, and check the gem list, bundler 1.0.7 is shown to be installed [also running Ruby 1.8.7, Rails 3.0.3, RubyGems 1.3.6]. This is my first experience with deploying a Rails app as well as Capistrano so I'm close to clueless but I'd guess some path or variable is not set correctly.
Here's my deploy.rb [created from following http://railstips.org/blog/archives/2008/12/14/deploying-rails-on-dreamhost-with-passenger/ so could be outdated]:
require "bundler/capistrano" # http://gembundler.com/deploying.html
default_run_options[:pty] = true
# be sure to change these
set :user, 'my_username'
set :domain, 'abunchofletters.co.uk'
set :application, 'abunchofletters'
# the rest should be good
set :repository, "#{user}##{domain}:git/#{application}.git"
set :deploy_to, "/home/#{user}/#{domain}"
set :deploy_via, :remote_cache
set :scm, 'git'
set :branch, 'master'
set :git_shallow_clone, 1
set :scm_verbose, true
set :use_sudo, false
server domain, :app, :web
role :db, domain, :primary => true
namespace :deploy do
task :restart do
run "touch #{current_path}/tmp/restart.txt"
end
end
Any ideas how to progress? If there's any more info you need just prompt me and I'll supply it.
I'm not too satisfied with the solution I came up with, but it got the deploy to work and bundler to update.
Here's my updated deploy.rb:
#require "bundler/capistrano"
default_run_options[:pty] = true
# be sure to change these
set :user, 'futureproof'
set :domain, 'abunchofletters.co.uk'
set :application, 'abunchofletters'
# the rest should be good
set :repository, "#{user}##{domain}:git/#{application}.git"
set :deploy_to, "/home/#{user}/#{domain}"
set :deploy_via, :remote_cache
set :shared_path, "/home/#{user}/.gems"
set :scm, 'git'
set :branch, 'master'
set :git_shallow_clone, 1
set :scm_verbose, true
set :use_sudo, false
server domain, :app, :web
role :db, domain, :primary => true
namespace :deploy do
desc "expand the gems"
task :gems, :roles => :web, :except => { :no_release => true } do
run "cd #{current_path}; #{shared_path}/bin/bundle unlock"
run "cd #{current_path}; nice -19 #{shared_path}/bin/bundle install vendor/" # nice -19 is very important otherwise DH will kill the process!
run "cd #{current_path}; #{shared_path}/bin/bundle lock"
end
task :restart do
run "touch #{current_path}/tmp/restart.txt"
end
end
The :gems task was seen here: http://grigio.org/deploy_rails_3_passenger_apache_dreamhost, though the bundle lock/unlock are deprecated now. Might be able to simply replace with bundle install/update, but deprecated will do for tonight.

Capistrano remote authentication problem

I'm trying to deploy to a slicehost slice using this config/deploy/production.rb file. I'm clueless & haven't used capistrano before now. Here are the steps I followed. Sorry but I'm completely new to capistrano. It keeps asking for my password (have set up passwordless SSH), and throwing this error:
(SocketError: getaddrinfo: Name or service not known)
connection failed for: ---------.com (Net::SSH::AuthenticationFailed: -----)
First, it's a 'bort' app http://github.com/fudgestudios/bort/tree/master
Second, I used the ubuntu-machine gem, detailed here:
http://suitmymind.github.com/ubuntu-machine/#screencast
config/deploy/production.rb
#############################################################
# Application
#############################################################
set :application, "---------------"
set :deploy_to, "/var/www/#{application}"
#############################################################
# Settings
#############################################################
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
set :use_sudo, true
set :scm_verbose, true
set :rails_env, "production"
#############################################################
# Servers
#############################################################
set :user, "----------"
set :domain, "--------------------------"
server domain, :app, :web
role :db, domain, :primary => true
#############################################################
# Git
#############################################################
set :scm, :git
set :branch, "master"
set :scm_user, '---------'
set :scm_passphrase, "----------"
set :repository, "git#github.com:--------/----------.git"
set :deploy_via, :remote_cache
#############################################################
# Passenger
#############################################################
namespace :deploy do
desc "Create the database yaml file"
task :after_update_code do
db_config = <<-EOF
production:
adapter: mysql
encoding: utf8
username: root
password: ------------
database: ------------_production
host: localhost
EOF
put db_config, "#{release_path}/config/database.yml"
#########################################################
# Uncomment the following to symlink an uploads directory.
# Just change the paths to whatever you need.
#########################################################
desc "Symlink the assets directories"
task :before_symlink do
run "mkdir -p #{shared_path}/assets"
run "ln -nfs #{shared_path}/assets #{release_path}/public/assets"
end
end
# Restart passenger on deploy
desc "Restarting mod_rails with restart.txt"
task :restart, :roles => :app, :except => { :no_release => true } do
run "touch #{current_path}/tmp/restart.txt"
end
[:start, :stop].each do |t|
desc "#{t} task is a no-op with mod_rails"
task t, :roles => :app do ; end
end
end
I think the problem would be either
It can't resolve your hostname
You typo wrong domain value
Just in case, have you tried to set the domain value to be your server's IP address instead?
"SocketError: getaddrinfo: Name or service not known" implies some sort of problem resolving or connecting to the remote host. Have you checked that you can connect manually?
One way to start debugging cap scripts is to perform each step of the process yourself. You can copy the statements directly from the verbose cap output. That should help isolate the problem, in this case, where the connection problem is (slicehost?, github?, both?).