class Object
Public Instance Methods
database_config(db)
click to toggle source
Reads the database credentials from the local config/database.yml file db
the name of the environment to get the credentials for Returns username, password, database
# File lib/capones_recipes/tasks/database/mysql.rb, line 86 def database_config(db) database = YAML::load_file('config/database.yml') return database["#{db}"]['username'], database["#{db}"]['password'], database["#{db}"]['database'] end
host_and_port()
click to toggle source
Returns the actual host name to sync and port
# File lib/capones_recipes/tasks/sync/fs.rb, line 67 def host_and_port return roles[:web].servers.first.host, ssh_options[:port] || roles[:web].servers.first.port || 22 end
purge_old_backups(base)
click to toggle source
Purge old backups within the shared sync directory
# File lib/capones_recipes/tasks/sync/sync.rb, line 49 def purge_old_backups(base) count = fetch(:sync_backups, 5).to_i backup_files = capture("ls -xt #{shared_path}/sync/#{base}*").split.reverse if count >= backup_files.length logger.important "no old backups to clean up" else logger.info "keeping #{count} of #{backup_files.length} sync backups" delete_backups = (backup_files - backup_files.last(count)).join(" ") try_sudo "rm -rf #{delete_backups}" end end
remote_database_config(db)
click to toggle source
Reads the database credentials from the remote config/database.yml file db
the name of the environment to get the credentials for Returns username, password, database
# File lib/capones_recipes/tasks/database/sync.rb, line 119 def remote_database_config(db) env = rails_env || db config = capture "cat #{latest_release}/config/database.yml" database = YAML::load(config) return database["#{env}"]['username'], database["#{env}"]['password'], database["#{env}"]['database'], database["#{env}"]['host'] end
run_rake(task, options={}, &block)
click to toggle source
# File lib/capones_recipes/tasks/thinking_sphinx.rb, line 35 def run_rake(task, options={}, &block) rake = fetch(:rake, "rake") rails_env = fetch(:rails_env, 'production') command = "cd #{latest_release} && #{rake} #{task} RAILS_ENV=#{rails_env} ; true" run(command, options, &block) end
run_with_tty(server, cmd)
click to toggle source
# File lib/capones_recipes/tasks/rails/console.rb, line 18 def run_with_tty server, cmd # looks like total pizdets command = [] command += %W( ssh -t #{gateway} -l #{self[:gateway_user] || self[:user]} ) if self[:gateway] command += %W( ssh -t ) command += %W( -p #{server.port}) if server.port command += %W( -l #{user} #{server.host} ) command += %W( cd #{current_path} ) # have to escape this once if running via double ssh command += [self[:gateway] ? '\&\&' : '&&'] command += Array(cmd) system *command end