tasks/redis.rake in resque-mongo-1.4.0 vs tasks/redis.rake in resque-mongo-1.8.1
- old
+ new
@@ -1,24 +1,32 @@
# Inspired by rabbitmq.rake the Redbox project at http://github.com/rick/redbox/tree/master
require 'fileutils'
require 'open-uri'
+require 'pathname'
class RedisRunner
- def self.redisdir
- "/tmp/redis/"
+ def self.redis_dir
+ @redis_dir ||= if ENV['PREFIX']
+ Pathname.new(ENV['PREFIX'])
+ else
+ Pathname.new(`which redis-server`) + '..' + '..'
+ end
end
- def self.redisconfdir
- server_dir = File.dirname(`which redis-server`)
- conf_file = "#{server_dir}/../etc/redis.conf"
- unless File.exists? conf_file
- conf_file = "#{server_dir}/../../etc/redis.conf"
- end
- conf_file
+ def self.bin_dir
+ redis_dir + 'bin'
end
+ def self.config
+ @config ||= if File.exists?(redis_dir + 'etc/redis.conf')
+ redis_dir + 'etc/redis.conf'
+ else
+ redis_dir + '../etc/redis.conf'
+ end
+ end
+
def self.dtach_socket
'/tmp/redis.dtach'
end
# Just check for existance of dtach socket
@@ -27,16 +35,16 @@
end
def self.start
puts 'Detach with Ctrl+\ Re-attach with rake redis:attach'
sleep 1
- command = "dtach -A #{dtach_socket} redis-server #{redisconfdir}"
+ command = "#{bin_dir}/dtach -A #{dtach_socket} #{bin_dir}/redis-server #{config}"
sh command
end
def self.attach
- exec "dtach -a #{dtach_socket}"
+ exec "#{bin_dir}/dtach -a #{dtach_socket}"
end
def self.stop
sh 'echo "SHUTDOWN" | nc localhost 6379'
end
@@ -71,35 +79,43 @@
RedisRunner.attach
end
desc 'Install the latest verison of Redis from Github (requires git, duh)'
task :install => [:about, :download, :make] do
- ENV['PREFIX'] and bin_dir = "#{ENV['PREFIX']}/bin" or bin_dir = '/usr/bin'
+ bin_dir = '/usr/bin'
+ conf_dir = '/etc'
+
+ if ENV['PREFIX']
+ bin_dir = "#{ENV['PREFIX']}/bin"
+ sh "mkdir -p #{bin_dir}" unless File.exists?("#{bin_dir}")
+
+ conf_dir = "#{ENV['PREFIX']}/etc"
+ sh "mkdir -p #{conf_dir}" unless File.exists?("#{conf_dir}")
+ end
+
%w(redis-benchmark redis-cli redis-server).each do |bin|
sh "cp /tmp/redis/#{bin} #{bin_dir}"
end
puts "Installed redis-benchmark, redis-cli and redis-server to #{bin_dir}"
- ENV['PREFIX'] and conf_dir = "#{ENV['PREFIX']}/etc" or conf_dir = '/etc'
unless File.exists?("#{conf_dir}/redis.conf")
- sh "mkdir #{conf_dir}" unless File.exists?("#{conf_dir}")
sh "cp /tmp/redis/redis.conf #{conf_dir}/redis.conf"
puts "Installed redis.conf to #{conf_dir} \n You should look at this file!"
end
end
task :make do
- sh "cd #{RedisRunner.redisdir} && make clean"
- sh "cd #{RedisRunner.redisdir} && make"
+ sh "cd /tmp/redis && make clean"
+ sh "cd /tmp/redis && make"
end
desc "Download package"
task :download do
- sh 'rm -rf /tmp/redis/' if File.exists?("#{RedisRunner.redisdir}/.svn")
- sh 'git clone git://github.com/antirez/redis.git /tmp/redis' unless File.exists?(RedisRunner.redisdir)
- sh "cd #{RedisRunner.redisdir} && git pull" if File.exists?("#{RedisRunner.redisdir}/.git")
+ sh 'rm -rf /tmp/redis/' if File.exists?("/tmp/redis/.svn")
+ sh 'git clone git://github.com/antirez/redis.git /tmp/redis' unless File.exists?('/tmp/redis')
+ sh "cd /tmp/redis && git pull" if File.exists?("/tmp/redis/.git")
end
end
namespace :dtach do
@@ -108,28 +124,36 @@
task :about do
puts "\nSee http://dtach.sourceforge.net/ for information about dtach.\n\n"
end
desc 'Install dtach 0.8 from source'
- task :install => [:about] do
+ task :install => [:about, :download, :make] do
- Dir.chdir('/tmp/')
+ bin_dir = "/usr/bin"
+
+ if ENV['PREFIX']
+ bin_dir = "#{ENV['PREFIX']}/bin"
+ sh "mkdir -p #{bin_dir}" unless File.exists?("#{bin_dir}")
+ end
+
+ sh "cp /tmp/dtach-0.8/dtach #{bin_dir}"
+ end
+
+ task :make do
+ sh 'cd /tmp/dtach-0.8/ && ./configure && make'
+ end
+
+ desc "Download package"
+ task :download do
unless File.exists?('/tmp/dtach-0.8.tar.gz')
require 'net/http'
url = 'http://downloads.sourceforge.net/project/dtach/dtach/0.8/dtach-0.8.tar.gz'
open('/tmp/dtach-0.8.tar.gz', 'wb') do |file| file.write(open(url).read) end
end
unless File.directory?('/tmp/dtach-0.8')
- system('tar xzf dtach-0.8.tar.gz')
+ sh 'cd /tmp && tar xzf dtach-0.8.tar.gz'
end
-
- ENV['PREFIX'] and bin_dir = "#{ENV['PREFIX']}/bin" or bin_dir = "/usr/bin"
- Dir.chdir('/tmp/dtach-0.8/')
- sh 'cd /tmp/dtach-0.8/ && ./configure && make'
- sh "cp /tmp/dtach-0.8/dtach #{bin_dir}"
-
- puts "Dtach successfully installed to #{bin_dir}"
end
end