diff --git a/manifests/config.pp b/manifests/config.pp index a41b16c..7d9c5c9 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -1,81 +1,80 @@ # = Class: redis::config # # This class provides configuration for Redis. # class redis::config { File { owner => $::redis::config_owner, group => $::redis::config_group, mode => $::redis::config_file_mode, } file { $::redis::config_dir: ensure => directory, mode => $::redis::config_dir_mode, } file {$::redis::log_dir: ensure => directory, group => $::redis::service_group, mode => $::redis::log_dir_mode, owner => $::redis::service_user, } file {$::redis::workdir: ensure => directory, group => $::redis::service_group, mode => $::redis::workdir_mode, owner => $::redis::service_user, } if $::redis::default_install { redis::instance {'default': pid_file => $::redis::pid_file, log_file => $::redis::log_file, manage_service_file => $::redis::manage_service_file, unixsocket => $::redis::unixsocket, workdir => $::redis::workdir, } } if $::redis::ulimit { contain ::redis::ulimit } + $service_provider_lookup = pick(getvar_emptystring('service_provider'), false) + + if $service_provider_lookup != 'systemd' { + case $::operatingsystem { + 'Debian': { + $var_run_redis_mode = '2775' + } + default: { + $var_run_redis_mode = '0755' + } + } + + file { '/var/run/redis': + ensure => 'directory', + owner => $::redis::config_owner, + group => $::redis::config_group, + mode => $var_run_redis_mode, + } + } + # Adjust /etc/default/redis-server on Debian systems case $::osfamily { 'Debian': { file { '/etc/default/redis-server': ensure => present, group => $::redis::config_group, mode => $::redis::config_file_mode, owner => $::redis::config_owner, } - - $service_provider_lookup = pick(getvar_emptystring('service_provider'), false) - - if $service_provider_lookup != 'systemd' { - case $::operatingsystem { - 'Debian': { - $var_run_redis_mode = '2775' - } - default: { - $var_run_redis_mode = '0755' - } - } - - file { '/var/run/redis': - ensure => 'directory', - owner => $::redis::config_owner, - group => $::redis::config_group, - mode => $var_run_redis_mode, - } - } - } default: { } } } diff --git a/manifests/params.pp b/manifests/params.pp index aff82c8..c5af7e8 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -1,321 +1,322 @@ # = Class: redis::params # # This class provides a number of parameters. # class redis::params { # Generic $manage_repo = false $manage_package = true $managed_by_cluster_manager = false # redis.conf.erb $activerehashing = true $aof_load_truncated = true $aof_rewrite_incremental_fsync = true $appendfilename = 'appendonly.aof' $appendfsync = 'everysec' $appendonly = false $auto_aof_rewrite_min_size = '64mb' $auto_aof_rewrite_percentage = 100 $bind = '127.0.0.1' $output_buffer_limit_slave = '256mb 64mb 60' $output_buffer_limit_pubsub = '32mb 8mb 60' $conf_template = 'redis/redis.conf.erb' $default_install = true $databases = 16 $dbfilename = 'dump.rdb' $extra_config_file = undef $hash_max_ziplist_entries = 512 $hash_max_ziplist_value = 64 $hll_sparse_max_bytes = 3000 $hz = 10 $latency_monitor_threshold = 0 $list_max_ziplist_entries = 512 $list_max_ziplist_value = 64 $log_dir = '/var/log/redis' $log_file = '/var/log/redis/redis.log' $log_level = 'notice' $manage_service_file = false $maxclients = 10000 $maxmemory = undef $maxmemory_policy = undef $maxmemory_samples = undef $no_appendfsync_on_rewrite = false $notify_keyspace_events = undef $notify_service = true $port = 6379 $rdbcompression = true $requirepass = undef $save_db_to_disk = true $save_db_to_disk_interval = {'900' =>'1', '300' => '10', '60' => '10000'} $sentinel_auth_pass = undef $sentinel_bind = undef $sentinel_config_file_mode = '0644' $sentinel_config_group = 'root' $sentinel_config_owner = 'redis' $sentinel_conf_template = 'redis/redis-sentinel.conf.erb' $sentinel_down_after = 30000 $sentinel_failover_timeout = 180000 $sentinel_master_name = 'mymaster' $sentinel_parallel_sync = 1 $sentinel_port = 26379 $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' $sentinel_notification_script = undef $sentinel_client_reconfig_script = undef $service_provider = undef $set_max_intset_entries = 512 $slave_priority = 100 $slowlog_log_slower_than = 10000 $slowlog_max_len = 1024 $stop_writes_on_bgsave_error = true $syslog_enabled = undef $syslog_facility = undef $tcp_backlog = 511 $tcp_keepalive = 0 $timeout = 0 $ulimit = 65536 $unixsocket = '/var/run/redis/redis.sock' $unixsocketperm = 755 $zset_max_ziplist_entries = 128 $zset_max_ziplist_value = 64 # redis.conf.erb - replication $masterauth = undef $min_slaves_to_write = 0 $min_slaves_max_lag = 10 $repl_backlog_size = '1mb' $repl_backlog_ttl = 3600 $repl_disable_tcp_nodelay = false $repl_ping_slave_period = 10 $repl_timeout = 60 $slave_read_only = true $slave_serve_stale_data = true $slaveof = undef # redis.conf.erb - redis 3.0 clustering $cluster_enabled = false $cluster_config_file = 'nodes.conf' $cluster_node_timeout = 5000 case $::osfamily { 'Debian': { $config_dir = '/etc/redis' $config_dir_mode = '0755' $config_file = '/etc/redis/redis.conf' $config_file_mode = '0644' $config_file_orig = '/etc/redis/redis.conf.puppet' $config_owner = 'redis' $daemonize = true $log_dir_mode = '0755' $package_ensure = 'present' $package_name = 'redis-server' $pid_file = '/var/run/redis/redis-server.pid' $sentinel_config_file = '/etc/redis/sentinel.conf' $sentinel_config_file_orig = '/etc/redis/redis-sentinel.conf.puppet' $sentinel_daemonize = true $sentinel_init_script = '/etc/init.d/redis-sentinel' $sentinel_package_name = 'redis-sentinel' $sentinel_package_ensure = 'present' $service_manage = true $service_enable = true $service_ensure = 'running' $service_group = 'redis' $service_hasrestart = true $service_hasstatus = true $service_name = 'redis-server' $service_user = 'redis' $ppa_repo = 'ppa:chris-lea/redis-server' $workdir = '/var/lib/redis' $workdir_mode = '0750' case $::operatingsystem { 'Ubuntu': { $config_group = 'redis' case $::operatingsystemmajrelease { '14.04': { # upstream package is 2.8.4 $minimum_version = '2.8.4' } '16.04': { # upstream package is 3.0.3 $minimum_version = '3.0.3' } default: { warning("Ubuntu release ${::operatingsystemmajrelease} isn't 'officially' supported by module, but will git it a shot") $minimum_version = '2.8.5' } } } default: { $config_group = 'root' # Debian standard package is 2.4.14 # But we have dotdeb repo which is 3.2.5 $minimum_version = '3.2.5' } } } 'RedHat': { $config_dir = '/etc/redis' $config_dir_mode = '0755' $config_file = '/etc/redis.conf' $config_file_mode = '0644' $config_file_orig = '/etc/redis.conf.puppet' $config_group = 'root' $config_owner = 'redis' $daemonize = true $log_dir_mode = '0755' $package_ensure = 'present' $package_name = 'redis' $pid_file = '/var/run/redis/redis.pid' $sentinel_config_file = '/etc/redis-sentinel.conf' $sentinel_config_file_orig = '/etc/redis-sentinel.conf.puppet' $sentinel_daemonize = false $sentinel_init_script = undef $sentinel_package_name = 'redis' $sentinel_package_ensure = 'present' $service_manage = true $service_enable = true $service_ensure = 'running' $service_hasrestart = true $service_hasstatus = true $service_name = 'redis' $service_user = 'redis' $ppa_repo = undef $workdir = '/var/lib/redis' $workdir_mode = '0755' case $::operatingsystemmajrelease { '6': { - # CentOS 6 EPEL package is 2.4.10 - $minimum_version = '2.4.10' + # CentOS 6 EPEL package is just updated to 3.2.10 + # https://bugzilla.redhat.com/show_bug.cgi?id=923970 + $minimum_version = '3.2.10' $service_group = 'root' } '7': { # CentOS 7 EPEL package is 3.2.3 $minimum_version = '3.2.3' $service_group = 'redis' } default: { fail("Not sure what Redis version is avaliable upstream on your release: ${::operatingsystemmajrelease}") } } } 'FreeBSD': { $config_dir = '/usr/local/etc/redis' $config_dir_mode = '0755' $config_file = '/usr/local/etc/redis.conf' $config_file_mode = '0644' $config_file_orig = '/usr/local/etc/redis.conf.puppet' $config_group = 'wheel' $config_owner = 'redis' $daemonize = true $log_dir_mode = '0755' $package_ensure = 'present' $package_name = 'redis' $pid_file = '/var/run/redis/redis.pid' $sentinel_config_file = '/usr/local/etc/redis-sentinel.conf' $sentinel_config_file_orig = '/usr/local/etc/redis-sentinel.conf.puppet' $sentinel_daemonize = true $sentinel_init_script = undef $sentinel_package_name = 'redis' $sentinel_package_ensure = 'present' $service_manage = true $service_enable = true $service_ensure = 'running' $service_group = 'redis' $service_hasrestart = true $service_hasstatus = true $service_name = 'redis' $service_user = 'redis' $ppa_repo = undef $workdir = '/var/db/redis' $workdir_mode = '0750' # pkg version $minimum_version = '3.2.4' } 'Suse': { $config_dir = '/etc/redis' $config_dir_mode = '0750' $config_file = '/etc/redis/redis-server.conf' $config_file_mode = '0644' $config_group = 'redis' $config_owner = 'redis' $daemonize = true $log_dir_mode = '0750' $package_ensure = 'present' $package_name = 'redis' $pid_file = '/var/run/redis/redis-server.pid' $sentinel_config_file = '/etc/redis/redis-sentinel.conf' $sentinel_config_file_orig = '/etc/redis/redis-sentinel.conf.puppet' $sentinel_daemonize = true $sentinel_init_script = undef $sentinel_package_name = 'redis' $sentinel_package_ensure = 'present' $service_manage = true $service_enable = true $service_ensure = 'running' $service_group = 'redis' $service_hasrestart = true $service_hasstatus = true $service_name = 'redis' $service_user = 'redis' $ppa_repo = undef $workdir = '/var/lib/redis' $workdir_mode = '0750' # suse package version $minimum_version = '3.0.5' } 'Archlinux': { $config_dir = '/etc/redis' $config_dir_mode = '0755' $config_file = '/etc/redis/redis.conf' $config_file_mode = '0644' $config_file_orig = '/etc/redis/redis.conf.puppet' $config_group = 'root' $config_owner = 'root' $daemonize = true $log_dir_mode = '0755' $package_ensure = 'present' $package_name = 'redis' $pid_file = '/var/run/redis.pid' $sentinel_config_file = '/etc/redis/redis-sentinel.conf' $sentinel_config_file_orig = '/etc/redis/redis-sentinel.conf.puppet' $sentinel_daemonize = true $sentinel_init_script = undef $sentinel_package_name = 'redis' $sentinel_package_ensure = 'present' $service_manage = true $service_enable = true $service_ensure = 'running' $service_group = 'redis' $service_hasrestart = true $service_hasstatus = true $service_name = 'redis' $service_user = 'redis' $ppa_repo = undef $workdir = '/var/lib/redis' $workdir_mode = '0750' # pkg version $minimum_version = '3.2.4' } default: { fail "Operating system ${::operatingsystem} is not supported yet." } } } diff --git a/spec/classes/redis_centos_6_spec.rb b/spec/classes/redis_centos_6_spec.rb index 250d0cc..3da820c 100644 --- a/spec/classes/redis_centos_6_spec.rb +++ b/spec/classes/redis_centos_6_spec.rb @@ -1,90 +1,75 @@ require 'spec_helper' describe 'redis' do context 'on CentOS 6' do let(:facts) { centos_6_facts } context 'should set CentOS specific values' do - context 'when $::redis_server_version fact is not present (older features not enabled)' do - - let(:facts) { - centos_6_facts.merge({ - :redis_server_version => nil, - :puppetversion => Puppet.version, - }) - } - - it { should contain_file('/etc/redis.conf.puppet').with('content' => /^hash-max-zipmap-entries/) } - it { should contain_file('/etc/redis.conf.puppet').without('content' => /^hash-max-ziplist-entries/) } - it { should contain_file('/etc/redis.conf.puppet').without('content' => /^tcp-backlog/) } - - end - context 'when $::redis_server_version fact is not present and package_ensure is a newer version(3.2.1) (older features enabled)' do let(:facts) { centos_6_facts.merge({ :redis_server_version => nil, :puppetversion => Puppet.version, }) } let (:params) { { :package_ensure => '3.2.1' } } it { should contain_file('/etc/redis.conf.puppet').without('content' => /^hash-max-zipmap-entries/) } it { should contain_file('/etc/redis.conf.puppet').with('content' => /^hash-max-ziplist-entries/) } it { should contain_file('/etc/redis.conf.puppet').with('content' => /^tcp-backlog/) } end context 'when $::redis_server_version fact is not present and package_ensure is a newer version(4.0-rc3) (older features enabled)' do let(:facts) { centos_6_facts.merge({ :redis_server_version => nil, :puppetversion => Puppet.version, }) } let (:params) { { :package_ensure => '4.0-rc3' } } it { should contain_file('/etc/redis.conf.puppet').without('content' => /^hash-max-zipmap-entries/) } it { should contain_file('/etc/redis.conf.puppet').with('content' => /^hash-max-ziplist-entries/) } it { should contain_file('/etc/redis.conf.puppet').with('content' => /^tcp-backlog/) } end context 'when $::redis_server_version fact is present but the older version (older features not enabled)' do let(:facts) { centos_6_facts.merge({ :redis_server_version => '2.4.10', :puppetversion => Puppet.version, }) } it { should contain_file('/etc/redis.conf.puppet').with('content' => /^hash-max-zipmap-entries/) } it { should contain_file('/etc/redis.conf.puppet').without('content' => /^hash-max-ziplist-entries/) } it { should contain_file('/etc/redis.conf.puppet').without('content' => /^tcp-backlog/) } end context 'when $::redis_server_version fact is present but a newer version (older features enabled)' do let(:facts) { centos_6_facts.merge({ :redis_server_version => '3.2.1', :puppetversion => Puppet.version, }) } it { should contain_file('/etc/redis.conf.puppet').without('content' => /^hash-max-zipmap-entries/) } it { should contain_file('/etc/redis.conf.puppet').with('content' => /^hash-max-ziplist-entries/) } it { should contain_file('/etc/redis.conf.puppet').with('content' => /^tcp-backlog/) } end end end end diff --git a/templates/service_templates/redis.RedHat.erb b/templates/service_templates/redis.RedHat.erb index e061bda..ab3dc8d 100644 --- a/templates/service_templates/redis.RedHat.erb +++ b/templates/service_templates/redis.RedHat.erb @@ -1,104 +1,104 @@ #!/bin/sh # # redis init file for starting up the redis daemon # # chkconfig: - 20 80 # description: Starts and stops the redis daemon. # ### BEGIN INIT INFO # Provides: redis-server-<%= @name %> # Required-Start: $local_fs $remote_fs $network # Required-Stop: $local_fs $remote_fs $network # Short-Description: start and stop Redis server instance <%= @name %> # Description: A persistent key-value database ### END INIT INFO # Source function library. . /etc/rc.d/init.d/functions name="redis-server-<%= @name %>" -exec="/usr/sbin/redis-server" +exec="/usr/bin/redis-server" pidfile="/var/run/redis/redis-server-<%= @name %>.pid" REDIS_CONFIG="<%= @redis_file_name %>" [ -e /etc/sysconfig/redis ] && . /etc/sysconfig/redis lockfile=/var/lock/subsys/redis-<%= @name %> start() { [ -f $REDIS_CONFIG ] || exit 6 [ -x $exec ] || exit 5 echo -n $"Starting $name: " daemon --user ${REDIS_USER-redis} "$exec $REDIS_CONFIG" retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $name: " [ -x $shut ] && $shut retval=$? if [ -f $pidfile ] then # shutdown haven't work, try old way killproc -p $pidfile $name retval=$? else success "$name shutdown" fi echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } restart() { stop start } reload() { false } rh_status() { status -p $pidfile $name } rh_status_q() { rh_status >/dev/null 2>&1 } case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart) $1 ;; reload) rh_status_q || exit 7 $1 ;; force-reload) force_reload ;; status) rh_status ;; condrestart|try-restart) rh_status_q || exit 0 restart ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart}" exit 2 esac exit $?