Skip to content
This repository was archived by the owner on Dec 21, 2022. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 44 additions & 59 deletions deployer/contrib/nodes/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
timeout %(timeout)s

# Logfile
logfile %(logfile)s
logfile %(log_file)s

%(bind)s
"""
Expand All @@ -56,7 +56,10 @@ class Redis(SimpleNode):
bind = None

# Download URL
redis_download_url = 'http://redis.googlecode.com/files/redis-2.6.13.tar.gz'
version = '2.6.16'
tarball_name = Q('redis-%s.tar.gz') % Q.version
srcdir_name = Q('redis-%s') % Q.version
download_url = Q('http://download.redis.io/releases/%s') % Q.tarball_name

# directory for the database file, or None for the home directory
@property
Expand All @@ -71,13 +74,11 @@ def directory(self):
def database_file(self):
return 'redis-db-%s.rdb' % self.slug

@property
def config_file(self):
return '/etc/redis-%s.conf' % self.slug
config_dir = '/etc/redis'
config_file = Q('%s/%s.log') % (Q.config_dir, Q.slug)

@property
def logfile(self):
return '/var/log/redis-%s.log' % self.slug
log_dir = '/var/log/redis'
log_file = Q('%s/%s.log') % (Q.log_dir, Q.slug)

class packages(AptGet):
# Packages required for building redis
Expand All @@ -95,6 +96,14 @@ class upstart_service(UpstartService):
user = Q.parent.username
command = Q('/usr/local/bin/redis-server %s') % Q.parent.config_file

@property
def pre_start_script(self):
return """
mkdir -p %(log_dir)s; chmod 777 %(log_dir)s;
""" % {
'log_dir': self.parent.log_dir,
}


def setup(self):
# Also make sure that redis was not yet installed
Expand All @@ -110,54 +119,29 @@ def setup(self):
# If not yet installed
if not self.host.has_command('redis-server'):
# Download redis
self.host.run(wget(self.redis_download_url, 'redis.tgz'))
self.host.run('tar xvzf redis.tgz')

# Unset ARCH variable, otherwise redis doesn't compile.
# http://comments.gmane.org/gmane.linux.slackware.slackbuilds.user/6686
with self.host.env('ARCH', ''):
# Make and install
with self.host.cd('redis-2.*'):
if self.host.is_64_bit:
self.host.run('make ARCH="-m64"')
else:
self.host.run('make 32bit')
self.host.sudo('make install')
with self.host.cd('src'):
if not self.host.exists(self.tarball_name):
self.host.run(wget(self.download_url))
if not self.host.exists(self.srcdir_name):
self.host.run('tar xzf %s' % self.tarball_name)

with self.host.cd(self.srcdir_name):
# Unset ARCH variable, otherwise redis doesn't compile.
# http://comments.gmane.org/gmane.linux.slackware.slackbuilds.user/6686
with self.host.env('ARCH', ''):
# Make and install
if self.host.is_64_bit:
self.host.run('make ARCH="-m64"')
else:
self.host.run('make 32bit')
self.host.sudo('make install')

self.host.sudo('mkdir -p %s' % self.log_dir)
self.host.sudo('chmod 777 %s' % self.log_dir)

self.host.sudo('mkdir -p %s' % self.config_dir)

self.config.setup()
self.upstart_service.setup()
self.touch_logfile()

def tail_logfile(self):
self.host.sudo("tail -n 20 -f '%s'" % esc1(self.logfile))

@property
def is_already_installed(self):
"""
Returns true when redis was already installed on all hosts
"""
return self.host.exists(self.config_file) and self.upstart_service.is_already_installed()


def shell(self):
print 'Opening telnet connection to Redis... Press Ctrl-C to exit.'
print
self.host.run('redis-cli -h localhost -a "%s" -p %s' % (self.password or '', self.port))


def monitor(self):
"""
Monitor all commands that are currently executed on this redis database.
"""
self.host.run('echo "MONITOR" | redis-cli -h localhost -a "%s" -p %s' % (self.password or '', self.port))


def dbsize(self):
"""
Return the number of keys in the selected database.
"""



# Install upstart config, and run
self.upstart_service.setup()
Expand All @@ -181,7 +165,7 @@ def content(self):
'auto_save': 'save 60 1' if self.persistent else '',
'bind': ('bind %s' % self.bind if self.bind else ''),
'timeout': str(int(self.timeout)),
'logfile': self.logfile,
'log_file': self.log_file,
}

def setup(self):
Expand All @@ -190,11 +174,12 @@ def setup(self):

def touch_logfile(self):
# Touch and chown logfile.
self.host.sudo("touch '%s'" % esc1(self.logfile))
self.host.sudo("chown '%s' '%s'" % (esc1(self.username), esc1(self.logfile)))
# With log_file in log_dir, we chmod log_dir and this is not needed anymore
self.host.sudo("touch '%s'" % esc1(self.log_file))
self.host.sudo("chown '%s' '%s'" % (esc1(self.username), esc1(self.log_file)))

def tail_logfile(self):
self.host.sudo("tail -n 20 -f '%s'" % esc1(self.logfile))
def tail_log(self):
self.host.sudo("tail -n 20 -f '%s'" % esc1(self.log_file))

@property
def is_already_installed(self):
Expand Down