Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do rolling restart with Unicorn?

Suppose I make a little change to my rails app such as changing the html layout. How would I do a rolling restart with Unicorn? Effectively one would like to bring up unicorn processes(or workers instead?) for the newest version of the rails app and then switch traffic from the old unicorn processes/workers to the new ones atomically. From Google searches I couldn't quite get a concrete definitive explanation of how to do this and all the gotchas surrounding it.

like image 853
user782220 Avatar asked Oct 21 '12 05:10

user782220


1 Answers

There are multiple methods, but one of them is as follows:

  • Send SIGUSR2 to the master process. Unicorn start a new master with worker processes, that live in parallel with your old master and old worker processes.
  • Wait until the new master and worker processes have started.
  • Kill the old master.

Source: http://unicorn.bogomips.org/SIGNALS.html

This is not very memory friendly though. You temporarily need twice the memory usage.

Phusion Passenger Enterprise supports rolling restarts (along with other cool features) but it restarts processes one-by-one and so does not need as much memory. It is possible to script one-by-one rolling restarts in Unicorn using the TTIN and TTOUT signals but Phusion Passenger does everything automatically for you without scripting.

like image 190
Hongli Avatar answered Oct 12 '22 09:10

Hongli