From e37283ed71542be00046507005b4e861e72d55ed Mon Sep 17 00:00:00 2001 From: bovy89 Date: Fri, 4 Dec 2015 09:47:19 +0100 Subject: [PATCH 01/18] Added the possibility to exclude logrotate --- README.md | 8 ++++++++ manifests/sentinel.pp | 28 ++++++++++++++++------------ manifests/server.pp | 28 ++++++++++++++++------------ 3 files changed, 40 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 4f528f4..d868457 100644 --- a/README.md +++ b/README.md @@ -366,6 +366,10 @@ Since redis automatically rewrite their config since version 2.8 setting this to `true` will trigger a redis restart on each puppet run with redis 2.8 or later. +#####`manage_logrotate` + +Configure logrotate rules for redis server. Default: true + ##### High Availability Options #####`slaveof` @@ -459,6 +463,10 @@ sentinel restart. Since sentinels automatically rewrite their config since version 2.8 setting this to `true` will trigger a sentinel restart on each puppet run with redis 2.8 or later. +#####`manage_logrotate` + +Configure logrotate rules for redis server. Default: true + ##Requirements ###Modules needed: diff --git a/manifests/sentinel.pp b/manifests/sentinel.pp index 043bc54..06497f9 100644 --- a/manifests/sentinel.pp +++ b/manifests/sentinel.pp @@ -40,7 +40,8 @@ # sentinel restart. Since sentinels automatically rewrite their config since # version 2.8 setting this to `true` will trigger a sentinel restart on each puppet # run with redis 2.8 or later. -# +# [*manage_logrotate*] +# Configure logrotate rules for redis sentinel. Default: true define redis::sentinel ( $ensure = 'present', $sentinel_name = $name, @@ -64,6 +65,7 @@ $running = true, $enabled = true, $force_rewrite = false, + $manage_logrotate = true, ) { # validate parameters @@ -101,18 +103,20 @@ hasrestart => true, } - # install and configure logrotate - if ! defined(Package['logrotate']) { - package { 'logrotate': ensure => installed; } - } + if ($manage_logrotate == true){ + # install and configure logrotate + if ! defined(Package['logrotate']) { + package { 'logrotate': ensure => installed; } + } - file { "/etc/logrotate.d/redis-sentinel_${sentinel_name}": - ensure => file, - content => template('redis/sentinel_logrotate.conf.erb'), - require => [ - Package['logrotate'], - File["/etc/redis-sentinel_${sentinel_name}.conf"], - ] + file { "/etc/logrotate.d/redis-sentinel_${sentinel_name}": + ensure => file, + content => template('redis/sentinel_logrotate.conf.erb'), + require => [ + Package['logrotate'], + File["/etc/redis-sentinel_${sentinel_name}.conf"], + ] + } } } diff --git a/manifests/server.pp b/manifests/server.pp index 208a3df..e270774 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -84,7 +84,8 @@ # redis restart. Since redis automatically rewrite their config since # version 2.8 setting this to `true` will trigger a sentinel restart on each puppet # run with redis 2.8 or later. -# +# [*manage_logrotate*] +# Configure logrotate rules for redis server. Default: true define redis::server ( $redis_name = $name, $redis_memory = '100mb', @@ -124,6 +125,7 @@ $hash_max_ziplist_entries = 512, $hash_max_ziplist_value = 64, $force_rewrite = false, + $manage_logrotate = true, ) { $redis_user = $::redis::install::redis_user $redis_group = $::redis::install::redis_group @@ -176,18 +178,20 @@ group => $redis_group, } - # install and configure logrotate - if ! defined(Package['logrotate']) { - package { 'logrotate': ensure => installed; } - } + if ($manage_logrotate == true){ + # install and configure logrotate + if ! defined(Package['logrotate']) { + package { 'logrotate': ensure => installed; } + } - file { "/etc/logrotate.d/redis-server_${redis_name}": - ensure => file, - content => template('redis/redis_logrotate.conf.erb'), - require => [ - Package['logrotate'], - File["/etc/redis_${redis_name}.conf"], - ] + file { "/etc/logrotate.d/redis-server_${redis_name}": + ensure => file, + content => template('redis/redis_logrotate.conf.erb'), + require => [ + Package['logrotate'], + File["/etc/redis_${redis_name}.conf"], + ] + } } # manage redis service From 49529309c7c52cff475ba2dadfff5e34a3383120 Mon Sep 17 00:00:00 2001 From: Stanislav Voroniy Date: Tue, 22 Dec 2015 15:15:14 +0100 Subject: [PATCH 02/18] RH/CentOS 7 systemd support Update config without manual actions with force_rewrite --- manifests/sentinel.pp | 57 ++++++++++++------ manifests/server.pp | 58 +++++++++++++------ .../etc/init.d/debian_redis-sentinel.erb | 5 +- templates/etc/init.d/debian_redis-server.erb | 5 +- .../etc/init.d/redhat_redis-sentinel.erb | 5 +- templates/etc/init.d/redhat_redis-server.erb | 5 +- templates/etc/init.d/sles_redis-server.erb | 5 +- templates/etc/redis.conf.erb | 4 ++ templates/etc/sentinel.conf.erb | 4 ++ templates/systemd/redis.service.erb | 13 +++++ templates/systemd/sentinel.service.erb | 14 +++++ 11 files changed, 134 insertions(+), 41 deletions(-) create mode 100644 templates/systemd/redis.service.erb create mode 100644 templates/systemd/sentinel.service.erb diff --git a/manifests/sentinel.pp b/manifests/sentinel.pp index 06497f9..6d2fc03 100644 --- a/manifests/sentinel.pp +++ b/manifests/sentinel.pp @@ -32,14 +32,12 @@ # Configure if Sentinel should be running or not. Default: true # [*enabled*] # Configure if Sentinel is started at boot. Default: true -# [*force_rewrite*] +# [*sentinel_run_dir*] # -# Boolean. Default: `false` +# Default: `/var/run/redis` # -# Configure if the sentinels config is overwritten by puppet followed by a -# sentinel restart. Since sentinels automatically rewrite their config since -# version 2.8 setting this to `true` will trigger a sentinel restart on each puppet -# run with redis 2.8 or later. +# Since sentinels automatically rewrite their config since version 2.8 the puppet managed config will be copied +# to this directory and than sentinel will start with this copy. # [*manage_logrotate*] # Configure logrotate rules for redis sentinel. Default: true define redis::sentinel ( @@ -48,6 +46,7 @@ $sentinel_port = 26379, $sentinel_log_dir = '/var/log', $sentinel_pid_dir = '/var/run', + $sentinel_run_dir = '/var/run/redis', $monitors = { 'mymaster' => { master_host => '127.0.0.1', @@ -64,12 +63,17 @@ }, $running = true, $enabled = true, - $force_rewrite = false, $manage_logrotate = true, ) { # validate parameters - validate_bool($force_rewrite) + validate_absolute_path($sentinel_log_dir) + validate_absolute_path($sentinel_pid_dir) + validate_absolute_path($sentinel_run_dir) + validate_hash($monitors) + validate_bool($running) + validate_bool($enabled) + validate_bool($manage_logrotate) $redis_install_dir = $::redis::install::redis_install_dir $sentinel_init_script = $::operatingsystem ? { @@ -79,21 +83,40 @@ } # redis conf file - file { - "/etc/redis-sentinel_${sentinel_name}.conf": + $conf_file_name = "redis-sentinel_${sentinel_name}.conf" + $conf_file = "/etc/${conf_file_name}" + file { $conf_file: ensure => file, content => template('redis/etc/sentinel.conf.erb'), replace => $force_rewrite, require => Class['redis::install']; - - }-> + } # startup script - file { "/etc/init.d/redis-sentinel_${sentinel_name}": - ensure => file, - mode => '0755', - content => template($sentinel_init_script), - }~> + if ($::osfamily == 'RedHat' and versioncmp($::operatingsystemmajrelease, '7') >=0) { + $service_file = "/usr/lib/systemd/system/redis-sentinel_${sentinel_name}.service" + exec { "systemd_service_${sentinel_name}_preset": + command => "/bin/systemctl preset redis-sentinel_${sentinel_name}.service", + notify => Service["redis-sentinel_${sentinel_name}"], + } + + file { $service_file: + ensure => file, + mode => '0755', + content => template('redis/systemd/sentinel.service.erb'), + require => File["/etc/redis-sentinel_${sentinel_name}.conf"], + notify => Exec["systemd_service_${sentinel_name}_preset"], + } + } else { + $service_file = "/etc/init.d/redis-sentinel_${sentinel_name}" + file { $service_file: + ensure => file, + mode => '0755', + content => template($sentinel_init_script), + require => File["/etc/redis-sentinel_${sentinel_name}.conf"], + notify => Service["redis-sentinel_${sentinel_name}"], + } + } # manage sentinel service service { "redis-sentinel_${sentinel_name}": diff --git a/manifests/server.pp b/manifests/server.pp index e270774..207ce52 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -76,14 +76,14 @@ # [*hash_max_ziplist_value*] # Threshold for ziplist value. Default: 64 # -# [*force_rewrite*] +# [*redis_run_dir*] # -# Boolean. Default: `false` +# Default: `/var/run/redis` # -# Configure if the redis config is overwritten by puppet followed by a -# redis restart. Since redis automatically rewrite their config since -# version 2.8 setting this to `true` will trigger a sentinel restart on each puppet -# run with redis 2.8 or later. +# Since redis automatically rewrite their config since version 2.8 what conflicts with puppet +# the config files created by puppet will be copied to this directory and redis will be started from +# this copy. +# # [*manage_logrotate*] # Configure logrotate rules for redis server. Default: true define redis::server ( @@ -102,6 +102,7 @@ $redis_dir = '/var/lib', $redis_log_dir = '/var/log', $redis_pid_dir = '/var/run', + $redis_run_dir = '/var/run/redis', $redis_loglevel = 'notice', $redis_appedfsync = 'everysec', $running = true, @@ -124,7 +125,6 @@ $save = [], $hash_max_ziplist_entries = 512, $hash_max_ziplist_value = 64, - $force_rewrite = false, $manage_logrotate = true, ) { $redis_user = $::redis::install::redis_user @@ -140,8 +140,8 @@ $redis_2_6_or_greater = versioncmp($::redis::install::redis_version,'2.6') >= 0 # redis conf file - file { - "/etc/redis_${redis_name}.conf": + $conf_file = "/etc/redis_${redis_name}.conf" + file { $conf_file: ensure => file, content => template('redis/etc/redis.conf.erb'), replace => $force_rewrite, @@ -149,15 +149,35 @@ } # startup script - file { "/etc/init.d/redis-server_${redis_name}": - ensure => file, - mode => '0755', - content => template($redis_init_script), - require => [ - File["/etc/redis_${redis_name}.conf"], - File["${redis_dir}/redis_${redis_name}"] - ], - notify => Service["redis-server_${redis_name}"], + if ($::osfamily == 'RedHat' and versioncmp($::operatingsystemmajrelease, '7') >=0) { + $service_file = "/usr/lib/systemd/system/redis-server_${redis_name}.service" + exec { "systemd_service_${redis_name}_preset": + command => "/bin/systemctl preset redis-server_${redis_name}.service", + notify => Service["redis-server_${redis_name}"], + } + + file { $service_file: + ensure => file, + mode => '0755', + content => template('redis/systemd/redis.service.erb'), + require => [ + File["/etc/redis_${redis_name}.conf"], + File["${redis_dir}/redis_${redis_name}"] + ], + notify => Exec["systemd_service_${redis_name}_preset"], + } + } else { + $service_file = "/etc/init.d/redis-server_${redis_name}" + file { $service_file: + ensure => file, + mode => '0755', + content => template($redis_init_script), + require => [ + File["/etc/redis_${redis_name}.conf"], + File["${redis_dir}/redis_${redis_name}"] + ], + notify => Service["redis-server_${redis_name}"], + } } # path for persistent data @@ -200,6 +220,6 @@ enable => $enabled, hasstatus => true, hasrestart => true, - require => File["/etc/init.d/redis-server_${redis_name}"] + require => File["${service_file}"] } } diff --git a/templates/etc/init.d/debian_redis-sentinel.erb b/templates/etc/init.d/debian_redis-sentinel.erb index 4f9bc57..d63b755 100644 --- a/templates/etc/init.d/debian_redis-sentinel.erb +++ b/templates/etc/init.d/debian_redis-sentinel.erb @@ -16,6 +16,7 @@ REDIS_NAME="redis-sentinel_<%= @sentinel_name %>" REDIS_PID="<%= @sentinel_pid_dir %>/redis-sentinel_<%= @sentinel_name %>.pid" REDIS_LOCKFILE="/var/lock/redis-sentinel_<%= @sentinel_name %>" REDIS_CONF_FILE="/etc/redis-sentinel_<%= @sentinel_name %>.conf" +RUNTIME_CONF_FILE="<%= @sentinel_run_dir %>/redis-sentinel_<%= @sentinel_name %>.conf" [ -x "$REDIS_EXEC" ] || exit 5 @@ -23,9 +24,11 @@ start() { local retval [ -f "$REDIS_CONF_FILE" ] || exit 6 + [ -d <%= @sentinel_run_dir %> ] mkdir -p <%= @sentinel_run_dir %> + cp -u $REDIS_CONF_FILE $RUNTIME_CONF_FILE log_daemon_msg "Starting $REDIS_NAME" - start-stop-daemon --start --quiet --pidfile "$REDIS_PID" --retry 5 --exec "$REDIS_EXEC" --oknodo -- "$REDIS_CONF_FILE" + start-stop-daemon --start --quiet --pidfile "$REDIS_PID" --retry 5 --exec "$REDIS_EXEC" --oknodo -- "$RUNTIME_CONF_FILE" retval=$? log_end_msg $retval diff --git a/templates/etc/init.d/debian_redis-server.erb b/templates/etc/init.d/debian_redis-server.erb index f6c6157..2443ff9 100644 --- a/templates/etc/init.d/debian_redis-server.erb +++ b/templates/etc/init.d/debian_redis-server.erb @@ -16,6 +16,7 @@ REDIS_NAME="redis-server_<%= @redis_name %>" REDIS_PID="<%= @redis_pid_dir %>/redis_<%= @redis_name %>.pid" REDIS_LOCKFILE="/var/lock/redis_<%= @redis_name %>" REDIS_CONF_FILE="/etc/redis_<%= @redis_name %>.conf" +RUNTIME_CONF_FILE="<%= @redis_run_dir %>/redis_<%= @redis_name %>.conf" [ -x "$REDIS_EXEC" ] || exit 5 @@ -23,9 +24,11 @@ start() { local retval [ -f "$REDIS_CONF_FILE" ] || exit 6 + [ -d <%= @redis_run_dir %> ] ||mkdir -p <%= @redis_run_dir %> log_daemon_msg "Starting $REDIS_NAME" - start-stop-daemon --start --quiet --pidfile "$REDIS_PID" --retry 5 --exec "$REDIS_EXEC" --oknodo -- "$REDIS_CONF_FILE" + cp -u $REDIS_CONF_FILE $RUNTIME_CONF_FILE + start-stop-daemon --start --quiet --pidfile "$REDIS_PID" --retry 5 --exec "$REDIS_EXEC" --oknodo -- "$RUNTIME_CONF_FILE" retval=$? log_end_msg $retval diff --git a/templates/etc/init.d/redhat_redis-sentinel.erb b/templates/etc/init.d/redhat_redis-sentinel.erb index 113c7e6..31560c0 100644 --- a/templates/etc/init.d/redhat_redis-sentinel.erb +++ b/templates/etc/init.d/redhat_redis-sentinel.erb @@ -24,14 +24,17 @@ pidfile="<%= @sentinel_pid_dir %>/redis-sentinel_<%= @sentinel_name %>.pid" logfile="<%= @sentinel_log_dir -%>/redis-sentinel_<%= @sentinel_name %>.log" SENTINEL_CONF_FILE="/etc/redis-sentinel_<%= @sentinel_name %>.conf" +RUNTIME_CONF_FILE="<%= @sentinel_run_dir %>/redis-sentinel_<%= @sentinel_name %>.conf" lockfile="/var/lock/subsys/redis-sentinel_<%= @sentinel_name %>" start() { [ -x $sentinel ] || exit 5 [ -f $SENTINEL_CONF_FILE ] || exit 6 + [ -d <%= @sentinel_run_dir %> ] || mkdir -p <%= @sentinel_run_dir %> echo -n $"Starting $prog: " - daemon $sentinel $SENTINEL_CONF_FILE --pidfile $pidfile + cp -u $SENTINEL_CONF_FILE $RUNTIME_CONF_FILE + daemon $sentinel $RUNTIME_CONF_FILE --pidfile $pidfile retval=$? echo [ $retval -eq 0 ] && touch $lockfile diff --git a/templates/etc/init.d/redhat_redis-server.erb b/templates/etc/init.d/redhat_redis-server.erb index f507d7e..27b3c0d 100644 --- a/templates/etc/init.d/redhat_redis-server.erb +++ b/templates/etc/init.d/redhat_redis-server.erb @@ -23,6 +23,7 @@ prog="redis_<%= @redis_name %>" pidfile="<%= @redis_pid_dir %>/redis_<%= @redis_name %>.pid" REDIS_CONF_FILE="/etc/redis_<%= @redis_name %>.conf" +RUNTIME_CONF_FILE="<%= @redis_run_dir %>/redis_<%= @redis_name %>.conf" #[ -f /etc/sysconfig/redis ] && . /etc/sysconfig/redis @@ -31,8 +32,10 @@ lockfile="/var/lock/subsys/redis_<%= @redis_name %>" start() { [ -x $redis ] || exit 5 [ -f $REDIS_CONF_FILE ] || exit 6 + [ -d <%= @redis_pid_dir %> ] || mkdir -p <%= @redis_pid_dir %> echo -n $"Starting $prog: " - daemon $redis $REDIS_CONF_FILE + cp -u $REDIS_CONF_FILE $RUNTIME_CONF_FILE + daemon $redis $RUNTIME_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile diff --git a/templates/etc/init.d/sles_redis-server.erb b/templates/etc/init.d/sles_redis-server.erb index 42389aa..3335710 100644 --- a/templates/etc/init.d/sles_redis-server.erb +++ b/templates/etc/init.d/sles_redis-server.erb @@ -28,6 +28,7 @@ STATE=<%= @redis_pid_dir %> CONF=/etc PIDFILE=${STATE}/redis_<%= @redis_name %>.pid CONFIG=${CONF}/redis_<%= @redis_name %>.conf +RUN_CONFIG=<%= @redis_run_dir %>/redis_<%= @redis_name %>.conf . /etc/rc.status @@ -46,7 +47,9 @@ start() { echo -n "PID file detected, assuming that this instance is already running (PID `cat ${PIDFILE}`)". else rm -f ${PIDFILE} - sudo -u $USER $EXEC $CONFIG + [ -d <%= @redis_run_dir %> ] || mkdir -p <%= @redis_run_dir %> + cp -u $CONFIG $RUN_CONFIG + sudo -u $USER $EXEC $RUN_CONFIG fi rc_status -v } diff --git a/templates/etc/redis.conf.erb b/templates/etc/redis.conf.erb index 518cfdd..8d4a528 100644 --- a/templates/etc/redis.conf.erb +++ b/templates/etc/redis.conf.erb @@ -14,9 +14,13 @@ # # units are case insensitive so 1GB 1Gb 1gB are all the same. +<% if @osfamily == 'RedHat' and scope.function_versioncmp([@operatingsystemmajrelease, '7']) >= 0 -%> +daemonize no +<% else -%> # By default Redis does not run as a daemon. Use 'yes' if you need it. # Note that Redis will write a pid file in <%= @redis_pid_dir %>/redis_<%= @redis_name %>.pid when daemonized. daemonize yes +<% end -%> # When running daemonized, Redis writes a pid file in <%= @redis_pid_dir %>/redis.pid by # default. You can specify a custom pid file location here. diff --git a/templates/etc/sentinel.conf.erb b/templates/etc/sentinel.conf.erb index 5ba896b..941b5f9 100644 --- a/templates/etc/sentinel.conf.erb +++ b/templates/etc/sentinel.conf.erb @@ -2,7 +2,11 @@ # !!! generated by puppet !!! +<% if @osfamily == 'RedHat' and scope.function_versioncmp([@operatingsystemmajrelease, '7']) >= 0 -%> +daemonize no +<% else -%> daemonize yes +<% end -%> pidfile <%= @sentinel_pid_dir %>/redis-sentinel_<%= @sentinel_name %>.pid diff --git a/templates/systemd/redis.service.erb b/templates/systemd/redis.service.erb new file mode 100644 index 0000000..80198cb --- /dev/null +++ b/templates/systemd/redis.service.erb @@ -0,0 +1,13 @@ +[Unit] +Description=Redis persistent key-value database server +After=network.target + +[Service] +ExecStartPre=/bin/cp -u <%= @conf_file %> <%= @redis_run_dir %>/<%= @conf_file_name %> +ExecStart=/usr/bin/redis-server <%= @redis_run_dir %>/<%= @conf_file_name %> --daemonize no +ExecStop=/usr/bin/redis-shutdown redis_<%= @redis_name %> +User=redis +Group=redis + +[Install] +WantedBy=multi-user.target diff --git a/templates/systemd/sentinel.service.erb b/templates/systemd/sentinel.service.erb new file mode 100644 index 0000000..049a9f8 --- /dev/null +++ b/templates/systemd/sentinel.service.erb @@ -0,0 +1,14 @@ +[Unit] +Description=Redis Sentinel +After=network.target + +[Service] +ExecStartPre=/bin/cp -u <%= @conf_file %> <%= @sentinel_run_dir %>/<%= @conf_file_name %> +ExecStart=/usr/bin/redis-sentinel <%= @sentinel_run_dir %>/<%= @conf_file_name %> --daemonize no +ExecStop=/usr/bin/redis-shutdown redis-sentinel_<%= @sentinel_name %> +User=redis +Group=redis + +[Install] +WantedBy=multi-user.target + From 48d1964a405e8c49cb678e71107a41914614a9d4 Mon Sep 17 00:00:00 2001 From: Stanislav Voroniy Date: Tue, 22 Dec 2015 15:43:25 +0100 Subject: [PATCH 03/18] Add binding ip option to sentinel --- manifests/sentinel.pp | 3 +++ templates/etc/sentinel.conf.erb | 17 ++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/manifests/sentinel.pp b/manifests/sentinel.pp index 6d2fc03..708443f 100644 --- a/manifests/sentinel.pp +++ b/manifests/sentinel.pp @@ -5,6 +5,8 @@ # # [*sentinel_name*] # Name of Sentinel instance. Default: call name of the function. +# [*sentinel_ip*] +# Listen IP. # [*sentinel_port*] # Listen port of Redis. Default: 26379 # [*sentinel_log_dir*] @@ -43,6 +45,7 @@ define redis::sentinel ( $ensure = 'present', $sentinel_name = $name, + $sentinel_ip = undef, $sentinel_port = 26379, $sentinel_log_dir = '/var/log', $sentinel_pid_dir = '/var/run', diff --git a/templates/etc/sentinel.conf.erb b/templates/etc/sentinel.conf.erb index 941b5f9..a2c9f34 100644 --- a/templates/etc/sentinel.conf.erb +++ b/templates/etc/sentinel.conf.erb @@ -12,18 +12,21 @@ pidfile <%= @sentinel_pid_dir %>/redis-sentinel_<%= @sentinel_name %>.pid logfile <%= @sentinel_log_dir -%>/redis-sentinel_<%= @sentinel_name %>.log -port <%= @sentinel_port -%> +<% if @sentinel_ip then -%> +bind <%= @sentinel_ip %> + +<% end -%> +port <%= @sentinel_port %> <% #rules = scope.lookupvar('redis::sentinel::monitors') - @monitors.sort.each do |name, rule| %> + @monitors.sort.each do |name, rule| -%> # monitor <%= name %> sentinel monitor <%= name -%> <%= rule['master_host'] -%> <%= rule['master_port'] -%> <%= rule['quorum'] %> sentinel down-after-milliseconds <%= name -%> <%= rule['down_after_milliseconds'] %> sentinel parallel-syncs <%= name -%> <%= rule['parallel-syncs'] %> sentinel failover-timeout <%= name -%> <%= rule['failover_timeout'] %> -<%- if rule['auth-pass'] then %>sentinel auth-pass <%= name -%> <%= rule['auth-pass'] %><% end %> -<%- if rule['notification-script'] then %>sentinel notification-script <%= name -%> <%= rule['notification-script'] %><% end %> -<%- if rule['client-reconfig-script'] then %>sentinel client-reconfig-script <%= name -%> <%= rule['client-reconfig-script'] %><% end %> - -<% end %> +<%- if rule['auth-pass'] then %>sentinel auth-pass <%= name -%> <%= rule['auth-pass'] %><% end -%> +<%- if rule['notification-script'] then %>sentinel notification-script <%= name -%> <%= rule['notification-script'] %><% end -%> +<%- if rule['client-reconfig-script'] then %>sentinel client-reconfig-script <%= name -%> <%= rule['client-reconfig-script'] %><% end -%> +<% end -%> From 7949144d9cd7528e445622660f9ada142ae7a05c Mon Sep 17 00:00:00 2001 From: Stanislav Voroniy Date: Tue, 22 Dec 2015 19:49:38 +0100 Subject: [PATCH 04/18] Fix --- manifests/sentinel.pp | 2 -- manifests/server.pp | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/manifests/sentinel.pp b/manifests/sentinel.pp index 708443f..d98e204 100644 --- a/manifests/sentinel.pp +++ b/manifests/sentinel.pp @@ -91,7 +91,6 @@ file { $conf_file: ensure => file, content => template('redis/etc/sentinel.conf.erb'), - replace => $force_rewrite, require => Class['redis::install']; } @@ -144,5 +143,4 @@ ] } } - } diff --git a/manifests/server.pp b/manifests/server.pp index 207ce52..ddd4dcd 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -144,7 +144,6 @@ file { $conf_file: ensure => file, content => template('redis/etc/redis.conf.erb'), - replace => $force_rewrite, require => Class['redis::install']; } @@ -220,6 +219,6 @@ enable => $enabled, hasstatus => true, hasrestart => true, - require => File["${service_file}"] + require => File[$service_file] } } From 5ff7e49596e72d0061a77da2387ca91a1e393ca9 Mon Sep 17 00:00:00 2001 From: Stanislav Voroniy Date: Tue, 29 Dec 2015 12:06:15 +0100 Subject: [PATCH 05/18] Set correct resources dependencies Prevent exec of being run each time --- manifests/sentinel.pp | 6 ++++-- manifests/server.pp | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/manifests/sentinel.pp b/manifests/sentinel.pp index d98e204..c0f8b34 100644 --- a/manifests/sentinel.pp +++ b/manifests/sentinel.pp @@ -100,13 +100,14 @@ exec { "systemd_service_${sentinel_name}_preset": command => "/bin/systemctl preset redis-sentinel_${sentinel_name}.service", notify => Service["redis-sentinel_${sentinel_name}"], + refreshonly => true, } file { $service_file: ensure => file, mode => '0755', content => template('redis/systemd/sentinel.service.erb'), - require => File["/etc/redis-sentinel_${sentinel_name}.conf"], + require => File[$conf_file], notify => Exec["systemd_service_${sentinel_name}_preset"], } } else { @@ -115,7 +116,7 @@ ensure => file, mode => '0755', content => template($sentinel_init_script), - require => File["/etc/redis-sentinel_${sentinel_name}.conf"], + require => File[$conf_file], notify => Service["redis-sentinel_${sentinel_name}"], } } @@ -126,6 +127,7 @@ enable => $enabled, hasstatus => true, hasrestart => true, + subscribe => File[$conf_file], } if ($manage_logrotate == true){ diff --git a/manifests/server.pp b/manifests/server.pp index ddd4dcd..d101385 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -153,6 +153,7 @@ exec { "systemd_service_${redis_name}_preset": command => "/bin/systemctl preset redis-server_${redis_name}.service", notify => Service["redis-server_${redis_name}"], + refreshonly => true, } file { $service_file: @@ -160,7 +161,7 @@ mode => '0755', content => template('redis/systemd/redis.service.erb'), require => [ - File["/etc/redis_${redis_name}.conf"], + File[$conf_file], File["${redis_dir}/redis_${redis_name}"] ], notify => Exec["systemd_service_${redis_name}_preset"], @@ -172,7 +173,7 @@ mode => '0755', content => template($redis_init_script), require => [ - File["/etc/redis_${redis_name}.conf"], + File[$conf_file], File["${redis_dir}/redis_${redis_name}"] ], notify => Service["redis-server_${redis_name}"], @@ -208,7 +209,7 @@ content => template('redis/redis_logrotate.conf.erb'), require => [ Package['logrotate'], - File["/etc/redis_${redis_name}.conf"], + File[$conf_file], ] } } @@ -219,6 +220,7 @@ enable => $enabled, hasstatus => true, hasrestart => true, - require => File[$service_file] + require => File[$service_file], + subscribe => File[$conf_file], } } From ea2175e842bb3a020aa510890ce96d4988ed57f2 Mon Sep 17 00:00:00 2001 From: Stanislav Voroniy Date: Tue, 29 Dec 2015 13:19:28 +0100 Subject: [PATCH 06/18] fix alignment --- manifests/sentinel.pp | 6 +++--- manifests/server.pp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/manifests/sentinel.pp b/manifests/sentinel.pp index c0f8b34..c11d87a 100644 --- a/manifests/sentinel.pp +++ b/manifests/sentinel.pp @@ -98,8 +98,8 @@ if ($::osfamily == 'RedHat' and versioncmp($::operatingsystemmajrelease, '7') >=0) { $service_file = "/usr/lib/systemd/system/redis-sentinel_${sentinel_name}.service" exec { "systemd_service_${sentinel_name}_preset": - command => "/bin/systemctl preset redis-sentinel_${sentinel_name}.service", - notify => Service["redis-sentinel_${sentinel_name}"], + command => "/bin/systemctl preset redis-sentinel_${sentinel_name}.service", + notify => Service["redis-sentinel_${sentinel_name}"], refreshonly => true, } @@ -127,7 +127,7 @@ enable => $enabled, hasstatus => true, hasrestart => true, - subscribe => File[$conf_file], + subscribe => File[$conf_file], } if ($manage_logrotate == true){ diff --git a/manifests/server.pp b/manifests/server.pp index d101385..9886c97 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -151,8 +151,8 @@ if ($::osfamily == 'RedHat' and versioncmp($::operatingsystemmajrelease, '7') >=0) { $service_file = "/usr/lib/systemd/system/redis-server_${redis_name}.service" exec { "systemd_service_${redis_name}_preset": - command => "/bin/systemctl preset redis-server_${redis_name}.service", - notify => Service["redis-server_${redis_name}"], + command => "/bin/systemctl preset redis-server_${redis_name}.service", + notify => Service["redis-server_${redis_name}"], refreshonly => true, } From 0188cc27a8d6dab192643bd1d15991ce26a7d717 Mon Sep 17 00:00:00 2001 From: Daniel Klockenkaemper Date: Tue, 19 Jan 2016 13:53:12 +0100 Subject: [PATCH 07/18] add Gentoo support --- manifests/install.pp | 3 ++ manifests/sentinel.pp | 3 +- manifests/server.pp | 1 + .../etc/init.d/gentoo_redis-sentinel.erb | 34 +++++++++++++++++++ templates/etc/init.d/gentoo_redis-server.erb | 34 +++++++++++++++++++ 5 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 templates/etc/init.d/gentoo_redis-sentinel.erb create mode 100644 templates/etc/init.d/gentoo_redis-server.erb diff --git a/manifests/install.pp b/manifests/install.pp index 58ce8f7..48a7be8 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -48,6 +48,9 @@ } } } + 'Gentoo': { + package { 'dev-db/redis' : ensure => $redis_version, } + } default: { fail('The module does not support this OS.') } diff --git a/manifests/sentinel.pp b/manifests/sentinel.pp index c11d87a..405fbda 100644 --- a/manifests/sentinel.pp +++ b/manifests/sentinel.pp @@ -77,11 +77,12 @@ validate_bool($running) validate_bool($enabled) validate_bool($manage_logrotate) - + $redis_install_dir = $::redis::install::redis_install_dir $sentinel_init_script = $::operatingsystem ? { /(Debian|Ubuntu)/ => 'redis/etc/init.d/debian_redis-sentinel.erb', /(Fedora|RedHat|CentOS|OEL|OracleLinux|Amazon|Scientific)/ => 'redis/etc/init.d/redhat_redis-sentinel.erb', + /(Gentoo)/ => 'redis/etc/init.d/gentoo_redis-sentinel.erb', default => UNDEF, } diff --git a/manifests/server.pp b/manifests/server.pp index 9886c97..97e7251 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -135,6 +135,7 @@ /(Debian|Ubuntu)/ => 'redis/etc/init.d/debian_redis-server.erb', /(Fedora|RedHat|CentOS|OEL|OracleLinux|Amazon|Scientific)/ => 'redis/etc/init.d/redhat_redis-server.erb', /(SLES)/ => 'redis/etc/init.d/sles_redis-server.erb', + /(Gentoo)/ => 'redis/etc/init.d/gentoo_redis-server.erb', default => UNDEF, } $redis_2_6_or_greater = versioncmp($::redis::install::redis_version,'2.6') >= 0 diff --git a/templates/etc/init.d/gentoo_redis-sentinel.erb b/templates/etc/init.d/gentoo_redis-sentinel.erb new file mode 100644 index 0000000..bd69a0a --- /dev/null +++ b/templates/etc/init.d/gentoo_redis-sentinel.erb @@ -0,0 +1,34 @@ +#!/sbin/runscript +# $Id$ + +SENTINEL_DIR="/var/lib/redis" +SENTINEL_CONF="/etc/redis-sentinel_<%= @sentinel_name %>.conf" +SENTINEL_USER="root" +SENTINEL_GROUP="root" +SENTINEL_TIMEOUT=30 +SENTINEL_PID="<%= @sentinel_pid_dir %>/redis-sentinel_<%= @sentinel_name %>.pid" + +command="<%= @redis_install_dir %>/redis-server" +pidfile="${SENTINEL_PID}" + +start_stop_daemon_args="--background --pidfile ${SENTINEL_PID} + --chdir \"${SENTINEL_DIR}\" --user ${SENTINEL_USER} --group ${SENTINEL_GROUP}" +command_args="${SENTINEL_CONF} --sentinel" + +depend() { + use net localmount logger + after keepalived +} + +start_pre() { + checkpath -d -m 0775 -o ${SENTINEL_USER}:${SENTINEL_GROUP} $(dirname ${SENTINEL_PID}) +} + +stop() { + ebegin "Stopping ${SVCNAME}" + start-stop-daemon --stop \ + --exec ${command} \ + --retry ${SENTINEL_TIMEOUT} \ + --pidfile ${SENTINEL_PID} + eend +} \ No newline at end of file diff --git a/templates/etc/init.d/gentoo_redis-server.erb b/templates/etc/init.d/gentoo_redis-server.erb new file mode 100644 index 0000000..58b454b --- /dev/null +++ b/templates/etc/init.d/gentoo_redis-server.erb @@ -0,0 +1,34 @@ +#!/sbin/runscript +# $Id$ + +REDIS_DIR="<%= @redis_dir %>/redis_<%= @redis_name %>" +REDIS_CONF="/etc/redis_<%= @redis_name %>.conf" +REDIS_USER=<%= @redis_user %> +REDIS_GROUP=<%= @redis_group %> +REDIS_TIMEOUT=30 +REDIS_PID="<%= @redis_pid_dir %>/redis_<%= @redis_name %>.pid" + +command="<%= @redis_install_dir %>/redis-server" +pidfile="${REDIS_PID}" + +start_stop_daemon_args="--background --pidfile ${REDIS_PID} + --chdir \"${REDIS_DIR}\" --user ${REDIS_USER} --group ${REDIS_GROUP}" +command_args="${REDIS_CONF}" + +depend() { + use net localmount logger + after keepalived +} + +start_pre() { + checkpath -d -m 0775 -o ${REDIS_USER}:${REDIS_GROUP} $(dirname ${REDIS_PID}) +} + +stop() { + ebegin "Stopping ${SVCNAME}" + start-stop-daemon --stop \ + --exec ${command} \ + --retry ${REDIS_TIMEOUT} \ + --pidfile ${REDIS_PID} + eend +} \ No newline at end of file From 6dea87388a8538a49df51766c2d2f4f385d1ae82 Mon Sep 17 00:00:00 2001 From: Daniel Werdermann Date: Tue, 29 Mar 2016 16:01:56 +0200 Subject: [PATCH 08/18] fix source entry for forge api --- metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.json b/metadata.json index 959a60a..65d26f9 100644 --- a/metadata.json +++ b/metadata.json @@ -31,7 +31,7 @@ ], "name": "dwerder-redis", "version": "1.7.0", - "source": "git clone https://github.com/echocat/puppet-redis.git", + "source": "https://github.com/echocat/puppet-redis.git", "author": "Daniel Werdermann", "license": "MPL-2.0", "summary": "Install and configure redis and sentinel from repo or source", From 3fdbca00d1b6c9bd92d4124b9b14430121a9a8b3 Mon Sep 17 00:00:00 2001 From: Daniel Werdermann Date: Tue, 5 Apr 2016 19:44:12 +0200 Subject: [PATCH 09/18] add download_base to specify download url of source tar.gz --- .travis.yml | 28 +++++++++++++--------------- Gemfile | 30 ++++++++++++++++++++++-------- README.md | 5 +++++ manifests/install.pp | 10 +++++----- manifests/params.pp | 1 + spec/spec_helper.rb | 8 ++++++++ 6 files changed, 54 insertions(+), 28 deletions(-) diff --git a/.travis.yml b/.travis.yml index 87d702c..36a381a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,24 +1,22 @@ --- sudo: false language: ruby +cache: bundler bundler_args: --without system_tests -script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--format documentation'" +before_install: rm Gemfile.lock || true +script: bundle exec rake validate lint spec matrix: fast_finish: true include: - - rvm: 1.9.3 - env: PUPPET_GEM_VERSION="~> 3.4.0" - - rvm: 1.8.7 - env: PUPPET_GEM_VERSION="~> 3.0" - - rvm: 1.9.3 - env: PUPPET_GEM_VERSION="~> 3.0" - - rvm: 1.9.3 - env: PUPPET_GEM_VERSION="~> 3.0" FUTURE_PARSER="yes" - - rvm: 2.1.5 - env: PUPPET_GEM_VERSION="~> 3.0" - - rvm: 2.1.5 - env: PUPPET_GEM_VERSION="~> 3.6.0" - - rvm: 2.1.5 - env: PUPPET_GEM_VERSION="~> 3.0" FUTURE_PARSER="yes" + - rvm: 2.1.6 + env: PUPPET_GEM_VERSION='~> 4.0' COVERAGE=yes STRICT_VARIABLES=yes + - rvm: 2.1.6 + env: PUPPET_GEM_VERSION='https://github.com/puppetlabs/puppet.git#stable + - rvm: 2.1.5 + env: PUPPET_GEM_VERSION='~> 3.0' FUTURE_PARSER=yes + - rvm: 2.1.5 + env: PUPPET_GEM_VERSION='~> 3.0' + - rvm: 1.9.3 + env: PUPPET_GEM_VERSION='~> 3.0' notifications: email: false diff --git a/Gemfile b/Gemfile index 189b7c5..a4d651f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,9 +1,23 @@ -source 'https://rubygems.org' +source ENV['GEM_SOURCE'] || "https://rubygems.org" -puppetversion = ENV.key?('PUPPET_GEM_VERSION') ? "#{ENV['PUPPET_GEM_VERSION']}" : ['>= 3.3'] -facterversion = ENV.key?('FACTER_GEM_VERSION') ? "#{ENV['FACTER_GEM_VERSION']}" : ['>= 1.7'] -gem 'puppet', puppetversion -gem 'puppetlabs_spec_helper', '>= 0.1.0' -gem 'puppet-lint', '>= 0.3.2' -gem 'facter', facterversion -gem 'rspec', '< 3.2.0' +def location_for(place, version = nil) + if place =~ /^((?:git|https?)[:@][^#]*)#(.*)/ + [version, { :git => $1, :branch => $2, :require => false }].compact + elsif place =~ /^file:\/\/(.*)/ + ['>= 0', { :path => File.expand_path($1), :require => false }] + else + [place, version, { :require => false }].compact + end +end + +gem 'puppet', *location_for(ENV['PUPPET_GEM_VERSION'] || '~> 4') +gem 'facter', '>= 2.0' +gem 'puppetlabs_spec_helper', '>= 0.1.0', :require => false +gem 'puppet-lint', '>= 0.3.2', :require => false +gem 'rspec-puppet', '>= 2.3.2', :require => false +gem 'metadata-json-lint', :require => false +gem 'rake', '< 11.0.0' # rubi <1.9 versus rake 11.0.0 workaround + +if File.exists? "#{__FILE__}.local" + eval(File.read("#{__FILE__}.local"), binding) +end diff --git a/README.md b/README.md index d868457..eb33d78 100644 --- a/README.md +++ b/README.md @@ -232,6 +232,11 @@ the redis install package. Therefor, these values must be adjusted too. Redis system group. Default: undef (string) Default 'undef' results to 'root' as redis system group +#####`download_base` + +Url where to find the source tar.gz. +Default value is 'http://download.redis.io/releases' + ####Defined Type: `redis::server` Used to configure redis instances. You can setup multiple redis servers on the diff --git a/manifests/install.pp b/manifests/install.pp index 48a7be8..039a088 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -20,6 +20,9 @@ # [*redis_group*] # The redis system group. Default value is 'undef', which results to 'root' as system group. # +# [*download_base*] +# Url where to find the source tar.gz. Default value is 'http://download.redis.io/releases' +# class redis::install ( $redis_version = $::redis::params::redis_version, $redis_build_dir = $::redis::params::redis_build_dir, @@ -28,6 +31,7 @@ $download_tool = $::redis::params::download_tool, $redis_user = $::redis::params::redis_user, $redis_group = $::redis::params::redis_group, + $download_base = $::redis::params::download_base, ) inherits redis { if ( $redis_package == true ) { case $::operatingsystem { @@ -90,11 +94,7 @@ ensure => directory, } - if $redis_version == $::redis::params::redis_version { - $redis_download_url = 'http://download.redis.io/redis-stable.tar.gz' - } else { - $redis_download_url = "http://download.redis.io/releases/redis-${redis_version}.tar.gz" - } + $redis_download_url = "${download_base}/redis-${redis_version}.tar.gz" exec { "Download and untar redis ${redis_version}": require => File[$redis_build_dir], diff --git a/manifests/params.pp b/manifests/params.pp index 522709c..1d4e710 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -8,4 +8,5 @@ $download_tool = 'curl -s -L' $redis_user = undef $redis_group = undef + $download_base = 'http://download.redis.io/releases' } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2c6f566..ba14529 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1 +1,9 @@ +if ENV['COVERAGE'] == 'yes' + RSpec.configure do |c| + c.after(:suite) do + RSpec::Puppet::Coverage.report! + end + end +end + require 'puppetlabs_spec_helper/module_spec_helper' From 0ea559fe0fb6b8a0cf3f7a461739118343fbbdc2 Mon Sep 17 00:00:00 2001 From: Daniel Werdermann Date: Tue, 5 Apr 2016 19:49:20 +0200 Subject: [PATCH 10/18] add some badges --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index eb33d78..8e1b7b2 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,9 @@ This module installs and makes basic configs for multiple redis instances on the same node. It installs redis via REPO or from source. (http://redis.io/) It also can configure the monitoring server Sentinel. -Github Master: [![Build Status](https://secure.travis-ci.org/echocat/puppet-redis.png?branch=master)](https://travis-ci.org/echocat/puppet-redis) - +[![Puppet Forge](http://img.shields.io/puppetforge/v/dwerder/redis.svg)](https://forge.puppetlabs.com/dwerder/redis) +[![Build Status](https://secure.travis-ci.org/echocat/puppet-redis.png?branch=master)](https://travis-ci.org/echocat/puppet-redis) +[![Puppet Forge Downloads](http://img.shields.io/puppetforge/dt/dwerder/redis.svg)](https://forge.puppetlabs.com/dwerder/redis) ##Setup From c3692318247e9be2b239016470eb922c38f18e89 Mon Sep 17 00:00:00 2001 From: Daniel Werdermann Date: Tue, 5 Apr 2016 19:49:46 +0200 Subject: [PATCH 11/18] fix a test for strict_variables --- spec/classes/install_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/classes/install_spec.rb b/spec/classes/install_spec.rb index ae2be5f..6c5819d 100644 --- a/spec/classes/install_spec.rb +++ b/spec/classes/install_spec.rb @@ -3,7 +3,7 @@ describe 'redis::install' do context 'Unsupported OS' do - let(:facts) {{ :osfamily => 'unsupported' }} + let(:facts) {{ :osfamily => 'unsupported', :operatingsystem => 'UnknownOS' }} it { expect { should contain_class('redis::install')}.to raise_error(Puppet::Error, /The module does not support this OS/ )} end From 028794ab4b80f4c1468f78476a37ae089961c7ba Mon Sep 17 00:00:00 2001 From: Daniel Werdermann Date: Tue, 5 Apr 2016 20:10:06 +0200 Subject: [PATCH 12/18] prepare release 1.8.0 --- CHANGELOG.md | 14 ++++++++++++++ README.md | 11 ++++++++++- metadata.json | 12 +++++------- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c5404b..c1528a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +## 2016-04-05 - 1.8.0 (Feature/Bugfix release) + +#### Features: + +- (e37283e) Add the possibility to exclude logrotate +- (316f492) RedHat 7: add systemd support +- (316f492) Sentinel: add parameter `sentinel_ip` for binding address +- (3fdbca0) Server::install: add parameter `download_base` at install class to specify download url of source tar.gz +- (e47fc28) Gentoo: add support for Gentoo + +#### Bugfixes: + +- (6dea873) fix source entry for forge api in metadata.json + ## 2015-12-02 - 1.7.0 (Feature/Bugfix release) #### Features: diff --git a/README.md b/README.md index 8e1b7b2..418c846 100644 --- a/README.md +++ b/README.md @@ -416,9 +416,13 @@ Name of Redis instance. Default: call name of the function. The name is used to create the init script(s), which follows the pattern `redis-sentinel_${sentinel_name}` +#####`sentinel_ip` + +Listen IP of sentinel. Default: 6379 + #####`sentinel_port` -Listen port of Redis. Default: 6379 +Listen port of sentinel. Default: 6379 #####`sentinel_log_dir` @@ -430,6 +434,11 @@ Path for log. Full log path is `sentinel_log_dir`/sentinel_`sentinel_name`.log. Default is '/var/run' (string). Path for pid file. Full pid file path is `sentinel_pid_dir`/sentinel_`sentinel_name`.pid. +#####`sentinel_run_dir` + +Default: `/var/run/redis` (string) +Since sentinels automatically rewrite their config since version 2.8 the puppet managed config will be copied +to this directory and than sentinel will start with this copy. #####`monitors` diff --git a/metadata.json b/metadata.json index 65d26f9..66bb3f9 100644 --- a/metadata.json +++ b/metadata.json @@ -22,15 +22,16 @@ "requirements": [ { "name": "pe", - "version_requirement": "3.x" + "version_requirement": ">= 3.0.0 < 2015.4.0" }, { "name": "puppet", - "version_requirement": ">=2.7.20 <5.0.0" + "version_requirement": ">= 3.0.0 < 5.0.0" } ], + "description": "Redis module", "name": "dwerder-redis", - "version": "1.7.0", + "version": "1.8.0", "source": "https://github.com/echocat/puppet-redis.git", "author": "Daniel Werdermann", "license": "MPL-2.0", @@ -38,9 +39,6 @@ "project_page": "https://github.com/echocat/puppet-redis", "issues_url": "https://github.com/echocat/puppet-redis/issues", "dependencies": [ - { - "name": "puppetlabs/stdlib", - "version_requirement": ">= 4.2.0" - } + {"name":"puppetlabs/stdlib","version_requirement":">= 4.6.0 < 5.0.0"} ] } From fa7de2b293d217f4153f71f33d4da52b5191efa1 Mon Sep 17 00:00:00 2001 From: Daniel Werdermann Date: Tue, 5 Apr 2016 20:20:55 +0200 Subject: [PATCH 13/18] fix puppet 4 tests --- .rspec | 2 ++ manifests/install.pp | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 .rspec diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..16f9cdb --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--color +--format documentation diff --git a/manifests/install.pp b/manifests/install.pp index 039a088..5a68a45 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -83,7 +83,7 @@ exec { "Make dir ${redis_build_dir}": command => "mkdir -p ${redis_build_dir}", creates => $redis_build_dir, - path => $::path, + path => ['/usr/bin', '/usr/sbin', '/bin', '/sbin'], cwd => '/', user => 'root', group => 'root', @@ -101,7 +101,7 @@ before => Anchor['redis::prepare_build'], command => "${download_tool} ${redis_download_url} | tar xz", creates => "${redis_build_dir}/redis-${::redis::install::redis_version}", - path => $::path, + path => ['/usr/bin', '/usr/sbin', '/bin', '/sbin'], cwd => $redis_build_dir, user => 'root', group => 'root', @@ -116,7 +116,7 @@ command => 'make', creates => "${redis_build_dir}/redis-${redis_version}/src/redis-server", cwd => "${redis_build_dir}/redis-${::redis::install::redis_version}/", - path => $::path, + path => ['/usr/bin', '/usr/sbin', '/bin', '/sbin'], user => 'root', group => 'root', } From 02cdbd2707da5d0ee2aa8b7b3077904ad42aebe9 Mon Sep 17 00:00:00 2001 From: Daniel Werdermann Date: Fri, 8 Apr 2016 07:39:17 +0200 Subject: [PATCH 14/18] add more unit tests --- .gitignore | 52 ++++++++++++++++++++++++++++++++++++ Gemfile | 3 ++- manifests/install.pp | 2 +- spec/classes/install_spec.rb | 11 ++++++++ spec/spec_helper.rb | 2 ++ 5 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..459b347 --- /dev/null +++ b/.gitignore @@ -0,0 +1,52 @@ +*.gem +*.rbc +/.config +/coverage/ +/InstalledFiles +/pkg/ +/spec/reports/ +/test/tmp/ +/test/version_tmp/ +/tmp/ + +# Beaker/Vagrant +.vagrant/ + +# Puppet Files +pkg +spec/fixtures +.rspec_system +.vagrant/ + +## Specific to RubyMotion: +.dat* +.repl_history +build/ + +## Documentation cache and generated files: +/.yardoc/ +/_yardoc/ +/doc/ +/rdoc/ + +## Environment normalisation: +/.bundle/ +/lib/bundler/man/ + +Gemfile.lock +.ruby-version +.ruby-gemset + +# unless supporting rvm < 1.11.0 or doing something fancy, ignore this: +.rvmrc + +# idea +./idea +.idea/ + +# geppetto/eclipse +.project + +# others +*swp +.DS_Store diff --git a/Gemfile b/Gemfile index a4d651f..fef97e4 100644 --- a/Gemfile +++ b/Gemfile @@ -11,10 +11,11 @@ def location_for(place, version = nil) end gem 'puppet', *location_for(ENV['PUPPET_GEM_VERSION'] || '~> 4') -gem 'facter', '>= 2.0' +gem 'facter', *location_for(ENV['FACTER_GEM_VERSION'] || '~> 2') gem 'puppetlabs_spec_helper', '>= 0.1.0', :require => false gem 'puppet-lint', '>= 0.3.2', :require => false gem 'rspec-puppet', '>= 2.3.2', :require => false +gem 'rspec-puppet-facts', :require => false gem 'metadata-json-lint', :require => false gem 'rake', '< 11.0.0' # rubi <1.9 versus rake 11.0.0 workaround diff --git a/manifests/install.pp b/manifests/install.pp index 5a68a45..451a2f3 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -67,7 +67,7 @@ ensure_packages('build-essential') Package['build-essential'] -> Anchor['redis::prepare_build'] } - 'Fedora', 'RedHat', 'CentOS', 'OEL', 'OracleLinux', 'Amazon', 'Scientific': { + 'Fedora', 'RedHat', 'CentOS', 'OEL', 'OracleLinux', 'Amazon', 'Scientific', 'Sles': { ensure_packages('make') Package['make'] -> Anchor['redis::prepare_build'] ensure_packages('gcc') diff --git a/spec/classes/install_spec.rb b/spec/classes/install_spec.rb index 6c5819d..f309b74 100644 --- a/spec/classes/install_spec.rb +++ b/spec/classes/install_spec.rb @@ -27,4 +27,15 @@ end end + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts + end + + it { is_expected.to compile.with_all_deps } + + end + end + end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ba14529..8b1578f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,3 +7,5 @@ end require 'puppetlabs_spec_helper/module_spec_helper' +require 'rspec-puppet-facts' +include RspecPuppetFacts \ No newline at end of file From e487127fa530683623b2ca00c6813e5c14d08608 Mon Sep 17 00:00:00 2001 From: Daniel Werdermann Date: Fri, 8 Apr 2016 08:08:22 +0200 Subject: [PATCH 15/18] fix permissions of systemd script --- manifests/server.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/server.pp b/manifests/server.pp index 97e7251..aee99d6 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -159,7 +159,7 @@ file { $service_file: ensure => file, - mode => '0755', + mode => '0644', content => template('redis/systemd/redis.service.erb'), require => [ File[$conf_file], From 318d2cb83c11b85816ceba941c4d4476f6b68bd3 Mon Sep 17 00:00:00 2001 From: Daniel Werdermann Date: Fri, 8 Apr 2016 09:38:03 +0200 Subject: [PATCH 16/18] systemd scripts use wrong variables #73 --- manifests/sentinel.pp | 2 +- manifests/server.pp | 7 ++++--- templates/systemd/redis.service.erb | 9 +++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/manifests/sentinel.pp b/manifests/sentinel.pp index 405fbda..58a26e1 100644 --- a/manifests/sentinel.pp +++ b/manifests/sentinel.pp @@ -83,7 +83,7 @@ /(Debian|Ubuntu)/ => 'redis/etc/init.d/debian_redis-sentinel.erb', /(Fedora|RedHat|CentOS|OEL|OracleLinux|Amazon|Scientific)/ => 'redis/etc/init.d/redhat_redis-sentinel.erb', /(Gentoo)/ => 'redis/etc/init.d/gentoo_redis-sentinel.erb', - default => UNDEF, + default => undef, } # redis conf file diff --git a/manifests/server.pp b/manifests/server.pp index aee99d6..07dbb9a 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -83,7 +83,7 @@ # Since redis automatically rewrite their config since version 2.8 what conflicts with puppet # the config files created by puppet will be copied to this directory and redis will be started from # this copy. -# +# # [*manage_logrotate*] # Configure logrotate rules for redis server. Default: true define redis::server ( @@ -136,12 +136,13 @@ /(Fedora|RedHat|CentOS|OEL|OracleLinux|Amazon|Scientific)/ => 'redis/etc/init.d/redhat_redis-server.erb', /(SLES)/ => 'redis/etc/init.d/sles_redis-server.erb', /(Gentoo)/ => 'redis/etc/init.d/gentoo_redis-server.erb', - default => UNDEF, + default => undef, } $redis_2_6_or_greater = versioncmp($::redis::install::redis_version,'2.6') >= 0 # redis conf file - $conf_file = "/etc/redis_${redis_name}.conf" + $conf_file_name = "redis_${redis_name}.conf" + $conf_file = "/etc/${conf_file_name}" file { $conf_file: ensure => file, content => template('redis/etc/redis.conf.erb'), diff --git a/templates/systemd/redis.service.erb b/templates/systemd/redis.service.erb index 80198cb..caa55b6 100644 --- a/templates/systemd/redis.service.erb +++ b/templates/systemd/redis.service.erb @@ -1,13 +1,14 @@ [Unit] -Description=Redis persistent key-value database server +Description=Redis redis_<%= @redis_name %> database server After=network.target [Service] +ExecStartPre=/bin/mkdir -p <%= @redis_run_dir %> ExecStartPre=/bin/cp -u <%= @conf_file %> <%= @redis_run_dir %>/<%= @conf_file_name %> ExecStart=/usr/bin/redis-server <%= @redis_run_dir %>/<%= @conf_file_name %> --daemonize no -ExecStop=/usr/bin/redis-shutdown redis_<%= @redis_name %> -User=redis -Group=redis +ExecStop=/usr/bin/redis-cli -p <%= @redis_port %> shutdown +User=<%= @redis_user or 'root' %> +Group=<%= @redis_group or 'root' %> [Install] WantedBy=multi-user.target From 2596795f47d9596a0f40b61f13521cbcacebf117 Mon Sep 17 00:00:00 2001 From: Daniel Werdermann Date: Fri, 8 Apr 2016 09:49:06 +0200 Subject: [PATCH 17/18] fix systemd sentinel scripts --- manifests/sentinel.pp | 2 ++ templates/systemd/sentinel.service.erb | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/manifests/sentinel.pp b/manifests/sentinel.pp index 58a26e1..2bf1d96 100644 --- a/manifests/sentinel.pp +++ b/manifests/sentinel.pp @@ -68,6 +68,8 @@ $enabled = true, $manage_logrotate = true, ) { + $sentinel_user = $::redis::install::redis_user + $sentinel_group = $::redis::install::redis_group # validate parameters validate_absolute_path($sentinel_log_dir) diff --git a/templates/systemd/sentinel.service.erb b/templates/systemd/sentinel.service.erb index 049a9f8..a73ac84 100644 --- a/templates/systemd/sentinel.service.erb +++ b/templates/systemd/sentinel.service.erb @@ -1,13 +1,14 @@ [Unit] -Description=Redis Sentinel +Description=Redis Sentinel <%= sentinel_name %> After=network.target [Service] +ExecStartPre=/bin/mkdir -p <%= @sentinel_run_dir %> ExecStartPre=/bin/cp -u <%= @conf_file %> <%= @sentinel_run_dir %>/<%= @conf_file_name %> ExecStart=/usr/bin/redis-sentinel <%= @sentinel_run_dir %>/<%= @conf_file_name %> --daemonize no -ExecStop=/usr/bin/redis-shutdown redis-sentinel_<%= @sentinel_name %> -User=redis -Group=redis +ExecStop=/usr/bin/redis-cli -p <%= @sentinel_port %> shutdown +User=<%= @sentinel_user or 'root' %> +Group=<%= @sentinel_group or 'root' %> [Install] WantedBy=multi-user.target From d01c1f4ac8e65912219b7b12d638fe8bb78c27eb Mon Sep 17 00:00:00 2001 From: Daniel Werdermann Date: Fri, 8 Apr 2016 09:56:32 +0200 Subject: [PATCH 18/18] prepare release 1.8.1 --- CHANGELOG.md | 6 ++++++ metadata.json | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1528a5..097c004 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 2016-04-08 - 1.8.1 (Bugfix release) + +#### Bugfixes: + +- (318d2cb) RedHat 7: fix systemd scripts for Server and Sentinel + ## 2016-04-05 - 1.8.0 (Feature/Bugfix release) #### Features: diff --git a/metadata.json b/metadata.json index 66bb3f9..e72e0d6 100644 --- a/metadata.json +++ b/metadata.json @@ -29,9 +29,8 @@ "version_requirement": ">= 3.0.0 < 5.0.0" } ], - "description": "Redis module", "name": "dwerder-redis", - "version": "1.8.0", + "version": "1.8.1", "source": "https://github.com/echocat/puppet-redis.git", "author": "Daniel Werdermann", "license": "MPL-2.0",