SSHKit is an amazing tool to run any commands on your VPS or docker images as any user. Capistrano uses it to all the server related stuffs. In other words you can build your own deployer software or server maintenance tools using SSHKit.
$ gem install sshkit
Lets create a ruby script to create a file in my VPS’s home directory
on ['deployer@4X.79.XXX.XX1'], in: :sequence, wait: 1 do |host|
within '~' do # or '/home/deployer/'
as :deployer do
execute 'echo', 'My name is shiva > shiva.txt'
Go and check in your VPS, you see the file Continue reading
When you run
cap production deploy, it invokes the following tasks in sequence:
deploy:starting - start a deployment, make sure everything is ready
deploy:started - started hook (for custom tasks)
deploy:updating - update server(s) with a new release
deploy:updated - updated hook
deploy:publishing - publish the new release
deploy:published - published hook
deploy:finishing - finish the deployment, clean up everything
deploy:finished - finished hook
Notice there are several hook tasks e.g.
:updated for you to hook up custom tasks into the flow using
Capistrano is designed to run commands remotely. To do this we’ll need to specify a server, which we do by calling
server. We need to pass this the address of a server and a role. We’ll explain roles later; for now we’ll just set this to
First you need to set the configurations. Common settings go to the `deploy.rb` and environment specific settings goes to either 'config/deploy/production.rb' or 'staging.rb'
When you run
cap, Capistrano dutifully connects to your server(s) via SSH and executes the steps necessary to deploy your project. You can define those steps yourself by writing Rake tasks, or by using pre-built task libraries provided by the Capistrano community.
Include the gem in Gemfile
group :development do
gem 'capistrano', '~> 3.1'
We will start from creating simple tasks