Capistrano: cannot start unicorn - ruby-on-rails

I am having difficulties to (re)start Unicorn as I am deploying with Capistrano as well as manually.
This is deploy.rb:
# config valid only for current version of Capistrano
lock "3.8.1"
set :application, "project"
set :repo_url, "git#bitbucket.org:username/project.git"
set :branch, "master"
set :tmp_dir, '/home/deployer/tmp'
set :deploy_to, "/home/deployer/apps/project"
set :keep_releases, 5
set(:executable_config_files, %w(
unicorn_init.sh
))
# files which need to be symlinked to other parts of the
# filesystem. For example nginx virtualhosts, log rotation
# init scripts etc.
set(:symlinks, [
{
source: "nginx.conf",
link: "/etc/nginx/sites-enabled/default"
},
{
source: "unicorn_init.sh",
link: "/etc/init.d/unicorn_#{fetch(:application)}"
},
{
source: "log_rotation",
link: "/etc/logrotate.d/#{fetch(:application)}"
},
{
source: "monit",
link: "/etc/monit/conf.d/#{fetch(:application)}.conf"
}
])
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
invoke 'unicorn:restart'
end
end
after :publishing, :restart
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
end
end
desc "Make sure local git is in sync with remote."
task :check_revision do
on roles(:web) do
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts "WARNING: HEAD is not the same as origin/master"
puts "Run `git push` to sync changes."
exit
end
end
end
before "deploy", "deploy:check_revision"
end
And during this process of deploying, here's the error that Capistrano gives me:
SSHKit::Runner::ExecuteError: Exception while executing as deployer#IP: Exception while executing as deployer#IP: bundle exit status: 1
bundle stdout: Nothing written
bundle stderr: master failed to start, check stderr log for details
And here's the unicorn log:
I, [2017-07-26T09:27:41.274475 #21301] INFO -- : Refreshing Gem list
E, [2017-07-26T09:27:44.101407 #21301] ERROR -- : adding listener failed addr=/tmp/unicorn.project.sock (in use)
E, [2017-07-26T09:27:44.101620 #21301] ERROR -- : retrying in 0.5 seconds (4 tries left)
E, [2017-07-26T09:27:44.602753 #21301] ERROR -- : adding listener failed addr=/tmp/unicorn.project.sock (in use)
E, [2017-07-26T09:27:44.603927 #21301] ERROR -- : retrying in 0.5 seconds (3 tries left)
E, [2017-07-26T09:27:45.106551 #21301] ERROR -- : adding listener failed addr=/tmp/unicorn.project.sock (in use)
E, [2017-07-26T09:27:45.107051 #21301] ERROR -- : retrying in 0.5 seconds (2 tries left)
E, [2017-07-26T09:27:45.608434 #21301] ERROR -- : adding listener failed addr=/tmp/unicorn.project.sock (in use)
E, [2017-07-26T09:27:45.608617 #21301] ERROR -- : retrying in 0.5 seconds (1 tries left)
E, [2017-07-26T09:27:46.109480 #21301] ERROR -- : adding listener failed addr=/tmp/unicorn.project.sock (in use)
E, [2017-07-26T09:27:46.109664 #21301] ERROR -- : retrying in 0.5 seconds (0 tries left)
E, [2017-07-26T09:27:46.611021 #21301] ERROR -- : adding listener failed addr=/tmp/unicorn.project.sock (in use)
bundler: failed to load command: unicorn (/home/deployer/apps/project/shared/bundle/ruby/2.4.0/bin/unicorn)
Errno::EADDRINUSE: Address already in use - connect(2) for /tmp/unicorn.project.sock
/home/deployer/apps/project/shared/bundle/ruby/2.4.0/gems/unicorn-5.2.0/lib/unicorn/socket_helper.rb:122:in `initialize'
It says ** Errno::EADDRINUSE: Address already in use - connect(2) for /tmp/unicorn.project.sock** -- however, what does it mean exactly? How to fix it?
I tried to run Unicorn also manually from the server - `bundle exec unicorn -D -c config/unicorn/production.rb -E production`, but only got
> master failed to start, check stderr log for details
that's pointing out on the error message from the log above.
EDIT: Instances of Unicorn
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
rails 2134 0.0 0.5 13620 5640 ? Ss Jul24 0:00 /bin/bash /home/rails/rails_project/.unicorn.sh
rails 2347 0.0 1.6 91052 17136 ? Sl Jul24 0:04 unicorn master -c /etc/unicorn.conf -E production --debug
rails 2349 0.0 7.3 270292 74716 ? Sl Jul24 0:10 unicorn worker[0] -c /etc/unicorn.conf -E production --debug
rails 2352 0.0 7.5 270420 77188 ? Sl Jul24 0:09 unicorn worker[1] -c /etc/unicorn.conf -E production --debug
rails 2354 0.0 7.4 270628 75236 ? Sl Jul24 0:09 unicorn worker[2] -c /etc/unicorn.conf -E production --debug
rails 2358 0.0 7.6 270288 77312 ? Sl Jul24 0:10 unicorn worker[3] -c /etc/unicorn.conf -E production --debug
deployer 9330 0.0 7.9 269032 80364 ? Sl 08:36 0:02 unicorn master -c /home/deployer/apps/project/current/config/unicorn/production.rb -E deployment -D
deployer 9334 0.0 7.2 269560 73800 ? Sl 08:36 0:00 unicorn worker[0] -c /home/deployer/apps/project/current/config/unicorn/production.rb -E deployment -D
deployer 9337 0.0 7.2 269560 73800 ? Sl 08:36 0:00 unicorn worker[1] -c /home/deployer/apps/project/current/config/unicorn/production.rb -E deployment -D
deployer 9340 0.0 7.2 269560 73748 ? Sl 08:36 0:00 unicorn worker[2] -c /home/deployer/apps/project/current/config/unicorn/production.rb -E deployment -D
deployer 24279 0.0 0.1 12948 1080 pts/0 S+ 11:13 0:00 grep --color=auto %CPU\|unicorn

Related

RoR cap deploy with gitlab-runner getting stuck and not triggering a pass response

I have a gitlab-runner that I would like to use to deploy my Ruby on Rails application to a server. I am using the cap deploy function from the Capistrano Gem to deploy to my remote server. When I run the cap deploy function locally it works and finishes correctly however when I run it in my gitlab-runner it just sits and spins once it gets to a certain point, and eventually times out my gitlab-runner when running the Publish stage.
I would like to get this to work correctly so, if anyone has any ideas or could offer guidance I would greatly appreciate it.
.gitlab-ci.yml
before_script:
- ruby -v
- whoami
- which ruby
- bundle install --quiet
- RAILS_ENV=test bundle exec rake db:migrate --quiet
stages:
- citest
- security
- lint
- publish
- sendnotice
Citest:
stage: citest
script:
- rails t
Security:
stage: security
script:
- bundle exec brakeman -z -q
Lint:
stage: lint
script:
- bundle exec rubocop -a
- bundle exec rubocop -P
Publish:
stage: publish
script:
- eval `ssh-agent -s`
- ssh-add
- cap production deploy
SendNotice:
stage: sendnotice
script:
- ruby deploy_notice.rb
gitlab-runner - config.toml
concurrent = 1
check_interval = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "cilinux"
url = "http://example.com/"
token = "ssssssssssssssssssss"
executor = "shell"
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
Here is my gitlab-runner console output it just sits and spins at the last line
Running with gitlab-runner 11.7.0 (8bb608ff)
on cilinux zzBcVZd6
Using Shell executor...
Running on proserver...
Cloning repository...
Cloning into '/home/ci/builds/zzBcVZd6/0/Library/csi'...
Checking out 78654903 as master...
Skipping Git submodules setup
$ ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
$ whoami
ci
$ which ruby
/home/ci/.rvm/rubies/ruby-2.5.1/bin/ruby
$ bundle install --quiet
$ RAILS_ENV=test bundle exec rake db:migrate --quiet
$ eval `ssh-agent -s`
Agent pid 9096
$ ssh-add
Identity added: /home/ci/.ssh/id_rsa (/home/ci/.ssh/id_rsa)
$ cap production deploy
Skipping task `puma:restart'.
Capistrano tasks may only be invoked once. Since task `puma:restart' was previously invoked, invoke("puma:restart") at /home/ci/.rvm/gems/ruby-2.5.1/gems/capistrano3-puma-3.1.1/lib/capistrano/tasks/puma.rake:96 will be skipped.
If you really meant to run this task again, use invoke!("puma:restart")
THIS BEHAVIOR MAY CHANGE IN A FUTURE VERSION OF CAPISTRANO. Please join the conversation here if this affects you.
https://github.com/capistrano/capistrano/issues/1686
INFO [62149be6] Running /usr/bin/env mkdir -p /tmp on 192.168.4.68
INFO [17c17043] Finished in 0.039 seconds with exit status 0 (successful).
INFO Uploading /tmp/git-ssh-CSI-production-ci.sh 100.0%
INFO [2ea27bf0] Running /usr/bin/env chmod 700 /tmp/git-ssh-CSI-production-ci.sh on 192.168.4.68
INFO [ec4b6bc5] Finished in 0.044 seconds with exit status 0 (successful).
INFO [d0d40773] Running /usr/bin/env git ls-remote git#example.com:Library/csi.git HEAD on 192.168.4.68
INFO [1c63f5ce] Finished in 5.555 seconds with exit status 0 (successful).
INFO [0c2cdf20] Running /usr/bin/env mkdir -p /home/deploy/apps/CSI/shared /home/deploy/apps/CSI/releases on 192.168.4.68
INFO [ec964bdd] Finished in 0.010 seconds with exit status 0 (successful).
INFO [0ae11325] Running /usr/bin/env mkdir -p /home/deploy/apps/CSI/shared/public/assets on 192.168.4.68
INFO [d9121d4f] Finished in 0.047 seconds with exit status 0 (successful).
INFO [8806e1ba] Running /usr/bin/env mkdir -p /home/deploy/apps/CSI/shared/config on 192.168.4.68
INFO [f3e1f3c4] Finished in 0.046 seconds with exit status 0 (successful).
INFO The repository mirror is at /home/deploy/apps/CSI/repo
INFO [40d9a02e] Running /usr/bin/env git remote set-url origin git#examplecom:mydomain/csi.git on 192.168.4.68
INFO [8a0a2d6d] Finished in 0.047 seconds with exit status 0 (successful).
INFO [4b634e41] Running /usr/bin/env git remote update --prune on 192.168.4.68
INFO [0efa9ecf] Finished in 5.588 seconds with exit status 0 (successful).
INFO [7cf384f1] Running /usr/bin/env mkdir -p /home/deploy/apps/CSI/releases/20190219192659 on 192.168.4.68
INFO [089f6fd2] Finished in 0.045 seconds with exit status 0 (successful).
INFO [79e639ea] Running /usr/bin/env git archive master | /usr/bin/env tar -x -f - -C /home/deploy/apps/CSI/releases/20190219192659 on 192.168.4.68
INFO [2e47c81b] Finished in 0.060 seconds with exit status 0 (successful).
INFO [132ffc7e] Running /usr/bin/env echo "78654903778db4079706dc5c990292c11fc3bfd6" > REVISION on 192.168.4.68
INFO [e9a299c4] Finished in 0.045 seconds with exit status 0 (successful).
INFO [61aebbb2] Running /usr/bin/env mkdir -p /home/deploy/apps/CSI/releases/20190219192659/config on 192.168.4.68
INFO [c32f803c] Finished in 0.047 seconds with exit status 0 (successful).
INFO [5de3f8d7] Running /usr/bin/env ln -s /home/deploy/apps/CSI/shared/config/master.key /home/deploy/apps/CSI/releases/20190219192659/config/master.key on 192.168.4.68
INFO [fd68c3e6] Finished in 0.044 seconds with exit status 0 (successful).
INFO [ae83c25d] Running /usr/bin/env mkdir -p /home/deploy/apps/CSI/releases/20190219192659/public on 192.168.4.68
INFO [219cde3c] Finished in 0.043 seconds with exit status 0 (successful).
INFO [8daea977] Running /usr/bin/env ln -s /home/deploy/apps/CSI/shared/public/assets /home/deploy/apps/CSI/releases/20190219192659/public/assets on 192.168.4.68
INFO [776bd6d9] Finished in 0.045 seconds with exit status 0 (successful).
INFO [9b6d224d] Running ~/.rvm/bin/rvm default do bundle install --path /home/deploy/apps/CSI/shared/bundle --jobs 4 --without development test --deployment --quiet on 192.168.4.68
INFO [a7a6eab9] Finished in 12.598 seconds with exit status 0 (successful).
INFO [aa1ce450] Running ~/.rvm/bin/rvm default do bundle exec rake assets:precompile on 192.168.4.68
INFO [361e893b] Finished in 26.688 seconds with exit status 0 (successful).
INFO [df357b56] Running /usr/bin/env mkdir -p /home/deploy/apps/CSI/releases/20190219192659/assets_manifest_backup on 192.168.4.68
INFO [4b7c3340] Finished in 0.048 seconds with exit status 0 (successful).
INFO [a7d45495] Running /usr/bin/env cp /home/deploy/apps/CSI/releases/20190219192659/public/assets/.sprockets-manifest-6c09bafc512e6d668d8d88812378e77c.json /home/deploy/apps/CSI/releases/20190219192659/assets_manifest_backup on 192.168.4.68
INFO [b6ebf727] Finished in 0.047 seconds with exit status 0 (successful).
INFO [deploy:migrate] Run `rake db:migrate`
INFO [5e0d430c] Running ~/.rvm/bin/rvm default do bundle exec rake db:migrate on 192.168.4.68
INFO [64374921] Finished in 7.839 seconds with exit status 0 (successful).
INFO [3e852c97] Running /usr/bin/env ln -s /home/deploy/apps/CSI/releases/20190219192659 /home/deploy/apps/CSI/releases/current on 192.168.4.68
INFO [10e08783] Finished in 0.048 seconds with exit status 0 (successful).
INFO [36c88135] Running /usr/bin/env mv /home/deploy/apps/CSI/releases/current /home/deploy/apps/CSI on 192.168.4.68
INFO [0408953b] Finished in 0.046 seconds with exit status 0 (successful).
INFO Keeping 3 of 4 deployed releases on 192.168.4.68
INFO [44ecd2da] Running /usr/bin/env rm -rf /home/deploy/apps/CSI/releases/20190219173006 on 192.168.4.68
INFO [baa3970a] Finished in 0.149 seconds with exit status 0 (successful).
INFO [b90baafa] Running ~/.rvm/bin/rvm default do bundle exec pumactl -S /home/deploy/apps/CSI/shared/tmp/pids/puma.state -F /home/deploy/apps/CSI/shared/puma.rb restart on 192.168.4.68
INFO [bcbdb282] Finished in 1.102 seconds with exit status 0 (successful).
INFO [da13ee51] Running /usr/bin/env echo "Branch master (at 78654903778db4079706dc5c990292c11fc3bfd6) deployed as release 20190219192659 by ci" >> /home/deploy/apps/CSI/revisions.log on 192.168.4.68
INFO [6a780fb0] Finished in 0.046 seconds with exit status 0 (successful).
//SITS AND SPINS HERE
cap deploy.rb
# frozen_string_literal: true
server '192.168.4.68', roles: %i[web app db], primary: true
set :repo_url, 'git#codelib.pennunited.com:PennUnited_Code_Library/csi.git'
set :application, 'CSI'
set :user, 'deploy'
set :puma_threads, [4, 16]
set :puma_workers, 4
set :pty, true
set :use_sudo, false
set :stage, :production
set :deploy_via, :remote_cache
set :deploy_to, "/home/#{fetch(:user)}/apps/#{fetch(:application)}"
set :puma_bind, "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock"
set :puma_state, "#{shared_path}/tmp/pids/puma.state"
set :puma_pid, "#{shared_path}/tmp/pids/puma.pid"
set :puma_access_log, "#{release_path}/log/puma.error.log"
set :puma_error_log, "#{release_path}/log/puma.access.log"
set :ssh_options, forward_agent: true, user: fetch(:user), keys: %w[~/.ssh/id_rsa.pub], keepalive: true
set :puma_preload_app, true
set :puma_worker_timeout, nil
set :puma_init_active_record, true # Change to true if using ActiveRecord
## Defaults:
set :branch, :master
set :format, :pretty
set :log_level, :info
set :keep_releases, 3
## Linked Files & Directories (Default None):
set :linked_files, %w[config/master.key]
# set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
namespace :puma do
desc 'Create Directories for Puma Pids and Socket'
task :make_dirs do
on roles(:app) do
execute "mkdir #{shared_path}/tmp/sockets -p"
execute "mkdir #{shared_path}/tmp/pids -p"
end
end
namespace :deploy do
desc "Make sure local git is in sync with remote."
task :check_revision do
on roles(:app) do
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts "WARNING: HEAD is not the same as origin/master"
puts "Run `git push` to sync changes."
exit
end
end
end
desc 'Initial Deploy'
task :initial do
on roles(:app) do
before 'deploy:restart', 'puma:start'
invoke 'deploy'
end
end
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
invoke 'puma:restart'
end
end
before :starting, :check_revision
after :finishing, :compile_assets
after :finishing, :cleanup
after :finishing, :restart
end
before :start, :make_dirs
end
I was helped by removal of the keys added to ssh-agent (ssh-agent - k) after cap production deploy, job ceased to hang

"bundle exec thin start -C config/thin.yml" does not start thin

in attempt to deploy rails app to server I faced problem that 'thin' does't stars when I try do star it with cap production deploy:start. What is realy strange, than it hasn't any errors.
After this I try do it on deplyment server
env RAILS_ENV=production bundle exec thin start -C config/thin.yml
Starting server on /home/deployer/app/current/tmp/sockets/thin.0.sock ...
Starting server on /home/deployer/app/current/tmp/sockets/thin.1.sock ...
ls /home/deployer/app/current/tmp/sockets/
ps -aux | grep thin
root 16769 0.0 0.1 15468 908 pts/0 S 11:34 0:00 grep --color=auto thin
thin.yml
chdir: /home/deployer/app/current
environment: production
timeout: 30
log: /home/deployer/app/current/log/thin.log
pid: /home/deployer/app/current/tmp/pids/thin.pid
socket: /home/deployer/app/current/tmp/sockets/thin.sock
max_conns: 1024
max_persistent_conns: 10
require: []
wait: 30
servers: 2
daemonize: true
What is gone wrong?
In production.log only migrations
bundle exec thin start -C config/thin.yml &
returns
Starting server on /home/deployer/app/current/tmp/sockets/thin.0.sock ...
Starting server on /home/deployer/app/current/tmp/sockets/thin.1.sock ...
'bundle exec thin start -C confiā€¦' has ended
Answer
Okey, answer was log/thin.0.log there are some errors in code
You need to demonize thin for running it in production by adding &. Try this:
RAILS_ENV=production bundle exec thin start -C config/thin.yml &

Capistrano changes Rails.root path

Rails 3.2
ruby 1.9.3
that's where my releases are stored on server
deploy#production-web:/var/www/mrd_production/releases$ ls
20150729224354 20150730101637 20150730110152 20150730122336
that's where my current productions are stored in server
deploy#production-web:/var/www/mrd_production/current$ ls
app config.ru Gemfile public spec
assets_manifest_backup db Gemfile.lock Rakefile tmp
bin doc Guardfile README Vagrantfile
Capfile features lib REVISION
config fixtures log script
So, I am using capistrano for deploy:
bundle exec cap production deploy
deploy.rb
lock '3.4.0'
set :application, 's2yd'
set :repo_url, 'git#bitbucket.org:mrdelivery/mxad-mr.-delivery.git'
set :keep_releases, 3
set :log_level, :info
set :linked_files, %w{.env}
set :linked_dirs, %w{public/system}
set :migration_role, :app
set :rbenv_type, :user
set :rbenv_ruby, '1.9.3-p484'
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 3 do
execute :touch, release_path.join('tmp/restart.txt')
end
end
after :publishing, :restart
end
namespace :rails do
desc 'Open the rails console on the primary remote server'
task :console do
on roles(:app), primary: true do |host|
command = "cd #{deploy_to}/current && /home/#{host.user}/.rbenv/shims/bundle exec rails console #{fetch(:stage)}"
exec "ssh -l #{host.user} #{host.hostname} -p #{host.port || 22} -t 'cd #{deploy_to}/current && #{command}'"
end
end
end
config/deploy/production.rb
set :deploy_to, '/var/www/mrd_production' # Change this to match your deploy_dir in vars/app.yml
server '104.130.31.250', user: 'deploy', roles: %w{web app}
namespace :deploy do
desc 'generate_ymls'
task :generate_ymls do
on roles(:app) do
upload! File.expand_path('../../database.yml.production', __FILE__), "#{release_path}/config/database.yml"
end
end
end
before "deploy:migrate", 'deploy:generate_ymls'
After deploy, I enter the folder /var/www/mrd_production/current where my app resides...
deploy#production-web:/var/www/mrd_production/current$ RAILS_ENV=production rails c
irb(main):001:0> Rails.root
=> #<Pathname:/var/www/mrd_production/releases/20150730122336>
irb(main):002:0>
The problem is Rails.root points to /var/www/mrd_production/releases/20150730122336 but I need it to be pointed to the folder where I am in /var/www/mrd_production/current
How can I change Rails.root?
EDIT
bundle exec cap production deploy log:
INFO [8ba777a3] Running /usr/bin/env mkdir -p /tmp/s2yd/ as deploy#<server-ip>
INFO [8ba777a3] Finished in 0.269 seconds with exit status 0 (successful).
INFO Uploading /tmp/s2yd/git-ssh.sh 100.0%
INFO [867961a0] Running /usr/bin/env chmod +x /tmp/s2yd/git-ssh.sh as deploy#<server-ip>
INFO [867961a0] Finished in 0.267 seconds with exit status 0 (successful).
INFO [6be86a24] Running /usr/bin/env git ls-remote --heads git#bitbucket.org:mrdelivery/mxad-mr.-delivery.git as deploy#<server-ip>
INFO [6be86a24] Finished in 0.900 seconds with exit status 0 (successful).
INFO [e6f437c4] Running /usr/bin/env mkdir -p /var/www/mrd_production/shared /var/www/mrd_production/releases as deploy#<server-ip>
INFO [e6f437c4] Finished in 0.334 seconds with exit status 0 (successful).
INFO [37165e60] Running /usr/bin/env mkdir -p /var/www/mrd_production/shared/public/system as deploy#<server-ip>
INFO [37165e60] Finished in 0.266 seconds with exit status 0 (successful).
INFO [3c9b9d10] Running /usr/bin/env mkdir -p /var/www/mrd_production/shared as deploy#<server-ip>
INFO [3c9b9d10] Finished in 0.265 seconds with exit status 0 (successful).
INFO The repository mirror is at /var/www/mrd_production/repo
INFO [0002d83c] Running /usr/bin/env git remote update as deploy#<server-ip>
INFO [0002d83c] Finished in 2.495 seconds with exit status 0 (successful).
INFO [869b66a7] Running /usr/bin/env mkdir -p /var/www/mrd_production/releases/20150730220743 as deploy#<server-ip>
INFO [869b66a7] Finished in 0.271 seconds with exit status 0 (successful).
INFO [1b9871ea] Running /usr/bin/env git archive master | tar -x -f - -C /var/www/mrd_production/releases/20150730220743 as deploy#<server-ip>
INFO [1b9871ea] Finished in 0.528 seconds with exit status 0 (successful).
INFO [c28030f4] Running /usr/bin/env echo "6ce11b0" >> REVISION as deploy#<server-ip>
INFO [c28030f4] Finished in 0.266 seconds with exit status 0 (successful).
INFO [0af78fb4] Running /usr/bin/env mkdir -p /var/www/mrd_production/releases/20150730220743 as deploy#<server-ip>
INFO [0af78fb4] Finished in 0.273 seconds with exit status 0 (successful).
INFO [86aef2af] Running /usr/bin/env ln -s /var/www/mrd_production/shared/.env /var/www/mrd_production/releases/20150730220743/.env as deploy#<server-ip>
INFO [86aef2af] Finished in 0.267 seconds with exit status 0 (successful).
INFO [80cc46a1] Running /usr/bin/env mkdir -p /var/www/mrd_production/releases/20150730220743/public as deploy#<server-ip>
INFO [80cc46a1] Finished in 0.268 seconds with exit status 0 (successful).
INFO [bbfef99c] Running /usr/bin/env rm -rf /var/www/mrd_production/releases/20150730220743/public/system as deploy#<server-ip>
INFO [bbfef99c] Finished in 0.270 seconds with exit status 0 (successful).
INFO [66f90632] Running /usr/bin/env ln -s /var/www/mrd_production/shared/public/system /var/www/mrd_production/releases/20150730220743/public/system as deploy#<server-ip>
INFO [66f90632] Finished in 0.268 seconds with exit status 0 (successful).
INFO [e63b7bd2] Running ~/.rbenv/bin/rbenv exec bundle install --path /var/www/mrd_production/shared/bundle --without development test --deployment --quiet as deploy#<server-ip>
INFO [e63b7bd2] Finished in 0.701 seconds with exit status 0 (successful).
INFO [89bd1320] Running ~/.rbenv/bin/rbenv exec bundle exec rake assets:precompile as deploy#<server-ip>
INFO [89bd1320] Finished in 15.517 seconds with exit status 0 (successful).
INFO [8e1765be] Running /usr/bin/env mkdir -p /var/www/mrd_production/releases/20150730220743/assets_manifest_backup as deploy#<server-ip>
INFO [8e1765be] Finished in 0.266 seconds with exit status 0 (successful).
INFO [30408583] Running /usr/bin/env cp /var/www/mrd_production/releases/20150730220743/public/assets/manifest.yml /var/www/mrd_production/releases/20150730220743/assets_manifest_backup as deploy#<server-ip>
INFO [30408583] Finished in 0.270 seconds with exit status 0 (successful).
INFO Uploading /home/drobazko/www/mxad-mr.-delivery/config/database.yml.production 100.0%
INFO [deploy:migrate] Run `rake db:migrate`
INFO [e0eabe3f] Running ~/.rbenv/bin/rbenv exec bundle exec rake db:migrate as deploy#<server-ip>
INFO [e0eabe3f] Finished in 14.161 seconds with exit status 0 (successful).
INFO [36cbdf44] Running /usr/bin/env ln -s /var/www/mrd_production/releases/20150730220743 /var/www/mrd_production/releases/current as deploy#<server-ip>
INFO [36cbdf44] Finished in 0.270 seconds with exit status 0 (successful).
INFO [f261e897] Running /usr/bin/env mv /var/www/mrd_production/releases/current /var/www/mrd_production as deploy#<server-ip>
INFO [f261e897] Finished in 0.266 seconds with exit status 0 (successful).
INFO [47336a26] Running /usr/bin/env touch /var/www/mrd_production/releases/20150730220743/tmp/restart.txt as deploy#<server-ip>
INFO [47336a26] Finished in 0.267 seconds with exit status 0 (successful).
INFO Keeping 3 of 4 deployed releases on <server-ip>
INFO [81cb4cbd] Running /usr/bin/env rm -rf /var/www/mrd_production/releases/20150730162232 as deploy#<server-ip>
INFO [81cb4cbd] Finished in 0.384 seconds with exit status 0 (successful).
INFO [673ac3d6] Running /usr/bin/env echo "Branch master (at 6ce11b0) deployed as release 20150730220743 by drobazko" >> /var/www/mrd_production/revisions.log as deploy#<server-ip>
If I'm not mistaken, when Capistrano makes the current folder it is actually a "shortcut" (for lack of a better term) to the most recent release (perhaps symlinked directory is better).
I don't know of a link to their doc that describes what I'm talking about, but I'm fairly certain that you should be fine with whatever you'd like to run.
EDIT:
this page describes the structure of the capistrano directory hierarchy. If you look specifically at the section on current it reads:
current is a symlink pointing to the latest release. This symlink is updated at the end of a successful deployment. If the deployment fails in any step the current symlink still points to the old release.
releases holds all deployments in a timestamped folder. These folders are the target of the current symlink.
Looks like you're still in the "old" current symlink after you deployed. cd out of current then back in, then jump back into the Rails console and you should be in the new correct release path.
This line is showing that the symlinking of current to the latest release directory happened correctly
INFO [36cbdf44] Running /usr/bin/env ln -s /var/www/mrd_production/releases/20150730220743 /var/www/mrd_production/releases/current as deploy#<server-ip>
You can't stay in current while the deploy happens else the symlink is change out from under you and the shell doesn't know.
Other things of note:
To open a shell like you are in deploy.rb, just use https://github.com/marshall-lee/capistrano-shell.
Additionally don't create shell commands from string concatenation, use the DSL, for example.
task :do_something do
on roles(:web) do
within release_path do
with rails_env: fetch(:rails_env) do
execute :rake, 'simple:task'
end
end
end
end

monit: failed to restart

I am using monit for sidekiq
while I am running the monit log file, it is showing the error.
[EDT Jun 18 09:50:11] error : 'sidekiq_site' process is not running
[EDT Jun 18 09:50:11] info : 'sidekiq_site' trying to restart
[EDT Jun 18 09:50:11] info : 'sidekiq_site' start: /bin/bash
[EDT Jun 18 09:51:41] error : 'sidekiq_site' failed to start
/etc/monit/conf.d/sidekiq.conf
check process sidekiq_site
with pidfile /var/www/project/shared/pids/sidekiq.pid
start program = "bash -c 'cd /var/www/project/current ; RAILS_ENV=production bundle exec sidekiq --index 0 --pidfile /var/www/project/shared/pids/sidekiq.pid --environment production --logfile /var/www/project/shared/log/sidekiq.log --daemon'" as uid root and gid root with timeout 90 seconds
stop program = "bash -c 'if [ -d /var/www/project/current ] && [ -f /var/www/project/shared/pids/sidekiq.pid ] && kill -0 `cat /var/www/project/shared/pids/sidekiq.pid`> /dev/null 2>&1; then cd /var/www/project/current && bundle exec sidekiqctl stop /var/www/project/shared/pids/sidekiq.pid 1 ; else echo 'Sidekiq is not running'; fi'" as uid root and gid root
if totalmem is greater than 200 MB for 2 cycles then restart # eating up memory?
group site_sidekiq
/etc/monit/monitrc
set daemon 30
set logfile /var/log/monit.log
set idfile /var/lib/monit/id
set statefile /var/lib/monit/state
set eventqueue
basedir /var/lib/monit/events
slots 100
set httpd port 2812
allow admin:""
set httpd port 2812 and
use address xx.xxx.xx.xx
allow xx.xx.xx.xx
check system trrm_server
if loadavg(5min) > 2 for 2 cycles then alert
if memory > 75% for 2 cycles then alert
if cpu(user) > 75% for 2 cycles then alert
include /etc/monit/conf.d/*
When running a start/stop event in monit there is no path variable set, therefore all programs must have absolute paths, even your call to bash.
No environment variables are used by Monit

Capistrano Attempting To Create /public Directory

I'm currently in the process of attempting my first Rails deployment using Capistrano, and I've run into a roadblock I haven't been able to overcome. During the cap deploy I'm getting an error "mkdir: cannot create directory/public'`".
Pertinent Details:
Rails Version: 3.2.6
Capistrano Version: 2.13.5
Running on Dreamhost
I'm precompiling my assets (I suspect this is part of the problem), so I've got load 'deploy/assets' in my Capfile.
I've followed the directions here: http://wiki.dreamhost.com/Capistrano for the most part, as well as scouring the web for a number of other articles on Capistrano.
deploy.rb
require "bundler/capistrano"
ssh_options[:forward_agent] = true
ssh_options[File.join(ENV["HOME"], ".ssh", "id_rsa-dreamhost")]
set :application, "<app>"
set :repository, "git#bitbucket.org:<gituser>/#{application}.git"
set :server_name, "<host>"
set :scm, :git # You can set :scm explicitly or Capistrano will make an intelligent guess based on known version control directory names
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
set :checkout, "export"
set :deploy_via, :remote_cache
set :branch, "master"
set :base_path, "/home/<user>/<domain>"
set :deploy_to, "#{base_path}/#{application}"
set :keep_releases, 3
set :user, '<user>'
set :runner, '<user>'
set :use_sudo, false
default_run_options[:pty] = true
set :shared_path, "/home/<user>/<shared_folder>"
set :release_path, "#{base_path}/#{application}"
role :web, "<host>" # Your HTTP server, Apache/etc
role :app, "<host>" # This may be the same as your `Web` server
role :db, "<host>", :primary => true # This is where Rails migrations will run
# if you want to clean up old releases on each deploy uncomment this:
# after "deploy:restart", "deploy:cleanup"
# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts
# If you are using Passenger mod_rails uncomment this:
namespace :deploy do
task :start do ; end
task :stop do ; end
desc "Restart the app by touching the restart.txt file."
task :restart, :roles => :app, :except => { :no_release => true } do
run "touch #{File.join(current_path,'tmp','restart.txt')}"
end
desc "Update the environment-specific files from the shared folder."
task :symlink_shared, :roles => [:app] do
run "ln -s #{shared_path}/app_config.yml #{release_path}/config/"
run "rm #{release_path}/config/database.yml"
run "ln -s #{shared_path}/database.yml #{release_path}/config/"
run "rm #{release_path}/public/.htaccess"
run "ln -s #{shared_path}/.htaccess #{release_path}/public/"
end
end
before "deploy:restart", "deploy:symlink_shared"
after "deploy:update_code", "deploy:migrate"
Output of cap deploy:setup
* 2012-12-23 16:49:27 executing `deploy:setup'
* executing "mkdir -p /home/<user>/<domain>/<app> /home/<user>/<domain>/<app>/releases /home/<user>/<shared_folder> /home/<user>/<shared_folder>/system /home/<user>/<shared_folder>/log /home/<user>/<shared_folder>/pids"
servers: ["<host>"]
[<host>] executing command
command finished in 263ms
* executing "chmod g+w /home/<user>/<domain>/<app> /home/<user>/<domain>/<app>/releases /home/<user>/<shared_folder> /home/<user>/<shared_folder>/system /home/<user>/<shared_folder>/log /home/<user>/<shared_folder>/pids"
servers: ["<host>"]
[<host>] executing command
command finished in 261ms
Output of cap deploy:check
* 2012-12-23 16:49:45 executing `deploy:check'
* executing "test -d /home/<user>/<domain>/<app>/releases"
servers: ["<host>"]
[<host>] executing command
command finished in 265ms
* executing "test -w /home/<user>/<domain>/<app>"
servers: ["<host>"]
[<host>] executing command
command finished in 256ms
* executing "test -w /home/<user>/<domain>/<app>/releases"
servers: ["<host>"]
[<host>] executing command
command finished in 256ms
* executing "which git"
servers: ["<host>"]
[<host>] executing command
command finished in 259ms
* executing "test -w /home/<user>/<shared_folder>"
servers: ["<host>"]
[<host>] executing command
command finished in 263ms
You appear to have all necessary dependencies installed
Output of cap:deploy
* 2012-12-23 16:51:41 executing `deploy'
* 2012-12-23 16:51:41 executing `deploy:update'
** transaction: start
* 2012-12-23 16:51:41 executing `deploy:update_code'
updating the cached checkout on all servers
executing locally: "git ls-remote git#bitbucket.org:<gituser>/<app>.git master"
command finished in 1102ms
* executing "if [ -d /home/<user>/<shared_folder>/cached-copy ]; then cd /home/<user>/<shared_folder>/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard 42dfb6a3f529e2293192f5e22c3214b7da55c9b4 && git clean -q -d -x -f; else git clone -q git#bitbucket.org:<gituser>/<app>.git /home/<user>/<shared_folder>/cached-copy && cd /home/<user>/<shared_folder>/cached-copy && git checkout -q -b deploy 42dfb6a3f529e2293192f5e22c3214b7da55c9b4; fi"
servers: ["<host>"]
[<host>] executing command
command finished in 3233ms
copying the cached version to /home/<user>/<domain>/<app>
* executing "cp -RPp /home/<user>/<shared_folder>/cached-copy /home/<user>/<domain>/<app> && (echo 42dfb6a3f529e2293192f5e22c3214b7da55c9b4 > /home/<user>/<domain>/<app>/REVISION)"
servers: ["<host>"]
[<host>] executing command
command finished in 338ms
* 2012-12-23 16:51:47 executing `deploy:finalize_update'
triggering before callbacks for `deploy:finalize_update'
* 2012-12-23 16:51:47 executing `deploy:assets:symlink'
* executing "ls -x /home/<user>/<domain>/<app>/releases"
servers: ["<host>"]
[<host>] executing command
command finished in 252ms
* executing "rm -rf /public/assets &&\\\n mkdir -p /public &&\\\n mkdir -p /home/<user>/<shared_folder>/assets &&\\\n ln -s /home/<user>/<shared_folder>/assets /public/assets"
servers: ["<host>"]
[<host>] executing command
** [out :: <host>] mkdir: cannot create directory `/public'
** [out :: <host>] : Permission denied
command finished in 268ms
*** [deploy:update_code] rolling back
* executing "rm -rf /home/<user>/<domain>/<app>; true"
servers: ["<host>"]
[<host>] executing command
command finished in 265ms
failed: "sh -c 'rm -rf /public/assets &&\\\n mkdir -p /public &&\\\n mkdir -p /home/<user>/<shared_folder>/assets &&\\\n ln -s /home/<user>/<shared_folder>/assets /public/assets'" on <host>
You can see the Permission denied error near the bottom of the output, as well as the failed shell command at the end. I can't figure out why it is attempting to do anything with /public, as I would expect a relative path to public in my web folder, rather than referring to what appears to be a public folder on root. I feel like I'm missing a variable reference somewhere which should get prepended to the mkdir command, but none of of the documentation I've read indicates this.
I'd appreciate any help I can get, and thanks in advance.
Please don't set release_path and shared_path by yourself. Let Capistrano figure it out automatically.
But you should set deploy_to correctly:
set :deploy_to, "/home/<user>/<domain>/<application>"
Also be careful with variables. The set syntax of Capistrano doesn't mean the variables are available for substitution. Your problem occurs because of "#{base_path}/" is nil and evalutates to "/".
Find out more on the configuration wiki of Capistrano.

Resources