task :restart_unicorn, :except => { :no_release => true } do
run "#{try_sudo} kill -s USR2 $(cat /var/www/app_name/shared/pids/unicorn.pid)"
end
When I do sudo kill -s USR2 $(cat /var/www/app_name/shared/pids/unicorn.pid)
on the server, what happens is that a new unicorn master is created, and the old one has (old)
appended to its name. The old one is never killed, but even if I kill it on my own, the new unicorn instance is still showing the old code from before my deployment. The new instance has the same creation time as the old -- its as if its just being duplicated. If I stop the instance, and the start it again, it works, but I would like to be able to do zero-downtime deploys.
Any help is appreciated.
EDIT
After following the sugest Ilya O., I created a capistrano task that does this:
old_pid = get_pid('/var/www/appname/shared/pids/unicorn.pid')
run "#{try_sudo} kill -s SIGUSR2 $(cat /var/www/appname/shared/pids/unicorn.pid)"
/var/www/app/current/tmp/pids/unicorn.pid)"
run "#{try_sudo} kill -s SIGWINCH #{old_pid}"
This runs SIGUSR2 on the pid, and kills the old unicorn process. The problem is that all my application server is never updated to my recently deployed code, this task just seems to copy my the old unicorn enviroment into a new process. It works fine if I simply kill the master process and then start unicorn fresh again, but then there is a minute or so of dropped requests.
We are using Unicorn as sync mechanism for items between the dev machines.Currently we are manually deploying the yml files to different environments like SIT, UAT and PROD. Is it possible to use Stack Exchange Network
How to use Unicorn for Content Staging 5 How to do content Staging in Sitecore when using Unicorn 1 Copy just new content and BLOBs from Live Master to another Environment 2 Unicorn Sync for Sitecore SXA site adding only new items 1
Usage is simple, just run Magic Unicorn (ensure Metasploit is installed if using Metasploit methods and in the right path) and magic unicorn will automatically generate a powershell command that you need to simply cut and paste the powershell code into a command line window or through a payload delivery system.
Do you have preload_app
set to true in your Unicorn config? If so, you need to send SIGUSR2 and then SIGQUIT to the original master process after the new process are up and running.
What may also be happening is that the original master process has died but the children are still serving requests. You can try sending SIGUSR2, and after the new master process has spawned, send SIGWINCH (to the old master) to kill the old unicorn child processes, and then SIGQUIT on the old master process. You should now have only the "new" unicorn processes serving requests.
EDIT: Try doing SIGQUIT instead of SIGWINCH. I think the old process might be spawning workers after SIGWINCH.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With