Topic: Can not "restart" Unicorn, have to kill then "start"

(Wow, the software on railsforum.com made a mess of my post. All the newlines were removed, and then most of the post was removed. What is up with that? I will try to edit.)

We have a new dev server that runs Nginx and Unicorn.

We have all our code in Github.

I am doing development locally on my Mac.

We are using Rails 3.1.

One of the teams in my company set up a project on the new server, and it is running perfectly.

I was asked to set up a 2nd project on the new server. I set it up mostly by copying the config files from the first project. I only changed paths, the names of applications, and the port numbers in use. In theory, every time I want to deploy my code from Github to the server, all I should need to type is "cap deploy". However, when I do so, the code deploys, and Unicorn is killed and then restarted, but somehow it does not restart correctly. The new project only returns a 500 error at that point. There is no useful error messages in any log that I can find.

To get the site going after "cap deploy" I need to ssh to the server and find the pid of the master Unicorn process running the site and then manually "kill" it. Then I can type "cap deploy:start" on my local machine, and everything works perfectly. But do I need to manually kill Unicorn?

Here is my deploy output (with a few changes to disguise the name of the site):

ye-wangs-imac:website ye$ cap deploy
    triggering start callbacks for `deploy'
  * executing `multistage:ensure'
*** Defaulting to `staging'
  * executing `staging'
  * executing `deploy'
  * executing `deploy:update'
** transaction: start
  * executing `deploy:update_code'
    executing locally: "git ls-remote git@github.com:travel/website.git master"
    command finished in 1217ms
  * executing "git clone git@github.com:travel/website.git /opt/www/stsite/releases/20111016143302 && cd /opt/www/stsite/releases/20111016143302 && git checkout -b deploy d87c28b213ae275f4f51564f2d3d70d55f866fdd && (echo d87c28b213ae275f4f51564f2d3d70d55f866fdd > /opt/www/stsite/releases/20111016143302/REVISION)"
    servers: ["11.22.333.4"]
    [11.22.333.4] executing command
** [11.22.333.4 :: out] Initialized empty Git repository in /opt/www/stsite/releases/20111016143302/.git/
** [11.22.333.4 :: out] remote: Counting objects: 816, done.
remote: Compressing objects:  80% (331/413)   
remote: Compressing objects: 100% (413/413), done.
Receiving objects:   7% (58/816)     
Receiving objects:  11% (90/816)   ng objects:   8% (66/816)   
Receiving objects:  47% (384/816)   g objects:  12% (98/816)   
remote: Total 816 (delta 314), reused 799 (delta 297)
Receiving objects: 100% (816/816), 209.85 KiB, done.
** Resolving deltas:   0% (0/314)
Resolving deltas: 100% (314/314), done.eltas:  13% (43/314)   
** [11.22.333.4 :: out] Switched to a new branch 'deploy'
    command finished in 1826ms
  * executing `deploy:finalize_update'
    triggering before callbacks for `deploy:finalize_update'
  * executing `deploy:assets:symlink'
  * executing "rm -rf /opt/www/stsite/releases/20111016143302/public/assets &&\\\n        mkdir -p /opt/www/stsite/releases/20111016143302/public &&\\\n        mkdir -p /opt/www/stsite/shared/assets &&\\\n        ln -s /opt/www/stsite/shared/assets /opt/www/stsite/releases/20111016143302/public/assets"
    servers: ["11.22.333.4"]
    [11.22.333.4] executing command
    command finished in 241ms
  * executing "chmod -R g+w /opt/www/stsite/releases/20111016143302"
    servers: ["11.22.333.4"]
    [11.22.333.4] executing command
    command finished in 235ms
  * executing "rm -rf /opt/www/stsite/releases/20111016143302/log /opt/www/stsite/releases/20111016143302/public/system /opt/www/stsite/releases/20111016143302/tmp/pids &&\\\n      mkdir -p /opt/www/stsite/releases/20111016143302/public &&\\\n      mkdir -p /opt/www/stsite/releases/20111016143302/tmp &&\\\n      ln -s /opt/www/stsite/shared/log /opt/www/stsite/releases/20111016143302/log &&\\\n      ln -s /opt/www/stsite/shared/system /opt/www/stsite/releases/20111016143302/public/system &&\\\n      ln -s /opt/www/stsite/shared/pids /opt/www/stsite/releases/20111016143302/tmp/pids"
    servers: ["11.22.333.4"]
    [11.22.333.4] executing command
    command finished in 244ms
    triggering after callbacks for `deploy:finalize_update'
  * executing `deploy:db:symlink'
  * executing "ln -nfs /opt/www/stsite/shared/config/database.yml /opt/www/stsite/releases/20111016143302/config/database.yml"
    servers: ["11.22.333.4"]
    [11.22.333.4] executing command
    command finished in 233ms
  * executing `bundle:install'
  * executing "ls -x /opt/www/stsite/releases"
    servers: ["11.22.333.4"]
    [11.22.333.4] executing command
    command finished in 235ms
  * executing "cd /opt/www/stsite/releases/20111016143302 && bundle install --gemfile /opt/www/stsite/releases/20111016143302/Gemfile --path /opt/www/stsite/shared/bundle --deployment --quiet --without development test"
    servers: ["11.22.333.4"]
    [11.22.333.4] executing command
    command finished in 905ms
    triggering after callbacks for `deploy:update_code'
  * executing `deploy:assets:precompile'
  * executing "cd /opt/www/stsite/releases/20111016143302 && bundle exec rake RAILS_ENV=staging RAILS_GROUPS=assets assets:precompile"
    servers: ["11.22.333.4"]
    [11.22.333.4] executing command
** [out :: 11.22.333.4] /opt/www/stsite/shared/bundle/ruby/1.9.1/gems/rack-1.3.4/lib/rack/backports/uri/common_192.rb:53: warning: already initialized constant WFKV_
** [out :: 11.22.333.4] /usr/local/rvm/rubies/ruby-1.9.2-p290/bin/ruby /opt/www/stsite/shared/bundle/ruby/1.9.1/bin/rake assets:precompile:nondigest RAILS_ENV=staging RAILS_GROUPS=assets
** [out :: 11.22.333.4] /opt/www/stsite/shared/bundle/ruby/1.9.1/gems/rack-1.3.4/lib/rack/backports/uri/common_192.rb:53: warning: already initialized constant WFKV_
    command finished in 7141ms
  * executing `deploy:symlink'
  * executing "rm -f /opt/www/stsite/current && ln -s /opt/www/stsite/releases/20111016143302 /opt/www/stsite/current"
    servers: ["11.22.333.4"]
    [11.22.333.4] executing command
    command finished in 234ms
** transaction: commit
  * executing `deploy:restart'
  * executing "kill -USR2 `cat /opt/www/stsite/current/tmp/pids/unicorn.pid`"
    servers: ["11.22.333.4"]
    [11.22.333.4] executing command
    command finished in 231ms
    triggering after callbacks for `deploy'
  * executing `rvm:trust_rvmrc'
  * executing "rvm rvmrc trust /opt/www/stsite/releases/20111016143302"
    servers: ["11.22.333.4"]
    [11.22.333.4] executing command
** [out :: 11.22.333.4] cat: /opt/www/stsite/releases/20111016143302/.rvmrc: No such file or directory
** [out :: 11.22.333.4] cat: /opt/www/stsite/releases/20111016143302/.rvmrc: No such file or directory
** [out :: 11.22.333.4] Marked /opt/www/stsite/releases/20111016143302/.rvmrc as trusted
    command finished in 327ms


Then I need to do:


ye-wangs-imac:website ye$ cap deploy:start
    triggering start callbacks for `deploy:start'
  * executing `multistage:ensure'
*** Defaulting to `staging'
  * executing `staging'
  * executing `deploy:start'
  * executing "cd /opt/www/stsite/current; bundle exec unicorn_rails -c /opt/www/stsite/current/config/unicorn/staging.rb -E staging -D"
    servers: ["11.22.333.4"]
    [11.22.333.4] executing command
** [out :: 11.22.333.4] /opt/www/stsite/shared/bundle/ruby/1.9.1/gems/rack-1.3.4/lib/rack/backports/uri/common_192.rb:53: warning: already initialized constant WFKV_
    command finished in 4838ms

Last edited by lkrubner (2011-10-16 10:52:07)

Re: Can not "restart" Unicorn, have to kill then "start"

It sounds like a permissions thing.
Are you sure your deployment recipe is good?
Can you get one of your colleagues to look at it?

What you want and what you need are too often not the same thing!
When your head is hurting from trying to solve a problem, stop standing on it. When you are the right way up you will see the problem differently and you just might find the solution.
(Quote by me 15th July 2009)