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/.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/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/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 4f528f4..418c846 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 @@ -232,6 +233,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 @@ -366,6 +372,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` @@ -406,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` @@ -420,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` @@ -459,6 +478,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/install.pp b/manifests/install.pp index 58ce8f7..5a68a45 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 { @@ -48,6 +52,9 @@ } } } + 'Gentoo': { + package { 'dev-db/redis' : ensure => $redis_version, } + } default: { fail('The module does not support this OS.') } @@ -76,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', @@ -87,18 +94,14 @@ 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], 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', @@ -113,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', } 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/manifests/sentinel.pp b/manifests/sentinel.pp index 043bc54..405fbda 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*] @@ -32,21 +34,22 @@ # 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` -# -# 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. +# Default: `/var/run/redis` # +# 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 ( $ensure = 'present', $sentinel_name = $name, + $sentinel_ip = undef, $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', @@ -63,35 +66,61 @@ }, $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 ? { /(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, } # 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}"], + refreshonly => true, + } + + file { $service_file: + ensure => file, + mode => '0755', + content => template('redis/systemd/sentinel.service.erb'), + require => File[$conf_file], + 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[$conf_file], + notify => Service["redis-sentinel_${sentinel_name}"], + } + } # manage sentinel service service { "redis-sentinel_${sentinel_name}": @@ -99,20 +128,22 @@ enable => $enabled, hasstatus => true, hasrestart => true, + subscribe => File[$conf_file], } - # 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..97e7251 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -76,15 +76,16 @@ # [*hash_max_ziplist_value*] # Threshold for ziplist value. Default: 64 # -# [*force_rewrite*] +# [*redis_run_dir*] # -# Boolean. Default: `false` -# -# 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. +# Default: `/var/run/redis` # +# 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 ( $redis_name = $name, $redis_memory = '100mb', @@ -101,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, @@ -123,7 +125,7 @@ $save = [], $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 @@ -133,29 +135,50 @@ /(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 # 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, require => Class['redis::install']; } # 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}"], + refreshonly => true, + } + + file { $service_file: + ensure => file, + mode => '0755', + content => template('redis/systemd/redis.service.erb'), + require => [ + File[$conf_file], + 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[$conf_file], + File["${redis_dir}/redis_${redis_name}"] + ], + notify => Service["redis-server_${redis_name}"], + } } # path for persistent data @@ -176,18 +199,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[$conf_file], + ] + } } # manage redis service @@ -196,6 +221,7 @@ enable => $enabled, hasstatus => true, hasrestart => true, - require => File["/etc/init.d/redis-server_${redis_name}"] + require => File[$service_file], + subscribe => File[$conf_file], } } diff --git a/metadata.json b/metadata.json index 959a60a..66bb3f9 100644 --- a/metadata.json +++ b/metadata.json @@ -22,25 +22,23 @@ "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", - "source": "git clone https://github.com/echocat/puppet-redis.git", + "version": "1.8.0", + "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", "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"} ] } 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 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' 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/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 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..a2c9f34 100644 --- a/templates/etc/sentinel.conf.erb +++ b/templates/etc/sentinel.conf.erb @@ -2,24 +2,31 @@ # !!! 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 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 -%> 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 +