-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds defined type for mult-instancing
* Move the config logic into a defined type * This will allow us to have multiple instances of redis on one machine * Example code: ``` # Install redis package class { '::redis': default_install => false, } redis::instance {'redis1': port => '7777', pid_file => '/var/run/redis/redis-server-redis1.pid', } redis::instance {'redis2': port => '8888', pid_file => '/var/run/redis/redis-server-redis2.pid', } ``` * Currently only works on Ubuntu because of init.d * First iteration
- Loading branch information
Showing
8 changed files
with
385 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
# redis::instance | ||
# | ||
# This is an defined type to allow the configuration of | ||
# multiple redis instances on one machine without conflicts | ||
# | ||
# @summary Allows the configuration of multiple redis configurations on one machine | ||
# | ||
# @example | ||
# redis::instance {'6380': | ||
# port => '6380', | ||
# } | ||
# | ||
# @param first The first parameter for this class | ||
# @param second The second paramter for this class | ||
define redis::instance( | ||
$activerehashing = $::redis::activerehashing, | ||
$aof_load_truncated = $::redis::aof_load_truncated, | ||
$aof_rewrite_incremental_fsync = $::redis::aof_rewrite_incremental_fsync, | ||
$appendfilename = $::redis::appendfilename, | ||
$appendfsync = $::redis::appendfsync, | ||
$appendonly = $::redis::appendonly, | ||
$auto_aof_rewrite_min_size = $::redis::auto_aof_rewrite_min_size, | ||
$auto_aof_rewrite_percentage = $::redis::auto_aof_rewrite_percentage, | ||
$bind = $::redis::bind, | ||
$conf_template = $::redis::conf_template, | ||
$config_dir = $::redis::config_dir, | ||
$config_dir_mode = $::redis::config_dir_mode, | ||
$config_file = $::redis::config_file, | ||
$config_file_mode = $::redis::config_file_mode, | ||
$config_file_orig = $::redis::config_file_orig, | ||
$config_group = $::redis::config_group, | ||
$config_owner = $::redis::config_owner, | ||
$daemonize = $::redis::daemonize, | ||
$databases = $::redis::databases, | ||
$dbfilename = $::redis::dbfilename, | ||
$extra_config_file = $::redis::extra_config_file, | ||
$hash_max_ziplist_entries = $::redis::hash_max_ziplist_entries, | ||
$hash_max_ziplist_value = $::redis::hash_max_ziplist_value, | ||
$hll_sparse_max_bytes = $::redis::hll_sparse_max_bytes, | ||
$hz = $::redis::hz, | ||
$latency_monitor_threshold = $::redis::latency_monitor_threshold, | ||
$list_max_ziplist_entries = $::redis::list_max_ziplist_entries, | ||
$list_max_ziplist_value = $::redis::list_max_ziplist_value, | ||
$log_file = $::redis::log_file, | ||
$log_level = $::redis::log_level, | ||
$minimum_version = $::redis::minimum_version, | ||
$masterauth = $::redis::masterauth, | ||
$maxclients = $::redis::maxclients, | ||
$maxmemory = $::redis::maxmemory, | ||
$maxmemory_policy = $::redis::maxmemory_policy, | ||
$maxmemory_samples = $::redis::maxmemory_samples, | ||
$min_slaves_max_lag = $::redis::min_slaves_max_lag, | ||
$min_slaves_to_write = $::redis::min_slaves_to_write, | ||
$no_appendfsync_on_rewrite = $::redis::no_appendfsync_on_rewrite, | ||
$notify_keyspace_events = $::redis::notify_keyspace_events, | ||
$managed_by_cluster_manager = $::redis::managed_by_cluster_manager, | ||
$pid_file = $::redis::pid_file, | ||
$port = $::redis::port, | ||
$rdbcompression = $::redis::rdbcompression, | ||
$repl_backlog_size = $::redis::repl_backlog_size, | ||
$repl_backlog_ttl = $::redis::repl_backlog_ttl, | ||
$repl_disable_tcp_nodelay = $::redis::repl_disable_tcp_nodelay, | ||
$repl_ping_slave_period = $::redis::repl_ping_slave_period, | ||
$repl_timeout = $::redis::repl_timeout, | ||
$requirepass = $::redis::requirepass, | ||
$save_db_to_disk = $::redis::save_db_to_disk, | ||
$save_db_to_disk_interval = $::redis::save_db_to_disk_interval, | ||
$service_user = $::redis::service_user, | ||
$set_max_intset_entries = $::redis::set_max_intset_entries, | ||
$slave_priority = $::redis::slave_priority, | ||
$slave_read_only = $::redis::slave_read_only, | ||
$slave_serve_stale_data = $::redis::slave_serve_stale_data, | ||
$slaveof = $::redis::slaveof, | ||
$slowlog_log_slower_than = $::redis::slowlog_log_slower_than, | ||
$slowlog_max_len = $::redis::slowlog_max_len, | ||
$stop_writes_on_bgsave_error = $::redis::stop_writes_on_bgsave_error, | ||
$syslog_enabled = $::redis::syslog_enabled, | ||
$syslog_facility = $::redis::syslog_facility, | ||
$tcp_backlog = $::redis::tcp_backlog, | ||
$tcp_keepalive = $::redis::tcp_keepalive, | ||
$timeout = $::redis::timeout, | ||
$unixsocket = $::redis::unixsocket, | ||
$unixsocketperm = $::redis::unixsocketperm, | ||
$ulimit = $::redis::ulimit, | ||
$zset_max_ziplist_entries = $::redis::zset_max_ziplist_entries, | ||
$zset_max_ziplist_value = $::redis::zset_max_ziplist_value, | ||
$cluster_enabled = $::redis::cluster_enabled, | ||
$cluster_config_file = $::redis::cluster_config_file, | ||
$cluster_node_timeout = $::redis::cluster_node_timeout, | ||
$workdir = $::redis::workdir, | ||
$service_ensure = $::redis::service_ensure, | ||
$service_enable = $::redis::service_enable, | ||
$service_hasrestart = $::redis::service_hasrestart, | ||
$service_hasstatus = $::redis::service_hasstatus, | ||
) { | ||
|
||
if $title == 'default' { | ||
$redis_file_name_orig = $config_file_orig | ||
$redis_file_name = $config_file | ||
} else { | ||
$redis_config_extension = ".${title}" | ||
$instance_init_file = "/etc/init.d/${title}" | ||
$redis_file_name_orig = "${config_file_orig}${redis_config_extension}" | ||
$redis_file_name = "${config_file}${redis_config_extension}" | ||
|
||
file { $instance_init_file: | ||
ensure => file, | ||
mode => '0755', | ||
content => template('redis/redis.init.erb'), | ||
subscribe => Exec["cp -p ${redis_file_name_orig} ${redis_file_name}"], | ||
} | ||
|
||
~> service { $title: | ||
ensure => $service_ensure, | ||
hasrestart => $service_hasrestart, | ||
hasstatus => $service_hasstatus, | ||
} | ||
} | ||
|
||
File { | ||
owner => $config_owner, | ||
group => $config_group, | ||
mode => $config_file_mode, | ||
} | ||
|
||
file {$redis_file_name_orig: | ||
ensure => file, | ||
} | ||
|
||
$redis_version_real = pick(getvar_emptystring('redis_server_version'), $minimum_version) | ||
|
||
if ($redis_version_real and $conf_template == 'redis/redis.conf.erb') { | ||
case $redis_version_real { | ||
/^2.4./: { | ||
File[$redis_file_name_orig] { content => template('redis/redis.conf.2.4.10.erb') } | ||
} | ||
/^2.8./: { | ||
File[$redis_file_name_orig] { content => template('redis/redis.conf.2.8.erb') } | ||
} | ||
default: { | ||
File[$redis_file_name_orig] { content => template($conf_template) } | ||
} | ||
} | ||
} else { | ||
File[$redis_file_name_orig] { content => template($conf_template) } | ||
} | ||
|
||
exec {"cp -p ${redis_file_name_orig} ${redis_file_name}": | ||
path => '/usr/bin:/bin', | ||
subscribe => File[$redis_file_name_orig], | ||
refreshonly => true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
require 'spec_helper_acceptance' | ||
|
||
describe 'redis::instance', :if => (fact('operatingsystem') == 'Ubuntu') do | ||
case fact('osfamily') | ||
when 'Debian' | ||
config_path = '/etc/redis/redis.conf' | ||
manage_repo = false | ||
redis_name = 'redis-server' | ||
else | ||
redis_name = 'redis' | ||
config_path = '/etc/redis.conf' | ||
manage_repo = true | ||
end | ||
|
||
it 'should run successfully' do | ||
pp = <<-EOS | ||
Exec { | ||
path => [ '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', ] | ||
} | ||
class { '::redis': | ||
manage_repo => #{manage_repo}, | ||
default_install => false, | ||
} | ||
redis::instance {'redis1': | ||
port => '7777', | ||
pid_file => '/var/run/redis/redis-server-redis1.pid', | ||
} | ||
redis::instance {'redis2': | ||
port => '8888', | ||
pid_file => '/var/run/redis/redis-server-redis2.pid', | ||
} | ||
EOS | ||
|
||
# Apply twice to ensure no errors the second time. | ||
apply_manifest(pp, :catch_failures => true) | ||
apply_manifest(pp, :catch_changes => true) | ||
end | ||
|
||
describe package(redis_name) do | ||
it { should be_installed } | ||
end | ||
|
||
describe service('redis1') do | ||
it { should be_running } | ||
end | ||
|
||
describe service('redis2') do | ||
it { should be_running } | ||
end | ||
|
||
describe file("#{config_path}.redis1") do | ||
its(:content) { should match /port 7777/ } | ||
end | ||
|
||
describe file("#{config_path}.redis2") do | ||
its(:content) { should match /port 8888/ } | ||
end | ||
|
||
context 'redis should respond to ping command' do | ||
describe command('redis-cli -h 127.0.0.1 -p 7777 ping') do | ||
its(:stdout) { should match /PONG/ } | ||
end | ||
|
||
describe command('redis-cli -h 127.0.0.1 -p 8888 ping') do | ||
its(:stdout) { should match /PONG/ } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'spec_helper' | ||
|
||
describe 'redis::instance', :type => :define do | ||
let :pre_condition do | ||
'class { "redis": | ||
default_install => false, | ||
}' | ||
end | ||
let :title do | ||
'redis2' | ||
end | ||
describe 'os-dependent items' do | ||
context "on RedHat based systems" do | ||
let(:facts) { | ||
ubuntu_1404_facts | ||
} | ||
it { should contain_file('/etc/redis.conf.puppet.redis2').with('content' => /^hash-max-zipmap-entries/) } | ||
it { should contain_service('redis2').with_ensure('running') } | ||
it { should contain_file('/etc/init.d/redis2').with_content(/DAEMON_ARGS=\/etc\/redis.conf.redis2/) } | ||
it { should contain_file('/etc/init.d/redis2').with_content(/PIDFILE=\/var\/run\/redis\/redis-server-redis2.pid/) } | ||
end | ||
end | ||
end |
Oops, something went wrong.