From 14df3605b2d844de94abf769d4ddfa3216045f4b Mon Sep 17 00:00:00 2001 From: Yanis Guenane Date: Mon, 9 Feb 2015 07:33:16 -0500 Subject: [PATCH] Add support for notification-script in sentinel This commit add support for the configuration of a notification-script in a redis-sentinel. --- manifests/params.pp | 103 ++++++++++++++-------------- manifests/sentinel.pp | 49 +++++++------ spec/classes/redis_sentinel_spec.rb | 10 +-- templates/redis-sentinel.conf.erb | 3 + 4 files changed, 88 insertions(+), 77 deletions(-) diff --git a/manifests/params.pp b/manifests/params.pp index 89eba9c71..c082c4358 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -7,57 +7,58 @@ $manage_repo = false # redis.conf.erb - $activerehashing = true - $appendfsync = 'everysec' - $appendonly = false - $auto_aof_rewrite_min_size = '64min' - $auto_aof_rewrite_percentage = 100 - $bind = '127.0.0.1' - $conf_template = 'redis/redis.conf.erb' - $databases = 16 - $dbfilename = 'dump.rdb' - $extra_config_file = undef - $hash_max_ziplist_entries = 512 - $hash_max_ziplist_value = 64 - $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' - $maxclients = 10000 - $maxmemory = undef - $maxmemory_policy = undef - $maxmemory_samples = undef - $no_appendfsync_on_rewrite = false - $notify_service = true - $pid_file = '/var/run/redis/redis-server.pid' - $port = 6379 - $rdbcompression = true - $requirepass = 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' - $set_max_intset_entries = 512 - $slowlog_log_slower_than = 10000 - $slowlog_max_len = 1024 - $syslog_enabled = undef - $syslog_facility = undef - $timeout = 0 - $ulimit = 65536 - $workdir = '/var/lib/redis/' - $zset_max_ziplist_entries = 128 - $zset_max_ziplist_value = 64 + $activerehashing = true + $appendfsync = 'everysec' + $appendonly = false + $auto_aof_rewrite_min_size = '64min' + $auto_aof_rewrite_percentage = 100 + $bind = '127.0.0.1' + $conf_template = 'redis/redis.conf.erb' + $databases = 16 + $dbfilename = 'dump.rdb' + $extra_config_file = undef + $hash_max_ziplist_entries = 512 + $hash_max_ziplist_value = 64 + $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' + $maxclients = 10000 + $maxmemory = undef + $maxmemory_policy = undef + $maxmemory_samples = undef + $no_appendfsync_on_rewrite = false + $notify_service = true + $pid_file = '/var/run/redis/redis-server.pid' + $port = 6379 + $rdbcompression = true + $requirepass = 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 + $set_max_intset_entries = 512 + $slowlog_log_slower_than = 10000 + $slowlog_max_len = 1024 + $syslog_enabled = undef + $syslog_facility = undef + $timeout = 0 + $ulimit = 65536 + $workdir = '/var/lib/redis/' + $zset_max_ziplist_entries = 128 + $zset_max_ziplist_value = 64 # redis.conf.erb - replication $masterauth = undef diff --git a/manifests/sentinel.pp b/manifests/sentinel.pp index 18d3c65fa..77b4b8932 100644 --- a/manifests/sentinel.pp +++ b/manifests/sentinel.pp @@ -121,6 +121,10 @@ # # Default: /tmp # +# [*notification_script*] +# Path to the notification script +# +# Default: undef # == Actions: # - Install and configure Redis Sentinel # @@ -134,28 +138,29 @@ # } # class redis::sentinel ( - $config_file = $::redis::params::sentinel_config_file, - $config_file_orig = $::redis::params::sentinel_config_file_orig, - $config_file_mode = $::redis::params::sentinel_config_file_mode, - $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, - $service_name = $::redis::params::sentinel_service_name, - $service_user = $::redis::params::service_user, - $working_dir = $::redis::params::sentinel_working_dir, + $config_file = $::redis::params::sentinel_config_file, + $config_file_orig = $::redis::params::sentinel_config_file_orig, + $config_file_mode = $::redis::params::sentinel_config_file_mode, + $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, + $service_name = $::redis::params::sentinel_service_name, + $service_user = $::redis::params::service_user, + $working_dir = $::redis::params::sentinel_working_dir, + $notification_script = $::redis::params::sentinel_notification_script, ) inherits redis::params { diff --git a/spec/classes/redis_sentinel_spec.rb b/spec/classes/redis_sentinel_spec.rb index 0b81be4e3..639cefd75 100644 --- a/spec/classes/redis_sentinel_spec.rb +++ b/spec/classes/redis_sentinel_spec.rb @@ -24,6 +24,7 @@ sentinel down-after-milliseconds cow 6000 sentinel parallel-syncs cow 1 sentinel failover-timeout cow 28000 +sentinel notification-script cow bar.sh logfile /tmp/barn-sentinel.log EOF @@ -62,10 +63,11 @@ describe 'with custom parameters' do let (:params) { { - :master_name => 'cow', - :down_after => 6000, - :log_file => '/tmp/barn-sentinel.log', - :failover_timeout => 28000 + :master_name => 'cow', + :down_after => 6000, + :log_file => '/tmp/barn-sentinel.log', + :failover_timeout => 28000, + :notification_script => 'bar.sh' } } diff --git a/templates/redis-sentinel.conf.erb b/templates/redis-sentinel.conf.erb index 06a3e9f57..c93176005 100644 --- a/templates/redis-sentinel.conf.erb +++ b/templates/redis-sentinel.conf.erb @@ -7,5 +7,8 @@ sentinel monitor <%= @master_name %> <%= @redis_host %> <%= @redis_port %> <%= @ sentinel down-after-milliseconds <%= @master_name %> <%= @down_after %> sentinel parallel-syncs <%= @master_name %> <%= @parallel_sync %> sentinel failover-timeout <%= @master_name %> <%= @failover_timeout %> +<% if @notification_script -%> +sentinel notification-script <%= @master_name %> <%= @notification_script %> +<% end -%> logfile <%= @log_file %>