breaking into the unknown…

rails deployment with mina


Recently, I need to automate server deployment on staging machine. I have used capistrano earlier, but decided to give a try to new deployment gem for rails : mina . You can find very good documentation here , which make the things very easy to understand and implement. Before, trying the code on staging server directly, I tried it on my friend suresh machine, as my target server.

STEP 1: Setting the Staging server

Staging Machine (I regarded my friend machine as Staging server)
username: trantor
password: xyz4154
system name : trantor-MS-7788 which basically represent the ip

You should able to ssh trantor@ from your terminal.   see how to ssh to remote machine here

STEP 2: Create empty directory on server manually which required by mina as prequisite
-> /var/www/ #this folder will become your deploy_to path
-> /var/www/ # mina will take database file from here
-> install rvm if you want to use it
-> create the database to be used

Note : Your task on staging server is over with step 2. remaining step is to be done in your own machine except step 9

STEP 3: adding staging.rb file in environment folder
this will contain configuration specific to staging server. add your required configuration to it
STEP 4: Add mina to your gem file and run bundle install
gem ‘mina’ #in gem file
$bundle install # on terminal

STEP 5: Initiating mina
$ mina init
—–> Created ./config/deploy.rb
Edit this file, then run `mina setup` after.

STEP 6: edit the /config/deploy.rb file as instructed there . the final content is as below

require 'mina/bundler'
require 'mina/rails'
require 'mina/git' #use it if your are using git repository
require 'mina/rvm' #use it if you have installed rvm on your server
set :domain, 'trantor@' # the server to which you ssh
set :deploy_to, '/var/www/' #create this folder manually on server, 
                                       mina will deploy to this
set :repository, '' # your repository url, 
                                           this repository must be accessible on server, see here
set :branch, 'master'
set :rails_env, 'staging' #default is production, 
                          so this line is must to deploy on staging

set :shared_paths, ['config/database.yml', 'log'] #will tell mina which things 
                                                 in your project should be taken from shared folder

task :environment do
invoke :'rvm:use[ruby-1.9.3-p194]' # You will create this gemset under setup

task :setup => :environment do
  queue! "rvm install ruby-1.9.3-p194" # will install the rvm on server
  queue! %[mkdir -p "#{deploy_to}/shared/log"]
  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/log"]

  queue! %[mkdir -p "#{deploy_to}/shared/config"]
  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/config"]

  queue! %[touch "#{deploy_to}/shared/config/database.yml"]
  queue  %[-----> Be sure to edit 'shared/config/database.yml'.]

desc "Deploys the current version to the server."
task :deploy => :environment do
  deploy do
    invoke :'git:clone'
    invoke :'deploy:link_shared_paths'
    invoke :'bundle:install'
    invoke :'rails:db_migrate'
    invoke :'rails:assets_precompile'

    to :launch do
      queue 'touch #{deploy_to}/tmp/restart.txt'

STEP  7: run mina setup on the terminal

$mina setup #it will run setup task from deploy.rb in step 6. Your server is now ready for deployment

STEP 8: deploy the code to the server

$mina delpoy

STEP 9: Start the server

cd to installed directory and run rails s -e staging as below

trantor@ trantor-MS-7788$ cd /var/www/ # your current code is in current folder

trantor@ trantor-MS-7788/var/www/$ rails s -e staging

This will start your application on server with webrick as you use to do on your development machine. To configure it to work with nginx and passenger see this post

STEP 10: See it working

Go to your browser and type ….press enter….yepieee…the site is UP🙂

You can find multi box deployment or multi server deployment using mina in this post

Author: arunyadav4u

over 7 years experience in web development with Ruby on Rails.Involved in all stage of development lifecycle : requirement gathering, planing, coding, deployment & Knowledge transfer. I can adept to any situation, mixup very easily with people & can be a great friend.

5 thoughts on “rails deployment with mina

  1. Iḿ getting this error:

    echo “! ERROR: Setup failed.”
    echo “! Ensure that the path ‘/var/www/lideranca’ is accessible to the SSH user.”
    echo “! Try doing:”
    echo “! sudo mkdir -p \”/var/www/lideranca\” && sudo chown -R deployer \”/var/www/lideranca\””
    mkdir -p “/var/www/lideranca/shared/log”
    chmod g+rx,u+rwx “/var/www/lideranca/shared/log”
    mkdir -p “/var/www/lideranca/shared/config”
    chmod g+rx,u+rwx “/var/www/lideranca/shared/config”
    touch “/var/www/lideranca/shared/config/database.yml”
    echo “—–> Be sure to edit ‘shared/config/database.yml’.”
    Elapsed time: 0.00 seconds

    What it should be? I already make the directories with right permissions

    Could you help with this?

    • It clearly saying that /var/www/lideranca is not accessible to the user trying to deploy and giving the solution.
      Have you run below on your server :

      sudo chown -R deployer /var/www/lideranca

      In the above command deployer is the user as which you login to server

      assuming your server is a linux machine, you can have different users say : root(the default one) ,arun and fernando

      Try below things :

      1 : try to login to the server manually and access the folder
      basically, if you ssh to the server like below

      ssh fernando@

      It will login you to server as the user fernando.
      Now try to access the folder /var/www/lideranca .
      If you can access it, excellent, if not give the user fernando ownership permission on it, as below

      sudo chown -R fernando /var/www/lideranca

      Now you can ask mina to use fernando for deployment with below configuration settings

      set :domain, ‘’
      set :user, ‘fernando’

      basically, the above setting will ask mina to ssh using the above command i,e ssh fernando@

      2 : check the permission on lideranca as below

      $ cd /var/www
      $ ls -l | grep lideranca

      if not having write permission, give it as below:

      $ chmod -R 766 lideranca

      If it do not help, provide me below to understand your problem:
      => your mina configuration
      => the shh command you are using manually to login to serevr

      • My user here is deployer. See the configuration

        [deployer@CentOS www]$ ls -ls
        total 4
        4 drwxrw-rw- 3 deployer root 4096 Fev 25 16:47 lideranca
        [deployer@CentOS www]$

        I tried everything that you say, but still doing the same error.

        I already have permittion and I can access the folder via ssh on my server

        My mina configuration is:

        require ‘mina/bundler’
        require ‘mina/rails’
        require ‘mina/git’
        # require ‘mina/rbenv’ # for rbenv support. (
        require ‘mina/rvm’ # for rvm support. (

        # Basic settings:
        # domain – The hostname to SSH to.
        # deploy_to – Path to deploy into.
        # repository – Git repo to clone from. (needed by mina/git)
        # branch – Branch name to deploy. (needed by mina/git)

        set :domain, ‘’
        set :deploy_to, ‘/var/www/lideranca’
        set :repository, ‘’
        set :branch, ‘master’

        # Manually create these paths in shared/ (eg: shared/config/database.yml) in your server.
        # They will be linked in the ‘deploy:link_shared_paths’ step.
        set :shared_paths, [‘config/database.yml’, ‘log’]

        # Optional settings:
        set :user, ‘deployer’ # Username in the server to SSH to.
        #set :port, ’22’ # SSH port number.

        # This task is the environment that is loaded for most commands, such as
        # `mina deploy` or `mina rake`.
        task :environment do
        # If you’re using rbenv, use this to load the rbenv environment.
        # Be sure to commit your .rbenv-version to your repository.
        # invoke :’rbenv:load’

        # For those using RVM, use this to load an RVM version@gemset.
        invoke :’rvm:use[ruby-1.9.3-p125@default]’

        # Put any custom mkdir’s in here for when `mina setup` is ran.
        # For Rails apps, we’ll make some of the shared paths that are shared between
        # all releases.
        task :setup => :environment do
        queue! %[mkdir -p “#{deploy_to}/shared/log”]
        queue! %[chmod g+rx,u+rwx “#{deploy_to}/shared/log”]

        queue! %[mkdir -p “#{deploy_to}/shared/config”]
        queue! %[chmod g+rx,u+rwx “#{deploy_to}/shared/config”]

        queue! %[touch “#{deploy_to}/shared/config/database.yml”]
        queue %[echo “—–> Be sure to edit ‘shared/config/database.yml’.”]

        desc “Deploys the current version to the server.”
        task :deploy => :environment do
        deploy do
        # Put things that will set up an empty directory into a fully set-up
        # instance of your project.
        invoke :’git:clone’
        invoke :’deploy:link_shared_paths’
        invoke :’bundle:install’
        invoke :’rails:db_migrate’
        invoke :’rails:assets_precompile’

        to :launch do
        queue “touch #{deploy_to}/tmp/restart.txt”

  2. —–> Stop sidekiq
    Skip stopping sidekiq (no pid file found)
    —–> Start sidekiq
    bundler: command not found: sidekiq
    Install missing gem executables with `bundle install`
    ! ERROR: Deploy failed.
    —–> Cleaning up build
    Deleting release
    Unlinking current

    ! Command failed.
    Failed with status 19

    can u help me to find out this please

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s