Skip to content

Instantly share code, notes, and snippets.

@usahg
Created April 2, 2013 08:22
Show Gist options
  • Save usahg/5290741 to your computer and use it in GitHub Desktop.
Save usahg/5290741 to your computer and use it in GitHub Desktop.
Cloning a script and running it on remote server with ruby
# this is a perfect use case for a capistrano task
# capistrano includes ruby ssh libraries and is used for deployments
# assuming ssh access is NOT password based but key-based
require 'capistrano'
default_run_options[:pty] = true
# Application Name
set :application, "remote_script"
# Repository Settings
set :scm, :git
set :branch, :master
set :repository, "path_to_git_repo_containing_upload_script.rb"
set :scm_verbose, true
ssh_options[:forward_agent] = true
set :git_shallow_clone, 1
# Server Settings
set :user, "ubuntu"
#set :password, "12345678" in case authentication was password based
set :domain, "10.11.120.139"
set :deploy_to, "/home/ubuntu/scripts/#{application}"
namespace :deploy do
task :start do
run "#{try_sudo} ruby /home/ubuntu/scripts/#{application} start"
end
task :stop do
run "#{try_sudo} ruby /home/ubuntu/scripts/#{application} stop"
end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} ruby /home/ubuntu/scripts/#{application} restart"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment