Showing with 172 additions and 21 deletions.
  1. +3 −3 manifests/install.pp
  2. +10 −1 manifests/params.pp
  3. +53 −8 manifests/sentinel.pp
  4. +3 −4 metadata.json
  5. +12 −5 spec/classes/redis_sentinel_spec.rb
  6. +2 −0 templates/redis-sentinel.conf.erb
  7. +89 −0 templates/redis-sentinel.init.erb
6 changes: 3 additions & 3 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# This class installs the application.
#
class redis::install {
package { $::redis::package_name:
ensure => $::redis::package_ensure,
}
ensure_resource('package', $::redis::package_name, {
'ensure' => $::redis::package_ensure
})
}

11 changes: 10 additions & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
$auto_aof_rewrite_percentage = 100
$bind = '127.0.0.1'
$conf_template = 'redis/redis.conf.erb'
$daemonize = true
$databases = 16
$dbfilename = 'dump.rdb'
$extra_config_file = undef
Expand Down Expand Up @@ -47,6 +46,8 @@
$sentinel_quorum = 2
$sentinel_service_name = 'redis-sentinel'
$sentinel_working_dir = '/tmp'
$sentinel_init_template = 'redis/redis-sentinel.init.erb'
$sentinel_pid_file = '/var/run/redis/redis-sentinel.pid'
$set_max_intset_entries = 512
$slowlog_log_slower_than = 10000
$slowlog_max_len = 1024
Expand Down Expand Up @@ -74,10 +75,14 @@
$config_file_mode = '0644'
$config_group = 'root'
$config_owner = 'root'
$daemonize = true
$package_ensure = 'present'
$package_name = 'redis-server'
$sentinel_config_file = '/etc/redis/redis-sentinel.conf'
$sentinel_config_file_orig = '/etc/redis/redis-sentinel.conf.puppet'
$sentinel_init_script = '/etc/init.d/redis-sentinel'
$sentinel_package_name = 'redis-server'
$sentinel_package_ensure = 'present'
$service_enable = true
$service_ensure = 'running'
$service_group = 'redis'
Expand All @@ -95,10 +100,14 @@
$config_file_mode = '0644'
$config_group = 'root'
$config_owner = 'root'
$daemonize = false
$package_ensure = 'present'
$package_name = 'redis'
$sentinel_config_file = '/etc/redis-sentinel.conf'
$sentinel_config_file_orig = '/etc/redis-sentinel.conf.puppet'
$sentinel_init_script = undef
$sentinel_package_name = 'redis'
$sentinel_package_ensure = 'present'
$service_enable = true
$service_ensure = 'running'
$service_group = 'redis'
Expand Down
61 changes: 53 additions & 8 deletions manifests/sentinel.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# = Class: redis::sentinel
#
# This class install redis-sentinel
# This class installs redis-sentinel
#
# == Parameters:
#
Expand Down Expand Up @@ -42,6 +42,11 @@
#
# Default: 180000
#
# [*init_script*]
# Specifiy the init script that will be created for sentinel.
#
# Default: undef on rpm, /etc/init.d/redis-sentinel on apt.
#
# [*log_file*]
# Specify where to write log entries.
#
Expand All @@ -63,12 +68,27 @@
#
# Default: 6379
#
# [*package_name*]
# The name of the package that installs sentinel.
#
# Default: 'redis-server' on apt, 'redis' on rpm
#
# [*package_ensure*]
# Do we ensure this package.
#
# Default: 'present'
#
# [*parallel_sync*]
# How many slaves can be reconfigured at the same time to use a
# new master after a failover.
#
# Default: 1
#
# [*pid_file*]
# If sentinel is daemonized it will write its pid at this location.
#
# Default: /var/run/redis/redis-sentinel.pid
#
# [*quorum*]
# Number of sentinels that must agree that a master is down to
# signal sdown state.
Expand Down Expand Up @@ -120,11 +140,16 @@
$conf_template = $::redis::params::sentinel_conf_template,
$down_after = $::redis::params::sentinel_down_after,
$failover_timeout = $::redis::params::sentinel_failover_timeout,
$init_script = $::redis::params::sentinel_init_script,
$init_template = $::redis::params::sentinel_init_template,
$log_file = $::redis::params::log_file,
$master_name = $::redis::params::sentinel_master_name,
$redis_host = $::redis::params::bind,
$redis_port = $::redis::params::port,
$package_name = $::redis::params::sentinel_package_name,
$package_ensure = $::redis::params::sentinel_package_ensure,
$parallel_sync = $::redis::params::sentinel_parallel_sync,
$pid_file = $::redis::params::sentinel_pid_file,
$quorum = $::redis::params::sentinel_quorum,
$sentinel_port = $::redis::params::sentinel_port,
$service_group = $::redis::params::service_group,
Expand All @@ -133,25 +158,45 @@
$working_dir = $::redis::params::sentinel_working_dir,
) inherits redis::params {


ensure_resource('package', $package_name, {
'ensure' => $package_ensure
})

file {
$config_file_orig:
ensure => present,
content => template($conf_template);

$config_file:
owner => $service_user,
group => $service_group,
mode => $config_file_mode;
owner => $service_user,
group => $service_group,
mode => $config_file_mode,
content => template($conf_template),
require => Package[$package_name];
}

exec {
"cp ${config_file_orig} ${config_file}":
"cp -p ${config_file_orig} ${config_file}":
path => '/usr/bin:/bin',
subscribe => File[$config_file_orig],
notify => Service[$service_name],
refreshonly => true;
}

if $init_script {
file {
$init_script:
ensure => present,
owner => 'root',
group => 'root',
mode => '0755',
content => template($init_template),
require => Package[$package_name];
}
exec {
"/usr/sbin/update-rc.d redis-sentinel defaults":
require => File[$init_script];
}
}

service { $service_name:
ensure => $::redis::params::service_ensure,
enable => $::redis::params::service_enable,
Expand Down
7 changes: 3 additions & 4 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "arioch-redis",
"version": "1.0.3",
"version": "1.0.4",
"author": "Tom De Vylder",
"summary": "Redis module",
"license": "Apache License, Version 2.0",
Expand Down Expand Up @@ -68,8 +68,7 @@
}
],
"dependencies": [
{
"name": "puppetlabs/apt"
}
{ "name": "puppetlabs/apt" },
{ "name": "puppetlabs/stdlib" }
]
}
17 changes: 12 additions & 5 deletions spec/classes/redis_sentinel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
$expected_noparams_content = <<EOF
port 26379
dir /tmp
daemonize yes
pidfile /var/run/redis/redis-sentinel.pid
sentinel monitor mymaster 127.0.0.1 6379 2
sentinel down-after-milliseconds mymaster 30000
Expand All @@ -15,6 +17,8 @@
$expected_params_content = <<EOF
port 26379
dir /tmp
daemonize yes
pidfile /var/run/redis/redis-sentinel.pid
sentinel monitor cow 127.0.0.1 6379 2
sentinel down-after-milliseconds cow 6000
Expand All @@ -27,21 +31,24 @@
describe 'redis::sentinel', :type => :class do
let (:facts) { debian_facts }

let :pre_condition do
[
'class { redis: }'
]
end

describe 'without parameters' do

it { should create_class('redis::sentinel') }

it { should contain_file('/etc/redis/redis-sentinel.conf.puppet').with(
'ensure' => 'present',
'mode' => '0644',
'owner' => 'redis',
'content' => $expected_noparams_content
)
}

it { should contain_file('/etc/redis/redis-sentinel.conf').with(
'mode' => '0644'
)
}

it { should contain_service('redis-sentinel').with(
'ensure' => 'running',
'enable' => 'true',
Expand Down
2 changes: 2 additions & 0 deletions templates/redis-sentinel.conf.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
port <%= @sentinel_port %>
dir <%= @working_dir %>
<% if @daemonize -%>daemonize yes<% else -%>daemonize no<% end %>
pidfile <%= @pid_file %>

sentinel monitor <%= @master_name %> <%= @redis_host %> <%= @redis_port %> <%= @quorum %>
sentinel down-after-milliseconds <%= @master_name %> <%= @down_after %>
Expand Down
89 changes: 89 additions & 0 deletions templates/redis-sentinel.init.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#! /bin/sh
### BEGIN INIT INFO
# Provides: redis-sentinel
# Required-Start: $syslog $remote_fs
# Required-Stop: $syslog $remote_fs
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: redis-sentinel - Monitor redis-server
# Description: redis-sentinel - Monitor redis-server
### END INIT INFO


PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/redis-sentinel
DAEMON_ARGS=<%= @config_file %>
NAME=redis-sentinel
DESC=redis-senitnel

RUNDIR=/var/run/redis
PIDFILE=$RUNDIR/redis-sentinel.pid

test -x $DAEMON || exit 0

if [ -r /etc/default/$NAME ]
then
. /etc/default/$NAME
fi

. /lib/lsb/init-functions

set -e

case "$1" in
start)
echo -n "Starting $DESC: "
mkdir -p $RUNDIR
touch $PIDFILE
chown <%= @service_user %>:<%= @service_group %> $RUNDIR $PIDFILE
chmod 755 $RUNDIR

if [ -n "$ULIMIT" ]
then
ulimit -n $ULIMIT
fi

if start-stop-daemon --start --quiet --umask 007 --pidfile $PIDFILE --chuid <%= @service_user %>:<%= @service_group %> --exec $DAEMON -- $DAEMON_ARGS
then
echo "$NAME."
else
echo "failed"
fi
;;
stop)
echo -n "Stopping $DESC: "
if start-stop-daemon --stop --retry forever/TERM/1 --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON
then
echo "$NAME."
else
echo "failed"
fi
rm -f $PIDFILE
sleep 1
;;

restart|force-reload)
${0} stop
${0} start
;;

status)
echo -n "$DESC is "
if start-stop-daemon --stop --quiet --signal 0 --name ${NAME} --pidfile ${PIDFILE}
then
echo "running"
else
echo "not running"
exit 1
fi
;;

*)
echo "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload|status}" >&2
exit 1
;;
esac

exit 0