Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instance service improvements #222

Merged
merged 4 commits into from
Aug 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ matrix:
env: PUPPET_GEM_VERSION="~> 3.0" FUTURE_PARSER="yes" ORDERING="random"
- sudo: required
dist: trusty
rvm: 2.1.9
rvm: 2.2.2
env: PUPPET_GEM_VERSION="~> 3.0" STRICT_VARIABLES="yes" ORDERING="random"
- sudo: required
dist: trusty
Expand Down
40 changes: 30 additions & 10 deletions manifests/instance.pp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
# @param [String] latency_monitor_threshold Latency monitoring threshold in milliseconds
# @param [String] list_max_ziplist_entries Set max ziplist entries for lists.
# @param [String] list_max_ziplist_value Set max ziplist values for lists.
# @param [String] log_dir Specify directory where to write log entries.
# @param [String] log_dir_mode Adjust mode for directory containing log files.
# @param [String] log_file Specify file where to write log entries.
# @param [String] log_level Specify the server verbosity level.
# @param [String] masterauth If the master is password protected (using the "requirepass" configuration
Expand All @@ -63,6 +65,7 @@
# @param [String] save_db_to_disk_interval save the dataset every N seconds if there are at least M changes in the dataset
# @param [String] service_enable Enable/disable daemon at boot.
# @param [String] service_ensure Specify if the server should be running.
# @param [String] service_group Specify which group to run as.
# @param [String] service_hasrestart Does the init script support restart?
# @param [String] service_hasstatus Does the init script support status?
# @param [String] service_user Specify which user to run as.
Expand Down Expand Up @@ -110,6 +113,7 @@
# @param [String] workdir The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
# Default: /var/lib/redis/
# @param [String] workdir_mode Adjust mode for data directory.
# @param [String] zset_max_ziplist_entries Set max entries for sorted sets.
# @param [String] zset_max_ziplist_value Set max values for sorted sets.
# @param [String] cluster_enabled Enables redis 3.0 cluster functionality
Expand Down Expand Up @@ -148,6 +152,8 @@
$latency_monitor_threshold = $::redis::latency_monitor_threshold,
$list_max_ziplist_entries = $::redis::list_max_ziplist_entries,
$list_max_ziplist_value = $::redis::list_max_ziplist_value,
$log_dir = $::redis::log_dir,
$log_dir_mode = $::redis::log_dir_mode,
$log_level = $::redis::log_level,
$minimum_version = $::redis::minimum_version,
$masterauth = $::redis::masterauth,
Expand Down Expand Up @@ -200,7 +206,7 @@
$service_hasstatus = $::redis::service_hasstatus,
# Defaults for redis::instance
$manage_service_file = true,
$log_file = "/var/log/redis/redis-server-${name}.log",
$log_file = undef,
$pid_file = "/var/run/redis/redis-server-${name}.pid",
$unixsocket = "/var/run/redis/redis-server-${name}.sock",
$workdir = "${::redis::workdir}/redis-server-${name}",
Expand All @@ -210,9 +216,23 @@
$redis_file_name_orig = $config_file_orig
$redis_file_name = $config_file
} else {
$redis_config_extension = ".${title}"
$redis_file_name_orig = "${config_file_orig}${redis_config_extension}"
$redis_file_name = "${config_file}${redis_config_extension}"
$redis_server_name = "redis-server-${name}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we wanted to be really pedandtic we could change it to be redis on RedHat and redis-server on Debian to follow convention, but I don't care that much

$redis_file_name_orig = sprintf('%s/%s.%s', dirname($config_file_orig), $redis_server_name, 'conf.puppet')
$redis_file_name = sprintf('%s/%s.%s', dirname($config_file), $redis_server_name, 'conf')
}

if $log_dir != $::redis::log_dir {
file { $log_dir:
ensure => directory,
group => $service_group,
mode => $log_dir_mode,
owner => $service_user,
}
}

$_real_log_file = $log_file ? {
undef => "${log_dir}/redis-server-${name}.log",
default => $log_file,
}

if $workdir != $::redis::workdir {
Expand All @@ -229,7 +249,7 @@

if $service_provider_lookup == 'systemd' {

file { "/etc/systemd/system/${title}.service":
file { "/etc/systemd/system/${redis_server_name}.service":
ensure => file,
owner => 'root',
group => 'root',
Expand All @@ -239,34 +259,34 @@
~> Exec['systemd-reload-redis']

if $title != 'default' {
service { $title:
service { $redis_server_name:
ensure => $service_ensure,
enable => $service_enable,
hasrestart => $service_hasrestart,
hasstatus => $service_hasstatus,
subscribe => [
File["/etc/systemd/system/${title}.service"],
File["/etc/systemd/system/${redis_server_name}.service"],
Exec["cp -p ${redis_file_name_orig} ${redis_file_name}"],
],
}
}

} else {

file { "/etc/init.d/${title}":
file { "/etc/init.d/${redis_server_name}":
ensure => file,
mode => '0755',
content => template("redis/service_templates/redis.${::osfamily}.erb"),
}

if $title != 'default' {
service { $title:
service { $redis_server_name:
ensure => $service_ensure,
enable => $service_enable,
hasrestart => $service_hasrestart,
hasstatus => $service_hasstatus,
subscribe => [
File["/etc/init.d/${title}"],
File["/etc/init.d/${redis_server_name}"],
Exec["cp -p ${redis_file_name_orig} ${redis_file_name}"],
],
}
Expand Down
12 changes: 6 additions & 6 deletions spec/acceptance/redis_multi_instances_one_host_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
describe 'redis::instance', :unless => (fact('operatingsystem') == 'Debian') do
case fact('osfamily')
when 'Debian'
config_path = '/etc/redis/redis.conf'
config_path = '/etc/redis'
manage_repo = false
redis_name = 'redis-server'
else
redis_name = 'redis'
config_path = '/etc/redis.conf'
config_path = '/etc'
manage_repo = true
end

Expand Down Expand Up @@ -43,19 +43,19 @@ class { '::redis':
it { should be_installed }
end

describe service('redis1') do
describe service('redis-server-redis1') do
it { should be_running }
end

describe service('redis2') do
describe service('redis-server-redis2') do
it { should be_running }
end

describe file("#{config_path}.redis1") do
describe file("#{config_path}/redis-server-redis1.conf") do
its(:content) { should match /port 7777/ }
end

describe file("#{config_path}.redis2") do
describe file("#{config_path}/redis-server-redis2.conf") do
its(:content) { should match /port 8888/ }
end

Expand Down
70 changes: 35 additions & 35 deletions spec/defines/instance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,69 +7,69 @@
}'
end
let :title do
'redis2'
'app2'
end
describe 'os-dependent items' do
context "on Ubuntu systems" do
context '14.04' do
let(:facts) {
ubuntu_1404_facts
}
it { should contain_file('/etc/redis/redis.conf.puppet.redis2').with('content' => /^bind 127.0.0.1/) }
it { should contain_file('/etc/redis/redis.conf.puppet.redis2').with('content' => /^logfile \/var\/log\/redis\/redis-server-redis2.log/) }
it { should contain_file('/etc/redis/redis.conf.puppet.redis2').with('content' => /^dir \/var\/lib\/redis\/redis-server-redis2/) }
it { should contain_file('/etc/redis/redis.conf.puppet.redis2').with('content' => /^unixsocket \/var\/run\/redis\/redis-server-redis2.sock/) }
it { should contain_file('/var/lib/redis/redis-server-redis2') }
it { should contain_service('redis2').with_ensure('running') }
it { should contain_service('redis2').with_enable('true') }
it { should contain_file('/etc/init.d/redis2').with_content(/DAEMON_ARGS=\/etc\/redis\/redis.conf.redis2/) }
it { should contain_file('/etc/init.d/redis2').with_content(/PIDFILE=\/var\/run\/redis\/redis-server-redis2.pid/) }
it { should contain_file('/etc/redis/redis-server-app2.conf.puppet').with('content' => /^bind 127.0.0.1/) }
it { should contain_file('/etc/redis/redis-server-app2.conf.puppet').with('content' => /^logfile \/var\/log\/redis\/redis-server-app2.log/) }
it { should contain_file('/etc/redis/redis-server-app2.conf.puppet').with('content' => /^dir \/var\/lib\/redis\/redis-server-app2/) }
it { should contain_file('/etc/redis/redis-server-app2.conf.puppet').with('content' => /^unixsocket \/var\/run\/redis\/redis-server-app2.sock/) }
it { should contain_file('/var/lib/redis/redis-server-app2') }
it { should contain_service('redis-server-app2').with_ensure('running') }
it { should contain_service('redis-server-app2').with_enable('true') }
it { should contain_file('/etc/init.d/redis-server-app2').with_content(/DAEMON_ARGS=\/etc\/redis\/redis-server-app2.conf/) }
it { should contain_file('/etc/init.d/redis-server-app2').with_content(/PIDFILE=\/var\/run\/redis\/redis-server-app2.pid/) }
end
context '16.04' do
let(:facts) {
ubuntu_1604_facts.merge({
:service_provider => 'systemd',
})
}
it { should contain_file('/etc/redis/redis.conf.puppet.redis2').with('content' => /^bind 127.0.0.1/) }
it { should contain_file('/etc/redis/redis.conf.puppet.redis2').with('content' => /^logfile \/var\/log\/redis\/redis-server-redis2.log/) }
it { should contain_file('/etc/redis/redis.conf.puppet.redis2').with('content' => /^dir \/var\/lib\/redis\/redis-server-redis2/) }
it { should contain_file('/etc/redis/redis.conf.puppet.redis2').with('content' => /^unixsocket \/var\/run\/redis\/redis-server-redis2.sock/) }
it { should contain_file('/var/lib/redis/redis-server-redis2') }
it { should contain_service('redis2').with_ensure('running') }
it { should contain_service('redis2').with_enable('true') }
it { should contain_file('/etc/systemd/system/redis2.service').with_content(/ExecStart=\/usr\/bin\/redis-server \/etc\/redis\/redis.conf.redis2/) }
it { should contain_file('/etc/redis/redis-server-app2.conf.puppet').with('content' => /^bind 127.0.0.1/) }
it { should contain_file('/etc/redis/redis-server-app2.conf.puppet').with('content' => /^logfile \/var\/log\/redis\/redis-server-app2.log/) }
it { should contain_file('/etc/redis/redis-server-app2.conf.puppet').with('content' => /^dir \/var\/lib\/redis\/redis-server-app2/) }
it { should contain_file('/etc/redis/redis-server-app2.conf.puppet').with('content' => /^unixsocket \/var\/run\/redis\/redis-server-app2.sock/) }
it { should contain_file('/var/lib/redis/redis-server-app2') }
it { should contain_service('redis-server-app2').with_ensure('running') }
it { should contain_service('redis-server-app2').with_enable('true') }
it { should contain_file('/etc/systemd/system/redis-server-app2.service').with_content(/ExecStart=\/usr\/bin\/redis-server \/etc\/redis\/redis-server-app2.conf/) }
end
end
context "on CentOS systems" do
context '6' do
let(:facts) {
centos_6_facts
}
it { should contain_file('/etc/redis.conf.puppet.redis2').with('content' => /^bind 127.0.0.1/) }
it { should contain_file('/etc/redis.conf.puppet.redis2').with('content' => /^logfile \/var\/log\/redis\/redis-server-redis2.log/) }
it { should contain_file('/etc/redis.conf.puppet.redis2').with('content' => /^dir \/var\/lib\/redis\/redis-server-redis2/) }
it { should contain_file('/etc/redis.conf.puppet.redis2').with('content' => /^unixsocket \/var\/run\/redis\/redis-server-redis2.sock/) }
it { should contain_file('/var/lib/redis/redis-server-redis2') }
it { should contain_service('redis2').with_ensure('running') }
it { should contain_service('redis2').with_enable('true') }
it { should contain_file('/etc/init.d/redis2').with_content(/REDIS_CONFIG="\/etc\/redis.conf.redis2"/) }
it { should contain_file('/etc/init.d/redis2').with_content(/pidfile="\/var\/run\/redis\/redis-server-redis2.pid"/) }
it { should contain_file('/etc/redis-server-app2.conf.puppet').with('content' => /^bind 127.0.0.1/) }
it { should contain_file('/etc/redis-server-app2.conf.puppet').with('content' => /^logfile \/var\/log\/redis\/redis-server-app2.log/) }
it { should contain_file('/etc/redis-server-app2.conf.puppet').with('content' => /^dir \/var\/lib\/redis\/redis-server-app2/) }
it { should contain_file('/etc/redis-server-app2.conf.puppet').with('content' => /^unixsocket \/var\/run\/redis\/redis-server-app2.sock/) }
it { should contain_file('/var/lib/redis/redis-server-app2') }
it { should contain_service('redis-server-app2').with_ensure('running') }
it { should contain_service('redis-server-app2').with_enable('true') }
it { should contain_file('/etc/init.d/redis-server-app2').with_content(/REDIS_CONFIG="\/etc\/redis-server-app2.conf"/) }
it { should contain_file('/etc/init.d/redis-server-app2').with_content(/pidfile="\/var\/run\/redis\/redis-server-app2.pid"/) }
end
context '7' do
let(:facts) {
centos_7_facts.merge({
:service_provider => 'systemd',
})
}
it { should contain_file('/etc/redis.conf.puppet.redis2').with('content' => /^bind 127.0.0.1/) }
it { should contain_file('/etc/redis.conf.puppet.redis2').with('content' => /^logfile \/var\/log\/redis\/redis-server-redis2.log/) }
it { should contain_file('/etc/redis.conf.puppet.redis2').with('content' => /^dir \/var\/lib\/redis\/redis-server-redis2/) }
it { should contain_file('/etc/redis.conf.puppet.redis2').with('content' => /^unixsocket \/var\/run\/redis\/redis-server-redis2.sock/) }
it { should contain_file('/var/lib/redis/redis-server-redis2') }
it { should contain_service('redis2').with_ensure('running') }
it { should contain_service('redis2').with_enable('true') }
it { should contain_file('/etc/systemd/system/redis2.service').with_content(/ExecStart=\/usr\/bin\/redis-server \/etc\/redis.conf.redis2/) }
it { should contain_file('/etc/redis-server-app2.conf.puppet').with('content' => /^bind 127.0.0.1/) }
it { should contain_file('/etc/redis-server-app2.conf.puppet').with('content' => /^logfile \/var\/log\/redis\/redis-server-app2.log/) }
it { should contain_file('/etc/redis-server-app2.conf.puppet').with('content' => /^dir \/var\/lib\/redis\/redis-server-app2/) }
it { should contain_file('/etc/redis-server-app2.conf.puppet').with('content' => /^unixsocket \/var\/run\/redis\/redis-server-app2.sock/) }
it { should contain_file('/var/lib/redis/redis-server-app2') }
it { should contain_service('redis-server-app2').with_ensure('running') }
it { should contain_service('redis-server-app2').with_enable('true') }
it { should contain_file('/etc/systemd/system/redis-server-app2.service').with_content(/ExecStart=\/usr\/bin\/redis-server \/etc\/redis-server-app2.conf/) }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion templates/redis.conf.2.4.10.erb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ loglevel <%= @log_level %>
# Specify the log file name. Also 'stdout' can be used to force
# Redis to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
logfile <%= @log_file %>
logfile <%= @_real_log_file %>

# To enable logging to the system logger, just set 'syslog-enabled' to yes,
# and optionally update the other syslog parameters to suit your needs.
Expand Down
2 changes: 1 addition & 1 deletion templates/redis.conf.2.8.erb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ loglevel <%= @log_level %>
# Specify the log file name. Also the empty string can be used to force
# Redis to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
logfile <%= @log_file %>
logfile <%= @_real_log_file %>

# To enable logging to the system logger, just set 'syslog-enabled' to yes,
# and optionally update the other syslog parameters to suit your needs.
Expand Down
2 changes: 1 addition & 1 deletion templates/redis.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ loglevel <%= @log_level %>
# Specify the log file name. Also 'stdout' can be used to force
# Redis to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
logfile <%= @log_file %>
logfile <%= @_real_log_file %>

# To enable logging to the system logger, just set 'syslog-enabled' to yes,
# and optionally update the other syslog parameters to suit your needs.
Expand Down