Capistrano recipe to restart standalone passenger server

You want to be able to use different ruby versions with passenger and by following the article here, you have set up your server to server the second version with a standalone passenger version. If you do that you cannot use the ‘touch tmp/restart.txt’ command to restart the standalone passenger server.

What you would need to do in your config/deploy.rb file, and assuming that your standalone passenger runs on a port (4000) different from the default (3000), is to replace the following:

run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"


run "cd #{release_path} && passenger stop -p 4000 && passenger start #{current_path} -a -p 4000 -e production -d --pid-file #{current_path}/tmp/pids/ --log-file #{current_path}/log/passenger.4000.log"

Find out the repositories permissions in gitolite


You would like to know what permission and for which repositories you have as a certain user when using gitolite to host your repositories.


Assuming that your gitolite user is gitolite and you have two different servers (server_a and server_b) with two different users (deploy_a and deploy_b) you can find out the permsissions by running the following:

$server_a/deploy_a: ssh gitolite@git_host info

$server_b/deploy_b: ssh gitolite@git_host info

Capistrano staging/production/demo recipe for precompiling assets


You have upgraded to rails 3.1.x, 3.2.x and you want capistrano to automatically precompile your assets and do the deployment in your various deployment environments (staging. production, demo etc).


First add a new directory in your server’s shared folder named assets

mkdir /path/to_your_shared_folder/assets

Then add the following line to your Capfile:

load 'deploy/assets'

And finally have your deploy environment file (deploy/staging.rb | deploy/prodution.rb) as follows:

set :rvm_ruby_string, '1.9.3-p125'
set :rvm_type, :user
set :rvm_bin_path, "$HOME/.rvm/bin"

# Add RVM's lib directory to the load path.
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))

# Load RVM's capistrano plugin
require "rvm/capistrano"

server '', :app, :web, :db, :primary => true

set :rails_env, :staging

after "deploy:update_code", :precompile_assets
  desc "precompile the assets"
  task :precompile_assets, :roles => :app do
    run "cd #{release_path} && RAILS_ENV=#{rails_env} bundle exec rake assets:precompile"

Javascript file not compiled in production with Rails asset pipeline


You have updated your application to the new 3.1.x or 3.2.x rails, and you are using the new asset pipeline.
You have a javascript file (example.js) that is only called in a specific view or conditionally (especially for css).
The application works fine in the development environment but when deploying in the production (or staging) server, you get an error like the following in the log file:

ActionView::Template::Error (example.js isn't precompiled)


As the new asset pipeline puts everything together in one file, your file that is called from a different place cannot be found.
Even if you include your example.js in the application.js manifest file with a //= require example, you still get the same error.
It is possible to compile a single javascript file separately from all the other ones.
So what you have to do is include the following into your necessary environment file (staging.rb, production.rb etc), or in the application.rb file if it going to be used in more than one environments.

config.assets.precompile += ['example.js']

Make sure that you include the .js in the code above, and then redeploy with capistrano cap staging|production deploy.

Using Postfix to send out emails from development environment in Rails


You want to be able to send emails from your development enironment using Postfix in your (K)Ubuntu pc.


First you would need to install postfix:

sudo apt-get install postfix

and then you would need to change an option in postfix to not use tls, so change /etc/postfix/

sudo vi /etc/postfix/

and change the smtpd_use_tls from yes to no:


restart your postfix server:

sudo /usr/sbin/postfix reload

and then setup your config/development.rb as follows:

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  address:                 "",
  port:                    25,
  enable_starttls_auto:    false

Command line mail message with postfix in (K)ubuntu


You have installed postfix in your local development machine (sudo apt-get install postfix), and you want to test sending emails from the command line using mail



You would first need to install the mailutils package:

sudo apt-get install mailutils

then you can send an email by:

CC: (leave blank)
Subject: Test subject
Main message body

and you can send it by pressing Ctrl+D