Skip to content

Commit

Permalink
Ensure the sentinel service is running
Browse files Browse the repository at this point in the history
Note the commented out lines in the sentinel.pp for the config_dir
and log_file resources. If these are there we get duplicate
resources. A few options to deal with this:

* Not worry about it: the dpkg and rpm packages make sure they are
  there anyway, we're really just insuring existence of default
  things. This only becomes a problem if someone wants to write
  log files and config files in unusual places, but if that's the
  case they are probably managing that anyway.

* Extract the conflicting resources to their own classes which both
  redis and redis-sentinel use. This gets complicated in the face of
  the way redis::params is used as a super class and other
  inclusions are done.

* Require stdlib and use ensure_resource (untested, but based on
  reading the docs it seems like it ought to work).

I'm inclined to the former.

Still missing and to do:

* confirm system restart on config file changes
* flesh out the tests
* implement monitoring of multiple masters (add loop to the conf
  file template and change data structure)
  • Loading branch information
Chris Dent committed Dec 11, 2014
1 parent 6dd0fdc commit 8206296
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
$sentinel_parallel_sync = 1
$sentinel_port = 26379
$sentinel_quorum = 2
$sentinel_service_name = 'redis-sentinel'
$sentinel_working_dir = '/tmp'
$set_max_intset_entries = 512
$slowlog_log_slower_than = 10000
Expand Down
31 changes: 20 additions & 11 deletions manifests/sentinel.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,49 @@
$redis_host = $::redis::params::bind,
$redis_port = $::redis::params::port,
$parallel_sync = $::redis::params::sentinel_parallel_sync,
$quorum = $::redis::parms::sentinel_quorum,
$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,
) inherits redis::params {

file {
$config_dir:
ensure => directory,
mode => $config_dir_mode;
# $config_dir:
# ensure => directory,
# mode => $config_dir_mode;

$config_file_orig:
ensure => present,
content => template($conf_template),
require => File[$config_dir];
content => template($conf_template);
# require => File[$config_dir];

$config_file:
owner => $service_user,
group => $service_group,
mode => $config_file_mode;

$log_dir:
ensure => directory,
group => $service_group,
mode => $config_dir_mode,
owner => $service_user;
# $log_dir:
# ensure => directory,
# group => $service_group,
# mode => $config_dir_mode,
# owner => $service_user;
}

exec {
"cp $config_file_orig $config_file":
path => "/usr/bin:/bin",
subscribe => File[$config_file_orig],
notify => Service[$service_name],
refreshonly => true;
}

service { $service_name:
ensure => $::redis::params::service_ensure,
enable => $::redis::params::service_enable,
hasrestart => $::redis::params::service_hasrestart,
hasstatus => $::redis::params::service_hasstatus,
}

}
17 changes: 17 additions & 0 deletions spec/classes/redis_sentinel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@
)
}

it { should contain_service('redis-sentinel').with(
'ensure' => 'running',
'enable' => 'true',
'hasrestart' => 'true',
'hasstatus' => 'false'
)
}

end

describe 'with parameter: down_after' do
let (:params) { { :down_after => 6000 } }

it { should contain_file('/etc/redis/redis-sentinel.conf.puppet').with(
'content' => /sentinel down-after-milliseconds mymaster 6000/
)
}
end

end

0 comments on commit 8206296

Please sign in to comment.