![]() ![]() We use monit to watch tmp/restart.txt which is touched after each capistrano deployment. The last piece of the puzzle is monitoring the application and restarting it after new version is deployed. We changed it so each application is run under different user (note $APP_USER variable). The script above is a modified version of example from Unicorn repo. Put this file in /etc/init.d/unicorn.appname and make it executable with chmod +x /etc/init.d/unicorn.appname If test $n -lt 0 & test -s $old_pid thenĮcho >&2 " $old_pid still exists after $TIMEOUT seconds" exit 1Įcho >&2 "Couldn't upgrade, starting ' $CMD ' instead" N = $TIMEOUT while test -s $old_pid & test $n -ge 0 Upgrade ) if sig USR2 & sleep 2 & sig 0 & oldsig QUIT Sig 0 & echo >&2 "Already running" & exit 0Įcho >&2 "Couldn't reload, starting ' $CMD ' instead" Now the nginx configuration: upstream unicorn-appname case $action in ![]() You can start unicorn right away with bundle exec unicorn - D - c /var/ www / appname / current / config / unicorn. # The rule of thumb is to use 1 worker per processor core available, # however since we'll be hosting many apps on this server, # we need to take a less aggressive approach worker_processes 2 # We deploy with capistrano, so "current" links to root dir of current release working_directory "/var/, :backlog => 64 pid "/var/stdout_path "/var/www/appname/current/log/unicorn.log" Here's rather minimal version, you'll find a well documented configuration example in Unicorn repo. So here's example configuration of Rails application running on unicorn with nginx as reverse proxy.įirst, let's add unicorn gem to our app's Gemfile gem 'unicorn'Ĭreate unicorn config file in config/unicorn.rb. Read more about unicorn internals in Ryan Tomayko's great article. Another cool feature is zero-downtime deployments, you can upgrade your application's code, unicorn library or even Ruby interpreter without dropping connections. Also it's OS kernel doing load balancing for us. Unicorn is able to listen on Unix sockets which are faster than TCP ones and are better choice for our setup where both nginx and applications run on the same machine. When nginx restarts it simply connects to already running and listening unicorn processes. Workers are managed by unicorn processes (which can be started using different Ruby versions, so each app can use different one), so you can reconfigure and restart both application and nginx independently. With passenger module you run all apps on one version of Ruby interpreter, also you need to restart whole http server when changing it's configuration or configuration of any application it proxies to, which results in downtime because application workers are restarted as well.īy separating application workers from http server you take a different approach. This accomplishes several important goals and is far more superior to using passenger module (with either nginx or apache).įirst of all it helps you isolate applications from each other and from nginx itself. Nginx acts as a reverse proxy for Rails (or more precisely Rack) applications which run on unicorn servers. In our setup we typically use combination of nginx and unicorn. In our case some applications are not big enough to justify being run on a dedicated machine, they can happily coexist with others on a single server. The key factors in such evaluation are expected traffic (and growth) and resource consumption by application workers and accompanying services/components (e.g. So there is plenty of factors that affect hosting infrastructure, and basically each app need to be evaluated individually. We developed most of them, but there are also some legacy ones (even Rails 1.2 or PHP). Self-managed solutions, be it own dedicated servers or using cloud infrastructure (like Rackspace Cloud), are still valid choices in most situations.Īt Monterail we're maintaining tens of web applications that are hosted in all of above-mentioned environments. ![]() However it doesn't mean that one should start developing his applications with Heroku or Engine Yard in mind from now on. Platform as a service is getting more and more traction recently. ![]()
0 Comments
Leave a Reply. |