diff --git a/manifests/instance.pp b/manifests/instance.pp index a5dc4ba..2f46391 100644 --- a/manifests/instance.pp +++ b/manifests/instance.pp @@ -1,488 +1,500 @@ # This is an defined type to allow the configuration of # multiple redis instances on one machine without conflicts # # @summary Allows the configuration of multiple redis configurations on one machine # # @example # redis::instance {'6380': # port => 6380, # } # # @param activerehashing # Enable/disable active rehashing. # @param aof_load_truncated # Enable/disable loading truncated AOF file # @param aof_rewrite_incremental_fsync # Enable/disable fsync for AOF file # @param appendfilename # The name of the append only file # @param appendfsync # Adjust fsync mode. Valid options: always, everysec, no. # @param appendonly # Enable/disable appendonly mode. # @param auto_aof_rewrite_min_size # Adjust minimum size for auto-aof-rewrite. # @param auto_aof_rewrite_percentage # Adjust percentatge for auto-aof-rewrite. # @param bind # Configure which IP address(es) to listen on. To bind on all interfaces, use an empty array. # @param config_file_orig # The location and name of a config file that provides the source # @param config_file # Adjust main configuration file. # @param config_file_mode # Adjust permissions for configuration files. # @param config_group # Adjust filesystem group for config files. # @param config_owner # Adjust filesystem owner for config files. # @param conf_template # Define which template to use. # @param daemonize # Have Redis run as a daemon. # @param databases # Set the number of databases. # @param dbfilename # The filename where to dump the DB # @param extra_config_file # Optional extra config file to include # @param hash_max_ziplist_entries # Set max ziplist entries for hashes. # @param hash_max_ziplist_value # Set max ziplist values for hashes. # @param hll_sparse_max_bytes # HyperLogLog sparse representation bytes limit # @param hz # Set redis background tasks frequency # @param latency_monitor_threshold # Latency monitoring threshold in milliseconds # @param list_max_ziplist_entries # Set max ziplist entries for lists. # @param list_max_ziplist_value # Set max ziplist values for lists. # @param log_dir # Specify directory where to write log entries. # @param log_dir_mode # Adjust mode for directory containing log files. # @param log_file # Specify file where to write log entries. Relative paths will be prepended # with log_dir but absolute paths are also accepted. # @param log_level # Specify the server verbosity level. # @param masterauth # If the master is password protected (using the "requirepass" configuration # @param maxclients # Set the max number of connected clients at the same time. # @param maxmemory # Don't use more memory than the specified amount of bytes. # @param maxmemory_policy # How Redis will select what to remove when maxmemory is reached. # @param maxmemory_samples # Select as well the sample size to check. # @param min_slaves_max_lag # The lag in seconds # @param min_slaves_to_write # Minimum number of slaves to be in "online" state # @param no_appendfsync_on_rewrite # If you have latency problems turn this to 'true'. Otherwise leave it as # @param notify_keyspace_events # Which events to notify Pub/Sub clients about events happening # @param pid_file # Where to store the pid. # @param port # Configure which port to listen on. # @param protected_mode # Whether protected mode is enabled or not. Only applicable when no bind is set. # @param rdbcompression # Enable/disable compression of string objects using LZF when dumping. # @param rename_commands # A list of Redis commands to rename or disable for security reasons # @param repl_backlog_size # The replication backlog size # @param repl_backlog_ttl # The number of seconds to elapse before freeing backlog buffer # @param repl_disable_tcp_nodelay # Enable/disable TCP_NODELAY on the slave socket after SYNC # @param repl_ping_slave_period # Slaves send PINGs to server in a predefined interval. It's possible # @param repl_timeout # Set the replication timeout for: # @param requirepass # Require clients to issue AUTH before processing any other # commands. # @param save_db_to_disk # Set if save db to disk. # @param save_db_to_disk_interval # save the dataset every N seconds if there are at least M changes in the dataset # @param service_name # The service name for this instance # @param service_enable # Enable/disable daemon at boot. # @param service_ensure # Specify if the server should be running. # @param service_group # Specify which group to run as. # @param service_user # Specify which user to run as. # @param set_max_intset_entries # The following configuration setting sets the limit in the size of the set # in order to use this special memory saving encoding. # @param slave_priority # The priority number for slave promotion by Sentinel # @param slave_read_only # You can configure a slave instance to accept writes or not. # @param slave_serve_stale_data # When a slave loses its connection with the master, or when the replication # is still in progress, the slave can act in two different ways: # 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will # still reply to client requests, possibly with out of date data, or the # data set may just be empty if this is the first synchronization. # 2) if slave-serve-stale-data is set to 'no' the slave will reply with # an error "SYNC with master in progress" to all the kind of commands # but to INFO and SLAVEOF. # @param slaveof # Use slaveof to make a Redis instance a copy of another Redis server. # @param slowlog_log_slower_than # Tells Redis what is the execution time, in microseconds, to exceed in order # for the command to get logged. # @param slowlog_max_len # Tells Redis what is the length to exceed in order for the command # to get logged. # @param stop_writes_on_bgsave_error # If false then Redis will continue to work as usual even if there # are problems with disk, permissions, and so forth. # @param syslog_enabled # Enable/disable logging to the system logger. # @param syslog_facility # Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7. # @param tcp_backlog # Sets the TCP backlog # @param tcp_keepalive # TCP keepalive. # @param timeout # Close the connection after a client is idle for N seconds (0 to disable). # @param tls_port # Configure which TLS port to listen on. # @param tls_cert_file # Specify which X.509 certificate file to use for TLS connections. # @param tls_key_file # Specify which privaye key file to use for TLS connections. # @param tls_ca_cert_file # Specify which X.509 CA certificate(s) bundle file to use. # @param tls_ca_cert_dir # Specify which X.509 CA certificate(s) bundle directory to use. # @param tls_auth_clients # Specify if clients and replicas are required to authenticate using valid client side certificates. # @param tls_replication # Specify if TLS should be enabled on replication links. # @param tls_cluster # Specify if TLS should be used for the bus protocol. # @param tls_ciphers # Configure allowed ciphers for TLS <= TLSv1.2. # @param tls_ciphersuites # Configure allowed TLSv1.3 ciphersuites. # @param tls_protocols # Configure allowed TLS protocol versions. # @param tls_prefer_server_ciphers # Specify if the server's preference should be used when choosing a cipher. # @param ulimit # Limit the use of system-wide resources. # @param ulimit_managed # Defines wheter the max number of open files for the # systemd service unit is explicitly managed. # @param unixsocket # Define unix socket path # @param unixsocketperm # Define unix socket file permissions # @param workdir # The DB will be written inside this directory, with the filename specified # above using the 'dbfilename' configuration directive. # @param workdir_mode # Adjust mode for data directory. # @param zset_max_ziplist_entries # Set max entries for sorted sets. # @param zset_max_ziplist_value # Set max values for sorted sets. # @param cluster_enabled # Enables redis 3.0 cluster functionality # @param cluster_config_file # Config file for saving cluster nodes configuration. This file is never # touched by humans. Only set if cluster_enabled is true # @param cluster_node_timeout # Node timeout. Only set if cluster_enabled is true # @param cluster_slave_validity_factor # Control variable to disable promoting slave in case of disconnection from # master Only set if cluster_enabled is true # @param cluster_require_full_coverage # If false Redis Cluster will server queries even if requests about a subset # of keys can be processed Only set if cluster_enabled is true # @param cluster_migration_barrier # Minimum number of slaves master will remain connected with, for another # slave to migrate to a master which is no longer covered by any slave Only # set if cluster_enabled is true define redis::instance ( Boolean $activerehashing = $redis::activerehashing, Boolean $aof_load_truncated = $redis::aof_load_truncated, Boolean $aof_rewrite_incremental_fsync = $redis::aof_rewrite_incremental_fsync, String[1] $appendfilename = $redis::appendfilename, Enum['no', 'always', 'everysec'] $appendfsync = $redis::appendfsync, Boolean $appendonly = $redis::appendonly, String[1] $auto_aof_rewrite_min_size = $redis::auto_aof_rewrite_min_size, Integer[0] $auto_aof_rewrite_percentage = $redis::auto_aof_rewrite_percentage, Variant[Stdlib::IP::Address, Array[Stdlib::IP::Address]] $bind = $redis::bind, String[1] $output_buffer_limit_slave = $redis::output_buffer_limit_slave, String[1] $output_buffer_limit_pubsub = $redis::output_buffer_limit_pubsub, String[1] $conf_template = $redis::conf_template, Stdlib::Absolutepath $config_file = $redis::config_file, Stdlib::Filemode $config_file_mode = $redis::config_file_mode, Stdlib::Absolutepath $config_file_orig = $redis::config_file_orig, String[1] $config_group = $redis::config_group, String[1] $config_owner = $redis::config_owner, Boolean $daemonize = true, Integer[1] $databases = $redis::databases, Variant[String[1], Boolean] $dbfilename = $redis::dbfilename, Optional[String] $extra_config_file = $redis::extra_config_file, Integer[0] $hash_max_ziplist_entries = $redis::hash_max_ziplist_entries, Integer[0] $hash_max_ziplist_value = $redis::hash_max_ziplist_value, Integer[0] $hll_sparse_max_bytes = $redis::hll_sparse_max_bytes, Integer[1, 500] $hz = $redis::hz, Integer[0] $latency_monitor_threshold = $redis::latency_monitor_threshold, Integer[0] $list_max_ziplist_entries = $redis::list_max_ziplist_entries, Integer[0] $list_max_ziplist_value = $redis::list_max_ziplist_value, Stdlib::Absolutepath $log_dir = $redis::log_dir, Stdlib::Filemode $log_dir_mode = $redis::log_dir_mode, Redis::LogLevel $log_level = $redis::log_level, Optional[Variant[String[1], Sensitive[String[1]]]] $masterauth = $redis::masterauth, Integer[1] $maxclients = $redis::maxclients, Optional[Variant[Integer, String]] $maxmemory = $redis::maxmemory, Optional[String] $maxmemory_policy = $redis::maxmemory_policy, Optional[Variant[Integer, String]] $maxmemory_samples = $redis::maxmemory_samples, Integer[0] $min_slaves_max_lag = $redis::min_slaves_max_lag, Integer[0] $min_slaves_to_write = $redis::min_slaves_to_write, Boolean $no_appendfsync_on_rewrite = $redis::no_appendfsync_on_rewrite, Optional[String[1]] $notify_keyspace_events = $redis::notify_keyspace_events, Boolean $managed_by_cluster_manager = $redis::managed_by_cluster_manager, Stdlib::Port $port = $redis::port, Boolean $protected_mode = $redis::protected_mode, Boolean $rdbcompression = $redis::rdbcompression, Hash[String,String] $rename_commands = $redis::rename_commands, String[1] $repl_backlog_size = $redis::repl_backlog_size, Integer[0] $repl_backlog_ttl = $redis::repl_backlog_ttl, Boolean $repl_disable_tcp_nodelay = $redis::repl_disable_tcp_nodelay, Integer[1] $repl_ping_slave_period = $redis::repl_ping_slave_period, Integer[1] $repl_timeout = $redis::repl_timeout, Optional[String] $requirepass = $redis::requirepass, Boolean $save_db_to_disk = $redis::save_db_to_disk, Hash $save_db_to_disk_interval = $redis::save_db_to_disk_interval, String[1] $service_user = $redis::service_user, Integer[0] $set_max_intset_entries = $redis::set_max_intset_entries, Integer[0] $slave_priority = $redis::slave_priority, Boolean $slave_read_only = $redis::slave_read_only, Boolean $slave_serve_stale_data = $redis::slave_serve_stale_data, Optional[String[1]] $slaveof = $redis::slaveof, Integer[-1] $slowlog_log_slower_than = $redis::slowlog_log_slower_than, Integer[0] $slowlog_max_len = $redis::slowlog_max_len, Boolean $stop_writes_on_bgsave_error = $redis::stop_writes_on_bgsave_error, Boolean $syslog_enabled = $redis::syslog_enabled, Optional[String[1]] $syslog_facility = $redis::syslog_facility, Integer[0] $tcp_backlog = $redis::tcp_backlog, Integer[0] $tcp_keepalive = $redis::tcp_keepalive, Integer[0] $timeout = $redis::timeout, Optional[Stdlib::Port] $tls_port = $redis::tls_port, Optional[Stdlib::Absolutepath] $tls_cert_file = $redis::tls_cert_file, Optional[Stdlib::Absolutepath] $tls_key_file = $redis::tls_key_file, Optional[Stdlib::Absolutepath] $tls_ca_cert_file = $redis::tls_ca_cert_file, Optional[Stdlib::Absolutepath] $tls_ca_cert_dir = $redis::tls_ca_cert_dir, Optional[String[1]] $tls_ciphers = $redis::tls_ciphers, Optional[String[1]] $tls_ciphersuites = $redis::tls_ciphersuites, Optional[String[1]] $tls_protocols = $redis::tls_protocols, Enum['yes', 'no', 'optional'] $tls_auth_clients = $redis::tls_auth_clients, Boolean $tls_replication = $redis::tls_replication, Boolean $tls_cluster = $redis::tls_cluster, Optional[Boolean] $tls_prefer_server_ciphers = $redis::tls_prefer_server_ciphers, Variant[Stdlib::Filemode, Enum['']] $unixsocketperm = $redis::unixsocketperm, Integer[0] $ulimit = $redis::ulimit, Boolean $ulimit_managed = $redis::ulimit_managed, Stdlib::Filemode $workdir_mode = $redis::workdir_mode, Integer[0] $zset_max_ziplist_entries = $redis::zset_max_ziplist_entries, Integer[0] $zset_max_ziplist_value = $redis::zset_max_ziplist_value, Boolean $cluster_enabled = $redis::cluster_enabled, String[1] $cluster_config_file = $redis::cluster_config_file, Integer[1] $cluster_node_timeout = $redis::cluster_node_timeout, Integer[0] $cluster_slave_validity_factor = $redis::cluster_slave_validity_factor, Boolean $cluster_require_full_coverage = $redis::cluster_require_full_coverage, Integer[0] $cluster_migration_barrier = $redis::cluster_migration_barrier, String[1] $service_name = "redis-server-${name}", Stdlib::Ensure::Service $service_ensure = $redis::service_ensure, Boolean $service_enable = $redis::service_enable, String[1] $service_group = $redis::service_group, Boolean $manage_service_file = true, String $log_file = "redis-server-${name}.log", - Stdlib::Absolutepath $pid_file = "/var/run/redis/redis-server-${name}.pid", - Variant[Stdlib::Absolutepath, Enum['']] $unixsocket = "/var/run/redis/redis-server-${name}.sock", + Stdlib::Absolutepath $pid_file = "/var/run/${service_name}/redis.pid", + Variant[Stdlib::Absolutepath, Enum['']] $unixsocket = "/var/run/${service_name}/redis.sock", Stdlib::Absolutepath $workdir = "${redis::workdir}/redis-server-${name}", ) { if $title == 'default' { $redis_file_name_orig = $config_file_orig $redis_file_name = $config_file } else { $redis_file_name_orig = sprintf('%s/%s.%s', dirname($config_file_orig), $service_name, 'conf.puppet') $redis_file_name = sprintf('%s/%s.%s', dirname($config_file), $service_name, 'conf') } if $log_dir != $redis::log_dir { file { $log_dir: ensure => directory, group => $service_group, mode => $log_dir_mode, owner => $service_user, } } if $workdir != $redis::workdir { file { $workdir: ensure => directory, group => $service_group, mode => $workdir_mode, owner => $service_user, } } if $manage_service_file { if $title != 'default' { $real_service_ensure = $service_ensure == 'running' $real_service_enable = $service_enable Exec["cp -p ${redis_file_name_orig} ${redis_file_name}"] ~> Service["${service_name}.service"] } else { $real_service_ensure = undef $real_service_enable = undef } systemd::unit_file { "${service_name}.service": ensure => 'present', active => $real_service_ensure, enable => $real_service_enable, owner => 'root', group => 'root', mode => '0644', - content => template('redis/service_templates/redis.service.erb'), + content => epp( + 'redis/service_templates/redis.service.epp', + { + bin_path => $redis::bin_path, + instance_title => $name, + port => $port, + redis_file_name => $redis_file_name, + service_name => $service_name, + service_user => $service_user, + ulimit => $ulimit, + ulimit_managed => $ulimit_managed, + } + ), } } else { if $ulimit_managed { systemd::service_limits { "${service_name}.service": limits => { 'LimitNOFILE' => $ulimit, }, restart_service => false, } } } $_real_log_file = $log_file ? { Stdlib::Absolutepath => $log_file, default => "${log_dir}/${log_file}", } $bind_arr = [$bind].flatten file { $redis_file_name_orig: ensure => file, owner => $config_owner, group => $config_group, mode => $config_file_mode, content => epp( $conf_template, { daemonize => $daemonize, pid_file => $pid_file, protected_mode => $protected_mode, port => $port, tcp_backlog => $tcp_backlog, bind_arr => $bind_arr, unixsocket => $unixsocket, unixsocketperm => $unixsocketperm, timeout => $timeout, tcp_keepalive => $tcp_keepalive, log_level => $log_level, log_file => $_real_log_file, syslog_enabled => $syslog_enabled, syslog_facility => $syslog_facility, databases => $databases, save_db_to_disk => $save_db_to_disk, save_db_to_disk_interval => $save_db_to_disk_interval, stop_writes_on_bgsave_error => $stop_writes_on_bgsave_error, rdbcompression => $rdbcompression, dbfilename => $dbfilename, workdir => $workdir, slaveof => $slaveof, masterauth => $masterauth, slave_serve_stale_data => $slave_serve_stale_data, slave_read_only => $slave_read_only, repl_ping_slave_period => $repl_ping_slave_period, repl_timeout => $repl_timeout, repl_disable_tcp_nodelay => $repl_disable_tcp_nodelay, repl_backlog_size => $repl_backlog_size, repl_backlog_ttl => $repl_backlog_ttl, slave_priority => $slave_priority, min_slaves_to_write => $min_slaves_to_write, min_slaves_max_lag => $min_slaves_max_lag, requirepass => $requirepass, rename_commands => $rename_commands, maxclients => $maxclients, maxmemory => $maxmemory, maxmemory_policy => $maxmemory_policy, maxmemory_samples => $maxmemory_samples, appendonly => $appendonly, appendfilename => $appendfilename, appendfsync => $appendfsync, no_appendfsync_on_rewrite => $no_appendfsync_on_rewrite, auto_aof_rewrite_percentage => $auto_aof_rewrite_percentage, auto_aof_rewrite_min_size => $auto_aof_rewrite_min_size, aof_load_truncated => $aof_load_truncated, slowlog_log_slower_than => $slowlog_log_slower_than, slowlog_max_len => $slowlog_max_len, latency_monitor_threshold => $latency_monitor_threshold, notify_keyspace_events => $notify_keyspace_events, hash_max_ziplist_entries => $hash_max_ziplist_entries, hash_max_ziplist_value => $hash_max_ziplist_value, list_max_ziplist_entries => $list_max_ziplist_entries, list_max_ziplist_value => $list_max_ziplist_value, set_max_intset_entries => $set_max_intset_entries, zset_max_ziplist_entries => $zset_max_ziplist_entries, zset_max_ziplist_value => $zset_max_ziplist_value, hll_sparse_max_bytes => $hll_sparse_max_bytes, activerehashing => $activerehashing, output_buffer_limit_slave => $output_buffer_limit_slave, output_buffer_limit_pubsub => $output_buffer_limit_pubsub, hz => $hz, aof_rewrite_incremental_fsync => $aof_rewrite_incremental_fsync, cluster_enabled => $cluster_enabled, cluster_config_file => $cluster_config_file, cluster_node_timeout => $cluster_node_timeout, cluster_slave_validity_factor => $cluster_slave_validity_factor, cluster_require_full_coverage => $cluster_require_full_coverage, cluster_migration_barrier => $cluster_migration_barrier, extra_config_file => $extra_config_file, tls_port => $tls_port, tls_cert_file => $tls_cert_file, tls_key_file => $tls_key_file, tls_ca_cert_file => $tls_ca_cert_file, tls_ca_cert_dir => $tls_ca_cert_dir, tls_ciphers => $tls_ciphers, tls_ciphersuites => $tls_ciphersuites, tls_protocols => $tls_protocols, tls_auth_clients => $tls_auth_clients, tls_replication => $tls_replication, tls_cluster => $tls_cluster, tls_prefer_server_ciphers => $tls_prefer_server_ciphers, } ), } exec { "cp -p ${redis_file_name_orig} ${redis_file_name}": path => '/usr/bin:/bin', subscribe => File[$redis_file_name_orig], refreshonly => true, } } diff --git a/spec/classes/redis_spec.rb b/spec/classes/redis_spec.rb index c45cf08..c780e8e 100644 --- a/spec/classes/redis_spec.rb +++ b/spec/classes/redis_spec.rb @@ -1,1438 +1,1438 @@ require 'spec_helper' describe 'redis' do let(:package_name) { facts[:osfamily] == 'Debian' ? 'redis-server' : 'redis' } let(:service_name) { package_name } let(:config_file) do case facts[:osfamily] when 'Archlinux', 'Debian' '/etc/redis/redis.conf' when 'FreeBSD' '/usr/local/etc/redis.conf' when 'RedHat' '/etc/redis.conf' end end let(:config_file_orig) { "#{config_file}.puppet" } on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) { facts } describe 'without parameters' do it { is_expected.to compile.with_all_deps } it { is_expected.to create_class('redis') } it { is_expected.to contain_class('redis::preinstall') } it { is_expected.to contain_class('redis::install') } it { is_expected.to contain_class('redis::config') } it { is_expected.to contain_class('redis::service') } it { is_expected.to contain_package(package_name).with_ensure('installed') } it do is_expected.to contain_file(config_file_orig). with_ensure('file'). with_content(%r{logfile /var/log/redis/redis\.log}). without_content(%r{undef}) if facts[:osfamily] == 'FreeBSD' is_expected.to contain_file(config_file_orig). with_content(%r{dir /var/db/redis}). with_content(%r{pidfile /var/run/redis/redis\.pid}) end end it { is_expected.to contain_service(service_name).with_ensure('running').with_enable('true') } context 'with SCL', if: facts[:osfamily] == 'RedHat' && facts[:operatingsystemmajrelease] < '8' do let(:pre_condition) do <<-PUPPET class { 'redis::globals': scl => 'rh-redis5', } PUPPET end it { is_expected.to compile.with_all_deps } it do is_expected.to create_class('redis'). with_package_name('rh-redis5-redis'). with_config_file('/etc/opt/rh/rh-redis5/redis.conf'). with_service_name('rh-redis5-redis') end context 'manage_repo => true', if: facts[:operatingsystem] == 'CentOS' do let(:params) { { manage_repo: true } } it { is_expected.to compile.with_all_deps } it { is_expected.to contain_package('centos-release-scl-rh') } end end end context 'with managed_by_cluster_manager true' do let(:params) { { managed_by_cluster_manager: true } } it { is_expected.to compile.with_all_deps } it do is_expected.to contain_file('/etc/security/limits.d/redis.conf').with( 'ensure' => 'file', 'owner' => 'root', 'group' => 'root', 'mode' => '0644', 'content' => "redis soft nofile 65536\nredis hard nofile 65536\n" ) end context 'when not managing service' do let(:params) { super().merge(service_manage: false, notify_service: false) } it { is_expected.to compile.with_all_deps } it do is_expected.to contain_file('/etc/security/limits.d/redis.conf').with( 'ensure' => 'file', 'owner' => 'root', 'group' => 'root', 'mode' => '0644', 'content' => "redis soft nofile 65536\nredis hard nofile 65536\n" ) end end end describe 'with parameter ulimit_managed' do context 'true' do let(:params) { { ulimit: 7777, ulimit_managed: true } } it { is_expected.to compile.with_all_deps } it do is_expected.to contain_file("/etc/systemd/system/#{service_name}.service.d/limit.conf"). with_ensure('absent') is_expected.to contain_systemd__service_limits("#{service_name}.service"). with_limits({ 'LimitNOFILE' => 7777 }). with_restart_service(false). with_ensure('present') end end context 'false' do let(:params) { { ulimit_managed: false } } it { is_expected.to compile.with_all_deps } it do is_expected.not_to contain_systemd__service_limits("#{service_name}.service") end end end describe 'with parameter activerehashing' do let(:params) do { activerehashing: true } end it { is_expected.to contain_file(config_file_orig).with_content(%r{activerehashing.*yes}) } end describe 'with parameter aof_load_truncated' do let(:params) do { aof_load_truncated: true } end it { is_expected.to contain_file(config_file_orig).with_content(%r{aof-load-truncated.*yes}) } end describe 'with parameter aof_rewrite_incremental_fsync' do let(:params) do { aof_rewrite_incremental_fsync: true } end it { is_expected.to contain_file(config_file_orig).with_content(%r{aof-rewrite-incremental-fsync.*yes}) } end describe 'with parameter appendfilename' do let(:params) do { appendfilename: '_VALUE_' } end it { is_expected.to contain_file(config_file_orig).with_content(%r{appendfilename.*_VALUE_}) } end describe 'with parameter appendfsync' do let(:params) do { appendfsync: 'no' } end it { is_expected.to contain_file(config_file_orig).with_content(%r{^appendfsync no$}) } end describe 'with parameter appendonly' do let(:params) do { appendonly: true } end it { is_expected.to contain_file(config_file_orig).with_content(%r{appendonly.*yes}) } end describe 'with parameter auto_aof_rewrite_min_size' do let(:params) do { auto_aof_rewrite_min_size: '_VALUE_' } end it { is_expected.to contain_file(config_file_orig).with_content(%r{auto-aof-rewrite-min-size.*_VALUE_}) } end describe 'with parameter auto_aof_rewrite_percentage' do let(:params) do { auto_aof_rewrite_percentage: 75 } end it { is_expected.to contain_file(config_file_orig).with_content(%r{auto-aof-rewrite-percentage 75}) } end describe 'parameter bind' do context 'by default' do it 'binds to localhost' do is_expected.to contain_file(config_file_orig).with_content(%r{bind 127\.0\.0\.1$}) end end context 'with a single IP address' do let(:params) { { bind: '10.0.0.1' } } it { is_expected.to contain_file(config_file_orig).with_content(%r{bind 10\.0\.0\.1$}) } end context 'with array of IP addresses' do let(:params) do { bind: ['127.0.0.1', '::1'] } end it { is_expected.to contain_file(config_file_orig).with_content(%r{bind 127\.0\.0\.1 ::1}) } end context 'with empty array' do let(:params) { { bind: [] } } it { is_expected.not_to contain_file(config_file_orig).with_content(%r{^bind}) } end end describe 'with parameter output_buffer_limit_slave' do let(:params) do { output_buffer_limit_slave: '_VALUE_' } end it { is_expected.to contain_file(config_file_orig).with_content(%r{client-output-buffer-limit slave.*_VALUE_}) } end describe 'with parameter output_buffer_limit_pubsub' do let(:params) do { output_buffer_limit_pubsub: '_VALUE_' } end it { is_expected.to contain_file(config_file_orig).with_content(%r{client-output-buffer-limit pubsub.*_VALUE_}) } end describe 'with parameter: config_dir' do let(:params) { { config_dir: '/etc/config_dir' } } it { is_expected.to contain_file('/etc/config_dir').with_ensure('directory') } end describe 'with parameter: config_dir_mode' do let(:params) { { config_dir_mode: '0700' } } it { is_expected.to contain_file('/etc/redis').with_mode('0700') } end describe 'with parameter: log_dir_mode' do let(:params) { { log_dir_mode: '0660' } } it { is_expected.to contain_file('/var/log/redis').with_mode('0660') } end describe 'with parameter: config_file_orig' do let(:params) { { config_file_orig: '/path/to/orig' } } it { is_expected.to contain_file('/path/to/orig') } end describe 'with parameter: config_file_mode' do let(:params) { { config_file_mode: '0600' } } it { is_expected.to contain_file(config_file_orig).with_mode('0600') } end describe 'with parameter: config_group' do let(:params) { { config_group: '_VALUE_' } } it { is_expected.to contain_file('/etc/redis').with_group('_VALUE_') } end describe 'with parameter: config_owner' do let(:params) { { config_owner: '_VALUE_' } } it { is_expected.to contain_file('/etc/redis').with_owner('_VALUE_') } end describe 'with parameter daemonize' do let(:params) do { daemonize: true } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{daemonize.*yes} ) } end describe 'with parameter databases' do let(:params) do { databases: 42 } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{databases 42} ) } end describe 'with parameter dbfilename' do let(:params) do { dbfilename: '_VALUE_' } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{dbfilename.*_VALUE_} ) } end describe 'without parameter dbfilename' do let(:params) do { dbfilename: false } end it { is_expected.to contain_file(config_file_orig).without_content(%r{^dbfilename}) } end describe 'with parameter hash_max_ziplist_entries' do let(:params) do { hash_max_ziplist_entries: 42 } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{hash-max-ziplist-entries 42} ) } end describe 'with parameter hash_max_ziplist_value' do let(:params) do { hash_max_ziplist_value: 42 } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{hash-max-ziplist-value 42} ) } end # TODO: Only present in 3.0 describe 'with parameter list_max_ziplist_entries' do let(:params) do { list_max_ziplist_entries: 42 } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{list-max-ziplist-entries 42} ) } end describe 'with parameter list_max_ziplist_value' do let(:params) do { list_max_ziplist_value: 42 } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{list-max-ziplist-value 42} ) } end describe 'with parameter log_dir' do let(:params) do { log_dir: '/var/log/redis' } end it { is_expected.to contain_file('/var/log/redis').with( 'ensure' => 'directory' ) } end describe 'with parameter log_file' do describe 'as absolute path' do let(:params) do { log_file: '/var/log/my-redis/my-redis.log' } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{^logfile /var/log/my-redis/my-redis\.log$} ) } end describe 'as relative path' do let(:params) do { log_dir: '/var/log/my-redis', log_file: 'my-redis.log' } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{^logfile /var/log/my-redis/my-redis\.log$} ) } end end describe 'with parameter log_level' do let(:params) do { log_level: 'debug' } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{^loglevel debug$} ) } end describe 'with parameter: manage_repo' do let(:params) { { manage_repo: true } } case facts[:operatingsystem] when 'Ubuntu' it { is_expected.to contain_apt__ppa('ppa:chris-lea/redis-server') } when 'RedHat', 'CentOS', 'Scientific', 'OEL', 'Amazon' it { is_expected.to contain_class('epel') } end end describe 'with parameter unixsocket' do describe '/tmp/redis.sock' do let(:params) { { unixsocket: '/tmp/redis.sock' } } it { is_expected.to contain_file(config_file_orig).with_content(%r{^unixsocket /tmp/redis\.sock$}) } end describe 'empty string' do let(:params) { { unixsocket: '' } } it { is_expected.to contain_file(config_file_orig).without_content(%r{^unixsocket }) } end end describe 'with parameter unixsocketperm' do describe '777' do let(:params) { { unixsocketperm: '777' } } it { is_expected.to contain_file(config_file_orig).with_content(%r{^unixsocketperm 777$}) } end describe 'empty string' do let(:params) { { unixsocketperm: '' } } it { is_expected.to contain_file(config_file_orig).without_content(%r{^unixsocketperm }) } end end describe 'with parameter masterauth' do let(:params) do { masterauth: '_VALUE_' } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{masterauth.*_VALUE_} ) } end describe 'with parameter maxclients' do let(:params) do { maxclients: 42 } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{^maxclients 42$} ) } end describe 'with parameter maxmemory' do let(:params) do { maxmemory: '_VALUE_' } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{maxmemory.*_VALUE_} ) } end describe 'with parameter maxmemory_policy' do let(:params) do { maxmemory_policy: '_VALUE_' } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{maxmemory-policy.*_VALUE_} ) } end describe 'with parameter maxmemory_samples' do let(:params) do { maxmemory_samples: '_VALUE_' } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{maxmemory-samples.*_VALUE_} ) } end describe 'with parameter min_slaves_max_lag' do let(:params) do { min_slaves_max_lag: 42 } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{^min-slaves-max-lag 42$} ) } end describe 'with parameter min_slaves_to_write' do let(:params) do { min_slaves_to_write: 42 } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{^min-slaves-to-write 42$} ) } end describe 'with parameter notify_keyspace_events' do let(:params) do { notify_keyspace_events: '_VALUE_' } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{notify-keyspace-events.*_VALUE_} ) } end describe 'with parameter notify_service' do let(:params) do { notify_service: true } end it { is_expected.to contain_file(config_file_orig).that_notifies("Service[#{service_name}]") } end describe 'with parameter no_appendfsync_on_rewrite' do let(:params) do { no_appendfsync_on_rewrite: true } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{no-appendfsync-on-rewrite.*yes} ) } end describe 'with parameter: package_ensure' do let(:params) { { package_ensure: '_VALUE_' } } it { is_expected.to contain_package(package_name).with( 'ensure' => '_VALUE_' ) } end describe 'with parameter: package_name' do let(:params) { { package_name: '_VALUE_' } } it { is_expected.to contain_package('_VALUE_') } end describe 'with parameter pid_file' do let(:params) do { pid_file: '/path/to/redis.pid' } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{^pidfile /path/to/redis.pid$} ) } end describe 'with parameter port' do let(:params) do { port: 6666 } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{^port 6666$} ) } end describe 'with parameter protected-mode' do let(:params) do { protected_mode: false } end it { is_expected.to contain_file(config_file_orig).with_content(%r{^protected-mode no$}) } end describe 'with parameter hll_sparse_max_bytes' do let(:params) do { hll_sparse_max_bytes: 42 } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{^hll-sparse-max-bytes 42$} ) } end describe 'with parameter hz' do let(:params) do { hz: 42 } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{^hz 42$} ) } end describe 'with parameter latency_monitor_threshold' do let(:params) do { latency_monitor_threshold: 42 } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{^latency-monitor-threshold 42$} ) } end describe 'with parameter rdbcompression' do let(:params) do { rdbcompression: true } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{rdbcompression.*yes} ) } end describe 'with parameter rename_commands' do context 'with a single rename' do let(:params) do { rename_commands: { CONFIG: '""' } } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{^rename-command CONFIG ""$} ) } end context 'with multiple renames' do let(:params) do { rename_commands: { CONFIG: '""', RENAME: '""' } } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{^rename-command CONFIG ""$} ) is_expected.to contain_file(config_file_orig).with( 'content' => %r{^rename-command RENAME ""$} ) } end context 'with empty hash' do let(:params) do { 'rename_commands' => {} } end it { is_expected.not_to contain_file(config_file_orig).with_content(%r{^rename-command}) } end end describe 'with parameter repl_backlog_size' do let(:params) do { repl_backlog_size: '_VALUE_' } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{repl-backlog-size.*_VALUE_} ) } end describe 'with parameter repl_backlog_ttl' do let(:params) do { repl_backlog_ttl: 42 } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{^repl-backlog-ttl 42$} ) } end describe 'with parameter repl_disable_tcp_nodelay' do let(:params) do { repl_disable_tcp_nodelay: true } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{repl-disable-tcp-nodelay.*yes} ) } end describe 'with parameter repl_ping_slave_period' do let(:params) do { repl_ping_slave_period: 42 } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{^repl-ping-slave-period 42} ) } end describe 'with parameter repl_timeout' do let(:params) do { repl_timeout: 1 } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{repl-timeout.*1} ) } end describe 'with parameter requirepass' do let(:params) do { requirepass: '_VALUE_' } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{requirepass.*_VALUE_} ) } end describe 'with parameter save_db_to_disk' do context 'true' do let(:params) do { save_db_to_disk: true } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{^save} ) } end context 'false' do let(:params) do { save_db_to_disk: false } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{^(?!save)} ) } end end describe 'with parameter save_db_to_disk_interval' do context 'with save_db_to_disk true' do context 'default' do let(:params) do { save_db_to_disk: true } end it { is_expected.to contain_file(config_file_orig).with('content' => %r{save 900 1}) } it { is_expected.to contain_file(config_file_orig).with('content' => %r{save 300 10}) } it { is_expected.to contain_file(config_file_orig).with('content' => %r{save 60 10000}) } end context 'default' do let(:params) do { save_db_to_disk: true, save_db_to_disk_interval: { '900' => '2', '300' => '11', '60' => '10011' } } end it { is_expected.to contain_file(config_file_orig).with('content' => %r{save 900 2}) } it { is_expected.to contain_file(config_file_orig).with('content' => %r{save 300 11}) } it { is_expected.to contain_file(config_file_orig).with('content' => %r{save 60 10011}) } end end context 'with save_db_to_disk false' do context 'default' do let(:params) do { save_db_to_disk: false } end it { is_expected.to contain_file(config_file_orig).without('content' => %r{save 900 1}) } it { is_expected.to contain_file(config_file_orig).without('content' => %r{save 300 10}) } it { is_expected.to contain_file(config_file_orig).without('content' => %r{save 60 10000}) } end end end describe 'with parameter: service_manage (set to false)' do let(:params) { { service_manage: false } } it { is_expected.not_to contain_service(package_name) } end describe 'with parameter: service_enable' do let(:params) { { service_enable: true } } it { is_expected.to contain_service(package_name).with_enable(true) } end describe 'with parameter: service_ensure' do let(:params) { { service_ensure: 'stopped' } } it { is_expected.to contain_service(package_name).with_ensure('stopped') } end describe 'with parameter: service_group' do let(:params) { { service_group: '_VALUE_' } } it { is_expected.to contain_file('/var/log/redis').with_group('_VALUE_') } end describe 'with parameter: service_name' do let(:params) { { service_name: '_VALUE_' } } it { is_expected.to contain_service('_VALUE_').with_name('_VALUE_') } end describe 'with parameter: service_user' do let(:params) { { service_user: '_VALUE_' } } it { is_expected.to contain_file('/var/log/redis').with_owner('_VALUE_') } end describe 'with parameter set_max_intset_entries' do let(:params) do { set_max_intset_entries: 42 } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{^set-max-intset-entries 42$} ) } end describe 'with parameter slave_priority' do let(:params) do { slave_priority: 42 } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{^slave-priority 42$} ) } end describe 'with parameter slave_read_only' do let(:params) do { slave_read_only: true } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{slave-read-only.*yes} ) } end describe 'with parameter slave_serve_stale_data' do let(:params) do { slave_serve_stale_data: true } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{slave-serve-stale-data.*yes} ) } end describe 'with parameter: slaveof' do context 'binding to localhost' do let(:params) do { bind: '127.0.0.1', slaveof: '_VALUE_' } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{^slaveof _VALUE_} ) } end context 'binding to external ip' do let(:params) do { bind: '10.0.0.1', slaveof: '_VALUE_' } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{^slaveof _VALUE_} ) } end end describe 'with parameter slowlog_log_slower_than' do context 'set to a value great or equal to zero' do let(:params) do { slowlog_log_slower_than: 42 } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{^slowlog-log-slower-than 42$} ) } end context 'set to -1 (disabled)' do let(:params) do { slowlog_log_slower_than: -1 } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{^slowlog-log-slower-than -1$} ) } end end describe 'with parameter slowlog_max_len' do let(:params) do { slowlog_max_len: 42 } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{^slowlog-max-len 42$} ) } end describe 'with parameter stop_writes_on_bgsave_error' do let(:params) do { stop_writes_on_bgsave_error: true } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{stop-writes-on-bgsave-error.*yes} ) } end describe 'with parameter syslog_enabled' do let(:params) do { syslog_enabled: true } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{syslog-enabled yes} ) } end describe 'with parameter syslog_facility' do let(:params) do { syslog_enabled: true, syslog_facility: '_VALUE_' } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{syslog-facility.*_VALUE_} ) } end describe 'with parameter tcp_backlog' do let(:params) do { tcp_backlog: 42 } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{^tcp-backlog 42$} ) } end describe 'with parameter tcp_keepalive' do let(:params) do { tcp_keepalive: 42 } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{^tcp-keepalive 42$} ) } end describe 'with parameter timeout' do let(:params) do { timeout: 42 } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{^timeout 42$} ) } end describe 'with parameter workdir' do let(:params) do { workdir: '/var/workdir' } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{^dir /var/workdir$} ) } end describe 'with parameter zset_max_ziplist_entries' do let(:params) do { zset_max_ziplist_entries: 42 } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{zset-max-ziplist-entries 42} ) } end describe 'with parameter zset_max_ziplist_value' do let(:params) do { zset_max_ziplist_value: 42 } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{zset-max-ziplist-value 42} ) } end describe 'with parameter cluster_enabled-false' do let(:params) do { cluster_enabled: false } end it { is_expected.not_to contain_file(config_file_orig).with( 'content' => %r{cluster-enabled} ) } end describe 'with parameter cluster_enabled-true' do let(:params) do { cluster_enabled: true } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{cluster-enabled.*yes} ) } end describe 'with parameter cluster_config_file' do let(:params) do { cluster_enabled: true, cluster_config_file: '_VALUE_' } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{cluster-config-file.*_VALUE_} ) } end describe 'with parameter cluster_config_file' do let(:params) do { cluster_enabled: true, cluster_node_timeout: 42 } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{cluster-node-timeout 42} ) } end describe 'with parameter cluster_config_file' do let(:params) do { cluster_enabled: true, cluster_slave_validity_factor: 1 } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{cluster-slave-validity-factor.*1} ) } end describe 'with parameter cluster_config_file' do let(:params) do { cluster_enabled: true, cluster_require_full_coverage: true } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{cluster-require-full-coverage.*yes} ) } end describe 'with parameter cluster_config_file' do let(:params) do { cluster_enabled: true, cluster_require_full_coverage: false } end it { is_expected.to contain_file(config_file_orig).with_content(%r{cluster-require-full-coverage.*no}) } end describe 'with parameter cluster_config_file' do let(:params) do { cluster_enabled: true, cluster_migration_barrier: 1 } end it { is_expected.to contain_file(config_file_orig).with_content(%r{cluster-migration-barrier.*1}) } end describe 'with TLS related parameters' do let(:params) do { tls_port: 7777, tls_cert_file: '/etc/ssl/certs/dummy.crt', tls_key_file: '/etc/ssl/private/dummy.key', tls_ca_cert_file: '/etc/ssl/certs/ca_bundle.pem', tls_ca_cert_dir: '/etc/ssl/some/dir', tls_auth_clients: 'no', tls_replication: true, tls_cluster: true, tls_ciphers: 'DEFAULT:!MEDIUM', tls_ciphersuites: 'TLS_CHACHA20_POLY1305_SHA256', tls_protocols: 'TLSv1.2 TLSv1.3', tls_prefer_server_ciphers: true } end it do is_expected.to contain_file(config_file_orig). with_content(%r{^tls-port 7777$}). with_content(%r{^tls-cert-file\s*/etc/ssl/certs/dummy\.crt$}). with_content(%r{^tls-key-file\s*/etc/ssl/private/dummy\.key$}). with_content(%r{^tls-ca-cert-file\s*/etc/ssl/certs/ca_bundle\.pem$}). with_content(%r{^tls-ca-cert-dir\s*/etc/ssl/some/dir$}). with_content(%r{^tls-auth-clients\s*no$}). with_content(%r{^tls-replication\s*yes$}). with_content(%r{^tls-cluster\s*yes$}). with_content(%r{^tls-ciphers\s*DEFAULT:!MEDIUM$}). with_content(%r{^tls-ciphersuites\s*TLS_CHACHA20_POLY1305_SHA256$}). with_content(%r{^tls-protocols\s*"TLSv1\.2\sTLSv1\.3"$}). with_content(%r{^tls-prefer-server-ciphers\s*yes$}) end end describe 'with parameter manage_service_file' do let(:params) do { manage_service_file: true } end it { is_expected.to contain_systemd__unit_file("#{service_name}.service") } it do content = <<-END.gsub(%r{^\s+\|}, '') |[Unit] |Description=Redis Advanced key-value store for instance default |After=network.target |After=network-online.target |Wants=network-online.target | |[Service] - |RuntimeDirectory=redis + |RuntimeDirectory=#{service_name} |RuntimeDirectoryMode=2755 |Type=notify |ExecStart=/usr/bin/redis-server #{config_file} --supervised systemd |ExecStop=/usr/bin/redis-cli -p 6379 shutdown |Restart=always |User=redis |Group=redis |LimitNOFILE=65536 | |[Install] |WantedBy=multi-user.target END is_expected.to contain_systemd__unit_file("#{service_name}.service").with_content(content) end end describe 'with parameter manage_service_file set to false' do let(:params) do { manage_service_file: false } end it { is_expected.not_to contain_systemd__unit_file("#{service_name}.service") } end end end end diff --git a/spec/defines/instance_spec.rb b/spec/defines/instance_spec.rb index f32e268..d171f40 100644 --- a/spec/defines/instance_spec.rb +++ b/spec/defines/instance_spec.rb @@ -1,49 +1,49 @@ require 'spec_helper' describe 'redis::instance' do let :pre_condition do <<-PUPPET class { 'redis': default_install => false, } PUPPET end on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) { facts } context 'with app2 title' do let(:title) { 'app2' } let(:config_file) do case facts[:osfamily] when 'RedHat' '/etc/redis-server-app2.conf' when 'FreeBSD' '/usr/local/etc/redis/redis-server-app2.conf' when 'Debian' '/etc/redis/redis-server-app2.conf' when 'Archlinux' '/etc/redis/redis-server-app2.conf' end end it do is_expected.to contain_file("#{config_file}.puppet"). with_content(%r{^bind 127.0.0.1}). with_content(%r{^logfile /var/log/redis/redis-server-app2\.log}). with_content(%r{^dir /var/lib/redis/redis-server-app2}). - with_content(%r{^unixsocket /var/run/redis/redis-server-app2\.sock}) + with_content(%r{^unixsocket /var/run/redis-server-app2/redis\.sock}) end it { is_expected.to contain_file('/var/lib/redis/redis-server-app2') } it do is_expected.to contain_file('/etc/systemd/system/redis-server-app2.service'). with_content(%r{ExecStart=/usr/bin/redis-server #{config_file}}) end it { is_expected.to contain_service('redis-server-app2.service').with_ensure(true).with_enable(true) } end end end end diff --git a/templates/service_templates/redis.service.epp b/templates/service_templates/redis.service.epp new file mode 100644 index 0000000..69739ed --- /dev/null +++ b/templates/service_templates/redis.service.epp @@ -0,0 +1,29 @@ +<%- | + Boolean $ulimit_managed, + Integer[0] $ulimit, + Stdlib::Absolutepath $bin_path, + Stdlib::Absolutepath $redis_file_name, + Stdlib::Port $port, + String[1] $instance_title, + String[1] $service_name, + String[1] $service_user, +| -%> +[Unit] +Description=Redis Advanced key-value store for instance <%= $instance_title %> +After=network.target +After=network-online.target +Wants=network-online.target + +[Service] +RuntimeDirectory=<%= $service_name %> +RuntimeDirectoryMode=2755 +Type=notify +ExecStart=<%= $bin_path %>/redis-server <%= $redis_file_name %> --supervised systemd +ExecStop=<%= $bin_path %>/redis-cli -p <%= $port %> shutdown +Restart=always +User=<%= $service_user %> +Group=<%= $service_user %> +<%if $ulimit_managed { %>LimitNOFILE=<%= $ulimit %><% } %> + +[Install] +WantedBy=multi-user.target diff --git a/templates/service_templates/redis.service.erb b/templates/service_templates/redis.service.erb deleted file mode 100644 index 74cf66a..0000000 --- a/templates/service_templates/redis.service.erb +++ /dev/null @@ -1,21 +0,0 @@ -[Unit] -Description=Redis Advanced key-value store for instance <%= @title %> -After=network.target -After=network-online.target -Wants=network-online.target - -[Service] -RuntimeDirectory=redis -RuntimeDirectoryMode=2755 -Type=notify -ExecStart=<%= scope['redis::bin_path'] %>/redis-server <%= @redis_file_name %> --supervised systemd -ExecStop=<%= scope['redis::bin_path'] %>/redis-cli -p <%= @port %> shutdown -Restart=always -User=<%= @service_user %> -Group=<%= @service_user %> -<%if @ulimit_managed -%> -LimitNOFILE=<%= @ulimit %> -<% end -%> - -[Install] -WantedBy=multi-user.target