desc <<-DESC Open a new shell in the specified #{resource_type}'s UNIX account. For password-less access, be sure to run #{qcommand "sshkey:register"} first. Environment variables: (optional) $ID: the ID of the #{resource_type} to connect to. (optional) $AS: the login of the UNIX account to connect as. DESC namespace :connect do task :default do resource = fetch_current ssh_details_for(resource).connect end desc <<-DESC Display SSH connection details. You can then use these details to connect to the #{resource_type} either from the command line (using the standard `ssh', `scp' or `sftp' tool suite), programmatically using Net::SSH, or graphically using WinSCP or Cyberduck. Environment variables: (optional) $ID: the ID of the #{resource_type} to get the connection details for. DESC task :details do resource = fetch_current details = ssh_details_for(resource) puts_long <<-EOS SSH connection details for #{resource_type} #{resource}: * Host: #{details.host} * Port: #{details.port} * Login: #{details.login} Remote command execution: $ ssh -p #{details.port} #{details.login}@#{details.host} File upload: $ scp -P #{details.port} #{details.login}@#{details.host} EOS end # Allow for defining a method named `command'. class << self undef_method :command if method_defined? :command end desc <<-DESC Output an SSH connection command, ready to run. Environment variables: (optional) $ID: the ID of the #{resource_type} to get the connection command for. DESC task :command do resource = fetch_current puts ssh_details_for(resource).connection_command end def ssh_details_for(resource) details = resource.ssh_details details.login = ENV["AS"] || 'root' unless details.attribute_set? :login # Return `details.connection' instead of `details' so that methods # of both SshDetails and SshDetails::AccountBinding are made # available from the same object. details.connection rescue WebService::NotAcceptable vps = resource.attribute_set?(:vps) ? resource.vps : resource reference = vps == resource ? "VPS" : "#{resource_type}'s VPS" error! <<-MSG The SSH port of the #{reference} (#{q vps}) is not accessible from the Internet. You need to open it in order to be able to connect to the #{resource_type}'s UNIX account. To do so, run #{qcommand "vps:firewall:open PORT=22"}. MSG end end desc "Alias for task `connect'." task(:enter) { connect.default } desc <<-DESC Run a command in the #{resource_type} environment. Default working directory is the home directory. Environment variables: (mandatory) $CMD: the command to run. (optional) $ID: the ID of the #{resource_type} to run the command in. DESC task :run do cmd = ENV['CMD'] or error! <<-MSG The command to execute must be specified in the $CMD environment variable. MSG resource = fetch_current connect.ssh_details_for(resource).run(cmd) end desc <<-DESC Upload a local file to the home directory of the #{resource_type}. Environment variables: (mandatory) $FILE: the path to the file to upload. (optional) $ID: the ID of the #{resource_type} to upload the file to. DESC task :upload do files = ENV['FILE'] || ENV['FILES'] or error! <<-MSG The file to upload must be specified in the $FILE environment variable. MSG resource = fetch_current connect.ssh_details_for(resource).upload(*Dir[files]) end namespace :rubygems do desc <<-DESC Install or update RubyGems (latest version) on the UNIX account of the specified #{resource_type}. Ruby will be installed if necessary (latest 1.8). Once you have done that, you can connect to the #{resource_type}'s UNIX account and start installing gems. For example: $ #{command "db:server:rubygems:install"} $ #{command "progress"} $ #{command "db:server:enter"} mysql@filiberto ~ $ gem install rails Environment variables: (optional) $ID: the ID of the #{resource_type} to install RubyGems onto. Default: the last #{resource_type}. DESC task :install do resource = fetch_current resource.post(:rubygems) puts_title "Request sent" puts "RubyGems (latest version) has been scheduled for installation or update on #{resource_type} #{resource}." end desc "Alias for `install'." task(:setup) { install } desc <<-DESC Update RubyGems to the latest version. Only the package management system is updated, not the gems themselves. Environment variables: (optional) $ID: the ID of the #{resource_type} to update RubyGems on. Default: the last #{resource_type}. DESC task(:update) do install end end