How to restart standalone socket proxyied Passenger after a capistrano deploy

a capistrano recipe to start stop passenger standalone with socket

After relocating all my web apps on DigitalOcean, I’ve discovered the performances of Nginx joined with Passenger standalone.

a capistrano recipe to start stop passenger standalone with socket

Nginx is a very fast and slim web server that could serve a lot of requests with agility. It is possible to use Nginx with a stand alone Passenger using a reverse proxy.

We know that:

  • Phusion Passenger Standalone also supports listening on a Unix domain socket instead of a TCP socket. Unix domain sockets are significantly faster than TCP sockets.
  • Nginx supports reverse proxying to Unix domain sockets; 

So with this nginx configuration, we could join together Nginx and Passenger through socket:

upstream olm_upstream {
    server unix:/tmp/;
server {
        listen   80; 
        root /var/www/vhosts/;
        location / {
                proxy_pass http://olm_upstream;
                proxy_set_header Host $host;

However, I’m using capistrano and start/stop socketed Passenger doen’t work by simply touch tmp/restart.txt.

So I’ve produced a capistrano recipe that perform a Passenger restart by stopping the old process and by starting a new one.

Here is the recipe:

Capistrano::Configuration.instance.load do
  after "deploy:update", "passenger:stop", "passenger:start"

  namespace :passenger do

      task :start, :roles => :app, :except => { :no_release => true } do
        run "cd #{current_path} && bundle exec passenger start --socket /tmp/#{application}.socket --daemonize --environment production --nginx-version 1.1.19"
      task :stop, :roles => :app, :except => { :no_release => true } do
        run "cd #{current_path} && bundle exec passenger stop --pid-file #{current_path}/tmp/pids/"


You’ve to customize your nginx version included in the recipe. Have a good deploy!

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *

%d blogger hanno fatto clic su Mi Piace per questo: