]> git.saurik.com Git - redis.git/blob - client-libraries/ruby/tasks/redis.tasks.rb
max inline request raised again to 1024*1024*256 bytes
[redis.git] / client-libraries / ruby / tasks / redis.tasks.rb
1 # Inspired by rabbitmq.rake the Redbox project at http://github.com/rick/redbox/tree/master
2 require 'fileutils'
3
4 class RedisRunner
5
6 def self.redisdir
7 "/tmp/redis/"
8 end
9
10 def self.redisconfdir
11 '/etc/redis.conf'
12 end
13
14 def self.dtach_socket
15 '/tmp/redis.dtach'
16 end
17
18 # Just check for existance of dtach socket
19 def self.running?
20 File.exists? dtach_socket
21 end
22
23 def self.start
24 puts 'Detach with Ctrl+\ Re-attach with rake redis:attach'
25 sleep 3
26 exec "dtach -A #{dtach_socket} redis-server #{redisconfdir}"
27 end
28
29 def self.attach
30 exec "dtach -a #{dtach_socket}"
31 end
32
33 def self.stop
34 sh 'echo "SHUTDOWN" | nc localhost 6379'
35 end
36
37 end
38
39 namespace :redis do
40
41 desc 'About redis'
42 task :about do
43 puts "\nSee http://code.google.com/p/redis/ for information about redis.\n\n"
44 end
45
46 desc 'Start redis'
47 task :start do
48 RedisRunner.start
49 end
50
51 desc 'Stop redis'
52 task :stop do
53 RedisRunner.stop
54 end
55
56 desc 'Restart redis'
57 task :restart do
58 RedisRunner.stop
59 RedisRunner.start
60 end
61
62 desc 'Attach to redis dtach socket'
63 task :attach do
64 RedisRunner.attach
65 end
66
67 desc 'Install the lastest verison of Redis from Github (requires git, duh)'
68 task :install => [:about, :download, :make] do
69 %w(redis-benchmark redis-cli redis-server).each do |bin|
70 sh "sudo cp /tmp/redis/#{bin} /usr/bin/"
71 end
72
73 puts "Installed redis-benchmark, redis-cli and redis-server to /usr/bin/"
74
75 unless File.exists?('/etc/redis.conf')
76 sh 'sudo cp /tmp/redis/redis.conf /etc/'
77 puts "Installed redis.conf to /etc/ \n You should look at this file!"
78 end
79 end
80
81 task :make do
82 sh "cd #{RedisRunner.redisdir} && make clean"
83 sh "cd #{RedisRunner.redisdir} && make"
84 end
85
86 desc "Download package"
87 task :download do
88 sh 'rm -rf /tmp/redis/' if File.exists?("#{RedisRunner.redisdir}/.svn")
89 sh 'git clone git://github.com/antirez/redis.git /tmp/redis' unless File.exists?(RedisRunner.redisdir)
90 sh "cd #{RedisRunner.redisdir} && git pull" if File.exists?("#{RedisRunner.redisdir}/.git")
91 end
92
93 end
94
95 namespace :dtach do
96
97 desc 'About dtach'
98 task :about do
99 puts "\nSee http://dtach.sourceforge.net/ for information about dtach.\n\n"
100 end
101
102 desc 'Install dtach 0.8 from source'
103 task :install => [:about] do
104
105 Dir.chdir('/tmp/')
106 unless File.exists?('/tmp/dtach-0.8.tar.gz')
107 require 'net/http'
108
109 Net::HTTP.start('superb-west.dl.sourceforge.net') do |http|
110 resp = http.get('/sourceforge/dtach/dtach-0.8.tar.gz')
111 open('/tmp/dtach-0.8.tar.gz', 'wb') do |file| file.write(resp.body) end
112 end
113 end
114
115 unless File.directory?('/tmp/dtach-0.8')
116 system('tar xzf dtach-0.8.tar.gz')
117 end
118
119 Dir.chdir('/tmp/dtach-0.8/')
120 sh 'cd /tmp/dtach-0.8/ && ./configure && make'
121 sh 'sudo cp /tmp/dtach-0.8/dtach /usr/bin/'
122
123 puts 'Dtach successfully installed to /usr/bin.'
124 end
125 end
126