From 19345cb9ffe54e7e5067813daeda1a622bfa73c0 Mon Sep 17 00:00:00 2001 From: Chris Dent Date: Sat, 17 Jan 2015 12:42:55 +0000 Subject: [PATCH] Ensure init script is linked into rc.d Also make sure that a daemonized sentinel properly produces a pid file so the init script can stop the sentinel. --- manifests/params.pp | 1 + manifests/sentinel.pp | 10 ++++++++++ spec/classes/redis_sentinel_spec.rb | 4 ++++ templates/redis-sentinel.conf.erb | 3 ++- templates/redis-sentinel.init.erb | 4 ++-- 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/manifests/params.pp b/manifests/params.pp index 32402d8f5..d4b4c2b8c 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -47,6 +47,7 @@ $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 diff --git a/manifests/sentinel.pp b/manifests/sentinel.pp index 962fde2a3..18d3c65fa 100644 --- a/manifests/sentinel.pp +++ b/manifests/sentinel.pp @@ -84,6 +84,11 @@ # # 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. @@ -144,6 +149,7 @@ $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, @@ -185,6 +191,10 @@ content => template($init_template), require => Package[$package_name]; } + exec { + "/usr/sbin/update-rc.d redis-sentinel defaults": + require => File[$init_script]; + } } service { $service_name: diff --git a/spec/classes/redis_sentinel_spec.rb b/spec/classes/redis_sentinel_spec.rb index 96c69b978..0b81be4e3 100644 --- a/spec/classes/redis_sentinel_spec.rb +++ b/spec/classes/redis_sentinel_spec.rb @@ -4,6 +4,8 @@ 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 sentinel parallel-syncs mymaster 1 @@ -16,6 +18,8 @@ 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 sentinel parallel-syncs cow 1 diff --git a/templates/redis-sentinel.conf.erb b/templates/redis-sentinel.conf.erb index 2e5119b06..06a3e9f57 100644 --- a/templates/redis-sentinel.conf.erb +++ b/templates/redis-sentinel.conf.erb @@ -1,6 +1,7 @@ port <%= @sentinel_port %> dir <%= @working_dir %> -<% if @daemonize -%>daemonize yes<% else -%>daemonize no<% end -%> +<% 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 %> diff --git a/templates/redis-sentinel.init.erb b/templates/redis-sentinel.init.erb index 6f4fba456..a4e1b3974 100644 --- a/templates/redis-sentinel.init.erb +++ b/templates/redis-sentinel.init.erb @@ -7,8 +7,8 @@ # Should-Stop: $local_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 -# Short-Description: redis-server - Persistent key-value db -# Description: redis-server - Persistent key-value db +# Short-Description: redis-sentinel - Monitor redis-server +# Description: redis-sentinel - Monitor redis-server ### END INIT INFO