diff --git a/REFERENCE.md b/REFERENCE.md index 9b3f8f2..9813e98 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -1,2071 +1,2047 @@ # Reference ## Table of Contents ### Classes #### Public Classes * [`redis`](#redis): This class installs redis * [`redis::administration`](#redisadministration): Allows various adminstrative settings for Redis As documented in the FAQ and https://redis.io/topics/admin * [`redis::globals`](#redisglobals): Set a global config for Redis * [`redis::sentinel`](#redissentinel): Install redis-sentinel #### Private Classes * `redis::config`: This class provides configuration for Redis. * `redis::install`: This class installs the application. * `redis::params`: This class provides a number of parameters. * `redis::preinstall`: Provides anything required by the install class, such as package repositories. * `redis::service`: This class manages the Redis daemon. * `redis::ulimit`: Redis class for configuring ulimit Used to DRY up the config class, and move the logic for ulimit changes all into one place. Parameters are ### Defined types * [`redis::instance`](#redisinstance): Allows the configuration of multiple redis configurations on one machine ### Functions * [`redis::get`](#redisget): ``` ### Data types * [`Redis::LogLevel`](#redisloglevel): Specify the server verbosity level. * [`Redis::RedisUrl`](#redisredisurl) ### Tasks * [`redis_cli`](#redis_cli): Executes a redis-cli command on the target system ## Classes ### `redis` This class installs redis #### Examples ##### Default install ```puppet include redis ``` ##### Slave Node ```puppet class { '::redis': bind => '10.0.1.2', slaveof => '10.0.1.1 6379', } ``` ##### Binding on multiple interfaces ```puppet class { 'redis': bind => ['127.0.0.1', '10.0.0.1', '10.1.0.1'], } ``` ##### Binding on all interfaces ```puppet class { 'redis': bind => [], } ``` #### Parameters The following parameters are available in the `redis` class. ##### `activerehashing` Data type: `Boolean` Enable/disable active rehashing. Default value: ``true`` ##### `aof_load_truncated` Data type: `Boolean` Enable/disable loading truncated AOF file Default value: ``true`` ##### `aof_rewrite_incremental_fsync` Data type: `Boolean` Enable/disable fsync for AOF file Default value: ``true`` ##### `appendfilename` Data type: `String[1]` The name of the append only file Default value: `'appendonly.aof'` ##### `appendfsync` Data type: `Enum['no', 'always', 'everysec']` Adjust fsync mode Default value: `'everysec'` ##### `appendonly` Data type: `Boolean` Enable/disable appendonly mode. Default value: ``false`` ##### `auto_aof_rewrite_min_size` Data type: `String[1]` Adjust minimum size for auto-aof-rewrite. Default value: `'64mb'` ##### `auto_aof_rewrite_percentage` Data type: `Integer[0]` Adjust percentatge for auto-aof-rewrite. Default value: `100` ##### `bind` Data type: `Variant[Stdlib::IP::Address, Array[Stdlib::IP::Address]]` Configure which IP address(es) to listen on. To bind on all interfaces, use an empty array. Default value: `['127.0.0.1']` ##### `config_dir` Data type: `Stdlib::Absolutepath` Directory containing the configuration files. Default value: `$redis::params::config_dir` ##### `config_dir_mode` Data type: `Stdlib::Filemode` Adjust mode for directory containing configuration files. Default value: `$redis::params::config_dir_mode` ##### `config_file_orig` Data type: `Stdlib::Absolutepath` The location and name of a config file that provides the source Default value: `$redis::params::config_file_orig` ##### `config_file` Data type: `Stdlib::Absolutepath` Adjust main configuration file. Default value: `$redis::params::config_file` ##### `config_file_mode` Data type: `Stdlib::Filemode` Adjust permissions for configuration files. Default value: `'0644'` ##### `config_group` Data type: `String[1]` Adjust filesystem group for config files. Default value: `$redis::params::config_group` ##### `config_owner` Data type: `String[1]` Adjust filesystem owner for config files. Default value: `$redis::params::config_owner` ##### `conf_template` Data type: `String[1]` Define which template to use. Default value: `'redis/redis.conf.erb'` ##### `daemonize` Data type: `Boolean` Have Redis run as a daemon. Default value: `$redis::params::daemonize` ##### `default_install` Data type: `Boolean` Configure a default install of redis. Default value: ``true`` ##### `databases` Data type: `Integer[1]` Set the number of databases. Default value: `16` ##### `dbfilename` Data type: `Variant[String[1], Boolean]` The filename where to dump the DB Default value: `'dump.rdb'` ##### `extra_config_file` Data type: `Optional[String]` Optional extra config file to include Default value: ``undef`` ##### `hash_max_ziplist_entries` Data type: `Integer[0]` Set max ziplist entries for hashes. Default value: `512` ##### `hash_max_ziplist_value` Data type: `Integer[0]` Set max ziplist values for hashes. Default value: `64` ##### `hll_sparse_max_bytes` Data type: `Integer[0]` HyperLogLog sparse representation bytes limit Default value: `3000` ##### `hz` Data type: `Integer[1, 500]` Set redis background tasks frequency Default value: `10` ##### `latency_monitor_threshold` Data type: `Integer[0]` Latency monitoring threshold in milliseconds Default value: `0` ##### `list_max_ziplist_entries` Data type: `Integer[0]` Set max ziplist entries for lists. Default value: `512` ##### `list_max_ziplist_value` Data type: `Integer[0]` Set max ziplist values for lists. Default value: `64` ##### `log_dir` Data type: `Stdlib::Absolutepath` Specify directory where to write log entries. Default value: `'/var/log/redis'` ##### `log_dir_mode` Data type: `Stdlib::Filemode` Adjust mode for directory containing log files. Default value: `$redis::params::log_dir_mode` ##### `log_file` Data type: `Stdlib::Absolutepath` Specify file where to write log entries. Default value: `'/var/log/redis/redis.log'` ##### `log_level` Data type: `Redis::LogLevel` Specify the server verbosity level. Default value: `'notice'` ##### `manage_repo` Data type: `Boolean` Enable/disable upstream repository configuration. Default value: ``false`` ##### `manage_package` Data type: `Boolean` Enable/disable management of package Default value: ``true`` ##### `managed_by_cluster_manager` Data type: `Boolean` Choose if redis will be managed by a cluster manager such as pacemaker or rgmanager Default value: ``false`` ##### `masterauth` Data type: `Optional[String[1]]` If the master is password protected (using the "requirepass" configuration Default value: ``undef`` ##### `maxclients` Data type: `Integer[1]` Set the max number of connected clients at the same time. Default value: `10000` ##### `maxmemory` Data type: `Any` Don't use more memory than the specified amount of bytes. Default value: ``undef`` ##### `maxmemory_policy` Data type: `Any` How Redis will select what to remove when maxmemory is reached. Default value: ``undef`` ##### `maxmemory_samples` Data type: `Any` Select as well the sample size to check. Default value: ``undef`` ##### `min_slaves_max_lag` Data type: `Integer[0]` The lag in seconds Default value: `10` ##### `min_slaves_to_write` Data type: `Integer[0]` Minimum number of slaves to be in "online" state Default value: `0` ##### `no_appendfsync_on_rewrite` Data type: `Boolean` If you have latency problems turn this to 'true'. Otherwise leave it as Default value: ``false`` ##### `notify_keyspace_events` Data type: `Optional[String[1]]` Which events to notify Pub/Sub clients about events happening Default value: ``undef`` ##### `notify_service` Data type: `Boolean` You may disable service reloads when config files change if you Default value: ``true`` ##### `package_ensure` Data type: `String[1]` Default action for package. Default value: `'present'` ##### `package_name` Data type: `String[1]` Upstream package name. Default value: `$redis::params::package_name` ##### `pid_file` Data type: `Stdlib::Absolutepath` Where to store the pid. Default value: `$redis::params::pid_file` ##### `port` Data type: `Stdlib::Port` Configure which port to listen on. Default value: `6379` ##### `protected_mode` Data type: `Boolean` Whether protected mode is enabled or not. Only applicable when no bind is set. Default value: ``true`` ##### `ppa_repo` Data type: `Optional[String]` Specify upstream (Ubuntu) PPA entry. Default value: `$redis::params::ppa_repo` ##### `rdbcompression` Data type: `Boolean` Enable/disable compression of string objects using LZF when dumping. Default value: ``true`` ##### `repl_backlog_size` Data type: `String[1]` The replication backlog size Default value: `'1mb'` ##### `repl_backlog_ttl` Data type: `Integer[0]` The number of seconds to elapse before freeing backlog buffer Default value: `3600` ##### `repl_disable_tcp_nodelay` Data type: `Boolean` Enable/disable TCP_NODELAY on the slave socket after SYNC Default value: ``false`` ##### `repl_ping_slave_period` Data type: `Integer[1]` Slaves send PINGs to server in a predefined interval. It's possible Default value: `10` ##### `repl_timeout` Data type: `Integer[1]` Set the replication timeout for: Default value: `60` ##### `requirepass` Data type: `Optional[String]` Require clients to issue AUTH before processing any other commands. Default value: ``undef`` ##### `save_db_to_disk` Data type: `Boolean` Set if save db to disk. Default value: ``true`` ##### `save_db_to_disk_interval` Data type: `Hash` save the dataset every N seconds if there are at least M changes in the dataset Default value: `{ '900' => '1', '300' => '10', '60' => '10000' }` ##### `service_manage` Data type: `Boolean` Specify if the service should be part of the catalog. Default value: ``true`` ##### `service_enable` Data type: `Boolean` Enable/disable daemon at boot. Default value: ``true`` ##### `service_ensure` Data type: `Stdlib::Ensure::Service` Specify if the server should be running. Default value: `'running'` ##### `service_group` Data type: `String[1]` Specify which group to run as. Default value: `'redis'` ##### `service_hasrestart` Data type: `Boolean` Does the init script support restart? Default value: ``true`` ##### `service_hasstatus` Data type: `Boolean` Does the init script support status? Default value: ``true`` ##### `service_name` Data type: `String[1]` Specify the service name for Init or Systemd. Default value: `$redis::params::service_name` -##### `service_provider` - -Data type: `Optional[String]` - -Specify the service provider to use - -Default value: ``undef`` - ##### `service_user` Data type: `String[1]` Specify which user to run as. Default value: `'redis'` ##### `set_max_intset_entries` Data type: `Integer[0]` The following configuration setting sets the limit in the size of the set in order to use this special memory saving encoding. Default value: `512` ##### `slave_priority` Data type: `Integer[0]` The priority number for slave promotion by Sentinel Default value: `100` ##### `slave_read_only` Data type: `Boolean` You can configure a slave instance to accept writes or not. Default value: ``true`` ##### `slave_serve_stale_data` Data type: `Boolean` 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. Default value: ``true`` ##### `slaveof` Data type: `Optional[String[1]]` Use slaveof to make a Redis instance a copy of another Redis server. Default value: ``undef`` ##### `slowlog_log_slower_than` Data type: `Integer[0]` Tells Redis what is the execution time, in microseconds, to exceed in order for the command to get logged. Default value: `10000` ##### `slowlog_max_len` Data type: `Integer[0]` Tells Redis what is the length to exceed in order for the command to get logged. Default value: `1024` ##### `stop_writes_on_bgsave_error` Data type: `Boolean` If false then Redis will continue to work as usual even if there are problems with disk, permissions, and so forth. Default value: ``true`` ##### `syslog_enabled` Data type: `Boolean` Enable/disable logging to the system logger. Default value: ``false`` ##### `syslog_facility` Data type: `Optional[String[1]]` Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7. Default value: ``undef`` ##### `tcp_backlog` Data type: `Integer[0]` Sets the TCP backlog Default value: `511` ##### `tcp_keepalive` Data type: `Integer[0]` TCP keepalive. Default value: `0` ##### `timeout` Data type: `Integer[0]` Close the connection after a client is idle for N seconds (0 to disable). Default value: `0` ##### `ulimit` Data type: `Integer[0]` Limit the use of system-wide resources. Default value: `65536` ##### `unixsocket` Data type: `Variant[Stdlib::Absolutepath, Enum['']]` Define unix socket path Default value: `'/var/run/redis/redis.sock'` ##### `unixsocketperm` Data type: `Variant[Stdlib::Filemode, Enum['']]` Define unix socket file permissions Default value: `'0755'` ##### `workdir` Data type: `Stdlib::Absolutepath` The DB will be written inside this directory, with the filename specified above using the 'dbfilename' configuration directive. Default value: `$redis::params::workdir` ##### `workdir_mode` Data type: `Stdlib::Filemode` Adjust mode for data directory. Default value: `'0750'` ##### `zset_max_ziplist_entries` Data type: `Integer[0]` Set max entries for sorted sets. Default value: `128` ##### `zset_max_ziplist_value` Data type: `Integer[0]` Set max values for sorted sets. Default value: `64` ##### `cluster_enabled` Data type: `Boolean` Enables redis 3.0 cluster functionality Default value: ``false`` ##### `cluster_config_file` Data type: `String[1]` Config file for saving cluster nodes configuration. This file is never touched by humans. Only set if cluster_enabled is true Default value: `'nodes.conf'` ##### `cluster_node_timeout` Data type: `Integer[1]` Node timeout. Only set if cluster_enabled is true Default value: `5000` ##### `cluster_slave_validity_factor` Data type: `Integer[0]` Control variable to disable promoting slave in case of disconnection from master Only set if cluster_enabled is true Default value: `0` ##### `cluster_require_full_coverage` Data type: `Boolean` 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 Default value: ``true`` ##### `cluster_migration_barrier` Data type: `Integer[0]` 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 Default value: `1` ##### `instances` Data type: `Hash[String[1], Hash]` Iterate through multiple instance configurations Default value: `{}` ##### `output_buffer_limit_slave` Data type: `String[1]` Default value: `'256mb 64mb 60'` ##### `output_buffer_limit_pubsub` Data type: `String[1]` Default value: `'32mb 8mb 60'` ##### `manage_service_file` Data type: `Boolean` Default value: ``false`` +##### `minimum_version` + +Data type: `String[1]` + + + +Default value: `$redis::params::minimum_version` + ### `redis::administration` Allows various adminstrative settings for Redis As documented in the FAQ and https://redis.io/topics/admin * **See also** * https://redis.io/topics/admin #### Examples ##### ```puppet include redis::administration ``` ##### ```puppet class {'redis::administration': disable_thp => false, } ``` #### Parameters The following parameters are available in the `redis::administration` class. ##### `enable_overcommit_memory` Data type: `Boolean` Enable the overcommit memory setting Default value: ``true`` ##### `disable_thp` Data type: `Boolean` Disable Transparent Huge Pages Default value: ``true`` ##### `somaxconn` Data type: `Integer[0]` Set somaxconn value Default value: `65535` ### `redis::globals` Set a global config for Redis #### Parameters The following parameters are available in the `redis::globals` class. ##### `scl` Data type: `Optional[String]` Use a specific Software CoLlection on Red Hat based systems Default value: ``undef`` ### `redis::sentinel` Install redis-sentinel #### Examples ##### Basic inclusion ```puppet include redis::sentinel ``` ##### Configuring options ```puppet class {'redis::sentinel': down_after => 80000, log_file => '/var/log/redis/sentinel.log', } ``` #### Parameters The following parameters are available in the `redis::sentinel` class. ##### `auth_pass` Data type: `Optional[String[1]]` The password to use to authenticate with the master and slaves. Default value: ``undef`` ##### `config_file` Data type: `Stdlib::Absolutepath` The location and name of the sentinel config file. Default value: `$redis::params::sentinel_config_file` ##### `config_file_orig` Data type: `Stdlib::Absolutepath` The location and name of a config file that provides the source of the sentinel config file. Two different files are needed because sentinel itself writes to its own config file and we do not want override that when puppet is run unless there are changes from the manifests. Default value: `$redis::params::sentinel_config_file_orig` ##### `config_file_mode` Data type: `Stdlib::Filemode` Permissions of config file. Default value: `'0644'` ##### `conf_template` Data type: `String[1]` Define which template to use. Default value: `'redis/redis-sentinel.conf.erb'` ##### `daemonize` Data type: `Boolean` Have Redis sentinel run as a daemon. Default value: `$redis::params::sentinel_daemonize` ##### `down_after` Data type: `Integer[1]` Number of milliseconds the master (or any attached slave or sentinel) should be unreachable (as in, not acceptable reply to PING, continuously, for the specified period) in order to consider it in S_DOWN state. Default value: `30000` ##### `failover_timeout` Data type: `Integer[1]` Specify the failover timeout in milliseconds. Default value: `180000` -##### `init_script` - -Data type: `Optional[Stdlib::Absolutepath]` - -Specifiy the init script that will be created for sentinel. - -Default value: `$redis::params::sentinel_init_script` - ##### `log_file` Data type: `Stdlib::Absolutepath` Specify where to write log entries. Default value: `$redis::params::sentinel_log_file` ##### `log_level` Data type: `Redis::LogLevel` Specify how much we should log. Default value: `'notice'` ##### `master_name` Data type: `String[1]` Specify the name of the master redis server. The valid charset is A-z 0-9 and the three characters ".-_". Default value: `'mymaster'` ##### `redis_host` Data type: `Stdlib::Host` Specify the bound host of the master redis server. Default value: `'127.0.0.1'` ##### `redis_port` Data type: `Stdlib::Port` Specify the port of the master redis server. Default value: `6379` +##### `protected_mode` + +Data type: `Boolean` + +Whether protected mode is enabled or not. Only applicable when no bind is set. + +Default value: `$redis::params::sentinel_protected_mode` + ##### `package_name` Data type: `String[1]` The name of the package that installs sentinel. Default value: `$redis::params::sentinel_package_name` ##### `package_ensure` Data type: `String[1]` Do we ensure this package. Default value: `'present'` ##### `parallel_sync` Data type: `Integer[0]` How many slaves can be reconfigured at the same time to use a new master after a failover. Default value: `1` ##### `pid_file` Data type: `Stdlib::Absolutepath` If sentinel is daemonized it will write its pid at this location. Default value: `$redis::params::sentinel_pid_file` ##### `quorum` Data type: `Integer[1]` Number of sentinels that must agree that a master is down to signal sdown state. Default value: `2` ##### `sentinel_bind` Data type: `Variant[Undef, Stdlib::IP::Address, Array[Stdlib::IP::Address]]` Allow optional sentinel server ip binding. Can help overcome issues arising from protect-mode added Redis 3.2 Default value: ``undef`` ##### `sentinel_port` Data type: `Stdlib::Port` The port of sentinel server. Default value: `26379` ##### `service_group` Data type: `String[1]` The group of the config file. Default value: `'redis'` ##### `service_name` Data type: `String[1]` The name of the service (for puppet to manage). Default value: `$redis::params::sentinel_service_name` ##### `service_user` Data type: `String[1]` The owner of the config file. Default value: `'redis'` ##### `service_enable` Data type: `Boolean` Enable the service at boot time. Default value: ``true`` ##### `working_dir` Data type: `Stdlib::Absolutepath` The directory into which sentinel will change to avoid mount conflicts. Default value: `$redis::params::sentinel_working_dir` ##### `notification_script` Data type: `Optional[Stdlib::Absolutepath]` Path to the notification script Default value: ``undef`` ##### `client_reconfig_script` Data type: `Optional[Stdlib::Absolutepath]` Path to the client-reconfig script Default value: ``undef`` -##### `init_template` - -Data type: `String[1]` - - - -Default value: `'redis/redis-sentinel.init.erb'` - ##### `service_ensure` Data type: `Stdlib::Ensure::Service` Default value: `'running'` ## Defined types ### `redis::instance` This is an defined type to allow the configuration of multiple redis instances on one machine without conflicts #### Examples ##### ```puppet redis::instance {'6380': port => 6380, } ``` #### Parameters The following parameters are available in the `redis::instance` defined type. ##### `activerehashing` Data type: `Boolean` Enable/disable active rehashing. Default value: `$redis::activerehashing` ##### `aof_load_truncated` Data type: `Boolean` Enable/disable loading truncated AOF file Default value: `$redis::aof_load_truncated` ##### `aof_rewrite_incremental_fsync` Data type: `Boolean` Enable/disable fsync for AOF file Default value: `$redis::aof_rewrite_incremental_fsync` ##### `appendfilename` Data type: `String[1]` The name of the append only file Default value: `$redis::appendfilename` ##### `appendfsync` Data type: `Enum['no', 'always', 'everysec']` Adjust fsync mode. Valid options: always, everysec, no. Default value: `$redis::appendfsync` ##### `appendonly` Data type: `Boolean` Enable/disable appendonly mode. Default value: `$redis::appendonly` ##### `auto_aof_rewrite_min_size` Data type: `String[1]` Adjust minimum size for auto-aof-rewrite. Default value: `$redis::auto_aof_rewrite_min_size` ##### `auto_aof_rewrite_percentage` Data type: `Integer[0]` Adjust percentatge for auto-aof-rewrite. Default value: `$redis::auto_aof_rewrite_percentage` ##### `bind` Data type: `Variant[Stdlib::IP::Address, Array[Stdlib::IP::Address]]` Configure which IP address(es) to listen on. To bind on all interfaces, use an empty array. Default value: `$redis::bind` ##### `config_file_orig` Data type: `Stdlib::Absolutepath` The location and name of a config file that provides the source Default value: `$redis::config_file_orig` ##### `config_file` Data type: `Stdlib::Absolutepath` Adjust main configuration file. Default value: `$redis::config_file` ##### `config_file_mode` Data type: `Stdlib::Filemode` Adjust permissions for configuration files. Default value: `$redis::config_file_mode` ##### `config_group` Data type: `String[1]` Adjust filesystem group for config files. Default value: `$redis::config_group` ##### `config_owner` Data type: `String[1]` Adjust filesystem owner for config files. Default value: `$redis::config_owner` ##### `conf_template` Data type: `String[1]` Define which template to use. Default value: `$redis::conf_template` ##### `daemonize` Data type: `Boolean` Have Redis run as a daemon. Default value: ``true`` ##### `databases` Data type: `Integer[1]` Set the number of databases. Default value: `$redis::databases` ##### `dbfilename` Data type: `Variant[String[1], Boolean]` The filename where to dump the DB Default value: `$redis::dbfilename` ##### `extra_config_file` Data type: `Optional[String]` Optional extra config file to include Default value: `$redis::extra_config_file` ##### `hash_max_ziplist_entries` Data type: `Integer[0]` Set max ziplist entries for hashes. Default value: `$redis::hash_max_ziplist_entries` ##### `hash_max_ziplist_value` Data type: `Integer[0]` Set max ziplist values for hashes. Default value: `$redis::hash_max_ziplist_value` ##### `hll_sparse_max_bytes` Data type: `Integer[0]` HyperLogLog sparse representation bytes limit Default value: `$redis::hll_sparse_max_bytes` ##### `hz` Data type: `Integer[1, 500]` Set redis background tasks frequency Default value: `$redis::hz` ##### `latency_monitor_threshold` Data type: `Integer[0]` Latency monitoring threshold in milliseconds Default value: `$redis::latency_monitor_threshold` ##### `list_max_ziplist_entries` Data type: `Integer[0]` Set max ziplist entries for lists. Default value: `$redis::list_max_ziplist_entries` ##### `list_max_ziplist_value` Data type: `Integer[0]` Set max ziplist values for lists. Default value: `$redis::list_max_ziplist_value` ##### `log_dir` Data type: `Stdlib::Absolutepath` Specify directory where to write log entries. Default value: `$redis::log_dir` ##### `log_dir_mode` Data type: `Stdlib::Filemode` Adjust mode for directory containing log files. Default value: `$redis::log_dir_mode` ##### `log_file` Data type: `Optional[Stdlib::Absolutepath]` Specify file where to write log entries. Default value: ``undef`` ##### `log_level` Data type: `Redis::LogLevel` Specify the server verbosity level. Default value: `$redis::log_level` ##### `masterauth` Data type: `Optional[String[1]]` If the master is password protected (using the "requirepass" configuration Default value: `$redis::masterauth` ##### `maxclients` Data type: `Integer[1]` Set the max number of connected clients at the same time. Default value: `$redis::maxclients` ##### `maxmemory` Data type: `Any` Don't use more memory than the specified amount of bytes. Default value: `$redis::maxmemory` ##### `maxmemory_policy` Data type: `Any` How Redis will select what to remove when maxmemory is reached. Default value: `$redis::maxmemory_policy` ##### `maxmemory_samples` Data type: `Any` Select as well the sample size to check. Default value: `$redis::maxmemory_samples` ##### `min_slaves_max_lag` Data type: `Integer[0]` The lag in seconds Default value: `$redis::min_slaves_max_lag` ##### `min_slaves_to_write` Data type: `Integer[0]` Minimum number of slaves to be in "online" state Default value: `$redis::min_slaves_to_write` ##### `no_appendfsync_on_rewrite` Data type: `Boolean` If you have latency problems turn this to 'true'. Otherwise leave it as Default value: `$redis::no_appendfsync_on_rewrite` ##### `notify_keyspace_events` Data type: `Optional[String[1]]` Which events to notify Pub/Sub clients about events happening Default value: `$redis::notify_keyspace_events` ##### `pid_file` Data type: `Stdlib::Absolutepath` Where to store the pid. Default value: `"/var/run/redis/redis-server-${name}.pid"` ##### `port` Data type: `Stdlib::Port` Configure which port to listen on. Default value: `$redis::port` ##### `protected_mode` Data type: `Boolean` Whether protected mode is enabled or not. Only applicable when no bind is set. Default value: `$redis::protected_mode` ##### `rdbcompression` Data type: `Boolean` Enable/disable compression of string objects using LZF when dumping. Default value: `$redis::rdbcompression` ##### `repl_backlog_size` Data type: `String[1]` The replication backlog size Default value: `$redis::repl_backlog_size` ##### `repl_backlog_ttl` Data type: `Integer[0]` The number of seconds to elapse before freeing backlog buffer Default value: `$redis::repl_backlog_ttl` ##### `repl_disable_tcp_nodelay` Data type: `Boolean` Enable/disable TCP_NODELAY on the slave socket after SYNC Default value: `$redis::repl_disable_tcp_nodelay` ##### `repl_ping_slave_period` Data type: `Integer[1]` Slaves send PINGs to server in a predefined interval. It's possible Default value: `$redis::repl_ping_slave_period` ##### `repl_timeout` Data type: `Integer[1]` Set the replication timeout for: Default value: `$redis::repl_timeout` ##### `requirepass` Data type: `Optional[String]` Require clients to issue AUTH before processing any other commands. Default value: `$redis::requirepass` ##### `save_db_to_disk` Data type: `Boolean` Set if save db to disk. Default value: `$redis::save_db_to_disk` ##### `save_db_to_disk_interval` Data type: `Hash` save the dataset every N seconds if there are at least M changes in the dataset Default value: `$redis::save_db_to_disk_interval` ##### `service_name` Data type: `String[1]` The service name for this instance Default value: `"redis-server-${name}"` ##### `service_enable` Data type: `Boolean` Enable/disable daemon at boot. Default value: `$redis::service_enable` ##### `service_ensure` Data type: `Stdlib::Ensure::Service` Specify if the server should be running. Default value: `$redis::service_ensure` ##### `service_group` Data type: `String[1]` Specify which group to run as. Default value: `$redis::service_group` ##### `service_hasrestart` Data type: `Boolean` Does the init script support restart? Default value: `$redis::service_hasrestart` ##### `service_hasstatus` Data type: `Boolean` Does the init script support status? Default value: `$redis::service_hasstatus` ##### `service_user` Data type: `String[1]` Specify which user to run as. Default value: `$redis::service_user` ##### `set_max_intset_entries` Data type: `Integer[0]` The following configuration setting sets the limit in the size of the set in order to use this special memory saving encoding. Default value: `$redis::set_max_intset_entries` ##### `slave_priority` Data type: `Integer[0]` The priority number for slave promotion by Sentinel Default value: `$redis::slave_priority` ##### `slave_read_only` Data type: `Boolean` You can configure a slave instance to accept writes or not. Default value: `$redis::slave_read_only` ##### `slave_serve_stale_data` Data type: `Boolean` 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. Default value: `$redis::slave_serve_stale_data` ##### `slaveof` Data type: `Optional[String[1]]` Use slaveof to make a Redis instance a copy of another Redis server. Default value: `$redis::slaveof` ##### `slowlog_log_slower_than` Data type: `Integer[0]` Tells Redis what is the execution time, in microseconds, to exceed in order for the command to get logged. Default value: `$redis::slowlog_log_slower_than` ##### `slowlog_max_len` Data type: `Integer[0]` Tells Redis what is the length to exceed in order for the command to get logged. Default value: `$redis::slowlog_max_len` ##### `stop_writes_on_bgsave_error` Data type: `Boolean` If false then Redis will continue to work as usual even if there are problems with disk, permissions, and so forth. Default value: `$redis::stop_writes_on_bgsave_error` ##### `syslog_enabled` Data type: `Boolean` Enable/disable logging to the system logger. Default value: `$redis::syslog_enabled` ##### `syslog_facility` Data type: `Optional[String[1]]` Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7. Default value: `$redis::syslog_facility` ##### `tcp_backlog` Data type: `Integer[0]` Sets the TCP backlog Default value: `$redis::tcp_backlog` ##### `tcp_keepalive` Data type: `Integer[0]` TCP keepalive. Default value: `$redis::tcp_keepalive` ##### `timeout` Data type: `Integer[0]` Close the connection after a client is idle for N seconds (0 to disable). Default value: `$redis::timeout` ##### `ulimit` Data type: `Integer[0]` Limit the use of system-wide resources. Default value: `$redis::ulimit` ##### `unixsocket` Data type: `Variant[Stdlib::Absolutepath, Enum['']]` Define unix socket path Default value: `"/var/run/redis/redis-server-${name}.sock"` ##### `unixsocketperm` Data type: `Variant[Stdlib::Filemode , Enum['']]` Define unix socket file permissions Default value: `$redis::unixsocketperm` ##### `workdir` Data type: `Stdlib::Absolutepath` The DB will be written inside this directory, with the filename specified above using the 'dbfilename' configuration directive. Default value: `"${redis::workdir}/redis-server-${name}"` ##### `workdir_mode` Data type: `Stdlib::Filemode` Adjust mode for data directory. Default value: `$redis::workdir_mode` ##### `zset_max_ziplist_entries` Data type: `Integer[0]` Set max entries for sorted sets. Default value: `$redis::zset_max_ziplist_entries` ##### `zset_max_ziplist_value` Data type: `Integer[0]` Set max values for sorted sets. Default value: `$redis::zset_max_ziplist_value` ##### `cluster_enabled` Data type: `Boolean` Enables redis 3.0 cluster functionality Default value: `$redis::cluster_enabled` ##### `cluster_config_file` Data type: `String[1]` Config file for saving cluster nodes configuration. This file is never touched by humans. Only set if cluster_enabled is true Default value: `$redis::cluster_config_file` ##### `cluster_node_timeout` Data type: `Integer[1]` Node timeout. Only set if cluster_enabled is true Default value: `$redis::cluster_node_timeout` ##### `cluster_slave_validity_factor` Data type: `Integer[0]` Control variable to disable promoting slave in case of disconnection from master Only set if cluster_enabled is true Default value: `$redis::cluster_slave_validity_factor` ##### `cluster_require_full_coverage` Data type: `Boolean` 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 Default value: `$redis::cluster_require_full_coverage` ##### `cluster_migration_barrier` Data type: `Integer[0]` 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 Default value: `$redis::cluster_migration_barrier` ##### `output_buffer_limit_slave` Data type: `String[1]` Default value: `$redis::output_buffer_limit_slave` ##### `output_buffer_limit_pubsub` Data type: `String[1]` Default value: `$redis::output_buffer_limit_pubsub` -##### `minimum_version` - -Data type: `String[1]` - - - -Default value: `$redis::minimum_version` - ##### `managed_by_cluster_manager` Data type: `Boolean` Default value: `$redis::managed_by_cluster_manager` -##### `package_ensure` - -Data type: `String[1]` - - - -Default value: `$redis::package_ensure` - ##### `manage_service_file` Data type: `Boolean` Default value: ``true`` ## Functions ### `redis::get` Type: Ruby 4.x API ``` #### `redis::get(String[1] $key, Redis::RedisUrl $url, Optional[String] $default)` ``` Returns: `Optional[String]` Returns the value of the key from Redis ##### `key` Data type: `String[1]` The key to look up in redis ##### `url` Data type: `Redis::RedisUrl` The endpoint of the Redis instance ##### `default` Data type: `Optional[String]` The value to return if the key is not found or the connection to Redis fails ## Data types ### `Redis::LogLevel` This can be one of: * debug (a lot of information, useful for development/testing) * verbose (many rarely useful info, but not a mess like the debug level) * notice (moderately verbose, what you want in production probably) * warning (only very important / critical messages are logged) Alias of `Enum['debug', 'verbose', 'notice', 'warning']` ### `Redis::RedisUrl` The Redis::RedisUrl data type. Alias of `Pattern[/(^redis:\/\/)/]` ## Tasks ### `redis_cli` Executes a redis-cli command on the target system **Supports noop?** false #### Parameters ##### `command` Data type: `String[1]` The command to run, including all arguments diff --git a/manifests/config.pp b/manifests/config.pp index b609b2e..2f941c0 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -1,70 +1,59 @@ # @summary This class provides configuration for Redis. # @api private class redis::config { File { owner => $redis::config_owner, group => $redis::config_group, mode => $redis::config_file_mode, } file { $redis::config_dir: ensure => directory, mode => $redis::config_dir_mode, } file { $redis::log_dir: ensure => directory, group => $redis::service_group, mode => $redis::log_dir_mode, owner => $redis::service_user, } file { $redis::workdir: ensure => directory, group => $redis::service_group, mode => $redis::workdir_mode, owner => $redis::service_user, } if $redis::default_install { redis::instance { 'default': pid_file => $redis::pid_file, log_file => $redis::log_file, unixsocket => $redis::unixsocket, workdir => $redis::workdir, daemonize => $redis::daemonize, service_name => $redis::service_name, manage_service_file => $redis::manage_service_file, } } if $redis::ulimit { contain redis::ulimit } - $service_provider_lookup = fact('service_provider') - - unless $facts['os']['family'] == 'Debian' or $service_provider_lookup == 'systemd' { - file { '/var/run/redis': - ensure => 'directory', - owner => $redis::config_owner, - group => $redis::config_group, - mode => '0755', - } - } - # Adjust /etc/default/redis-server on Debian systems case $facts['os']['family'] { 'Debian': { file { '/etc/default/redis-server': ensure => file, group => $redis::config_group, mode => $redis::config_file_mode, owner => $redis::config_owner, } } default: { } } } diff --git a/manifests/init.pp b/manifests/init.pp index 1e77543..6d87848 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,368 +1,365 @@ # This class installs redis # # @example Default install # include redis # # @example Slave Node # class { '::redis': # bind => '10.0.1.2', # slaveof => '10.0.1.1 6379', # } # # @example Binding on multiple interfaces # class { 'redis': # bind => ['127.0.0.1', '10.0.0.1', '10.1.0.1'], # } # # @example Binding on all interfaces # class { 'redis': # bind => [], # } # # @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 # @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_dir # Directory containing the configuration files. # @param config_dir_mode # Adjust mode for directory containing configuration files. # @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 default_install # Configure a default install of redis. # @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. # @param log_level # Specify the server verbosity level. # @param manage_repo # Enable/disable upstream repository configuration. # @param manage_package # Enable/disable management of package # @param managed_by_cluster_manager # Choose if redis will be managed by a cluster manager such as pacemaker or rgmanager # @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 notify_service # You may disable service reloads when config files change if you # @param package_ensure # Default action for package. # @param package_name # Upstream package name. # @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 ppa_repo # Specify upstream (Ubuntu) PPA entry. # @param rdbcompression # Enable/disable compression of string objects using LZF when dumping. # @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_manage # Specify if the service should be part of the catalog. # @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_hasrestart # Does the init script support restart? # @param service_hasstatus # Does the init script support status? # @param service_name # Specify the service name for Init or Systemd. -# @param service_provider -# Specify the service provider to use # @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 ulimit # Limit the use of system-wide resources. # @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 # @param instances # Iterate through multiple instance configurations class redis ( Boolean $activerehashing = true, Boolean $aof_load_truncated = true, Boolean $aof_rewrite_incremental_fsync = true, String[1] $appendfilename = 'appendonly.aof', Enum['no', 'always', 'everysec'] $appendfsync = 'everysec', Boolean $appendonly = false, String[1] $auto_aof_rewrite_min_size = '64mb', Integer[0] $auto_aof_rewrite_percentage = 100, Variant[Stdlib::IP::Address, Array[Stdlib::IP::Address]] $bind = ['127.0.0.1'], String[1] $output_buffer_limit_slave = '256mb 64mb 60', String[1] $output_buffer_limit_pubsub = '32mb 8mb 60', String[1] $conf_template = 'redis/redis.conf.erb', Stdlib::Absolutepath $config_dir = $redis::params::config_dir, Stdlib::Filemode $config_dir_mode = $redis::params::config_dir_mode, Stdlib::Absolutepath $config_file = $redis::params::config_file, Stdlib::Filemode $config_file_mode = '0644', Stdlib::Absolutepath $config_file_orig = $redis::params::config_file_orig, String[1] $config_group = $redis::params::config_group, String[1] $config_owner = $redis::params::config_owner, Boolean $daemonize = $redis::params::daemonize, Integer[1] $databases = 16, Boolean $default_install = true, Variant[String[1], Boolean] $dbfilename = 'dump.rdb', Optional[String] $extra_config_file = undef, Integer[0] $hash_max_ziplist_entries = 512, Integer[0] $hash_max_ziplist_value = 64, Integer[0] $hll_sparse_max_bytes = 3000, Integer[1, 500] $hz = 10, Integer[0] $latency_monitor_threshold = 0, Integer[0] $list_max_ziplist_entries = 512, Integer[0] $list_max_ziplist_value = 64, Stdlib::Absolutepath $log_dir = '/var/log/redis', Stdlib::Filemode $log_dir_mode = $redis::params::log_dir_mode, Stdlib::Absolutepath $log_file = '/var/log/redis/redis.log', Redis::LogLevel $log_level = 'notice', Boolean $manage_service_file = false, Boolean $manage_package = true, Boolean $manage_repo = false, Optional[String[1]] $masterauth = undef, Integer[1] $maxclients = 10000, $maxmemory = undef, $maxmemory_policy = undef, $maxmemory_samples = undef, Integer[0] $min_slaves_max_lag = 10, Integer[0] $min_slaves_to_write = 0, Boolean $no_appendfsync_on_rewrite = false, Optional[String[1]] $notify_keyspace_events = undef, Boolean $notify_service = true, Boolean $managed_by_cluster_manager = false, String[1] $minimum_version = $redis::params::minimum_version, String[1] $package_ensure = 'present', String[1] $package_name = $redis::params::package_name, Stdlib::Absolutepath $pid_file = $redis::params::pid_file, Stdlib::Port $port = 6379, Boolean $protected_mode = true, Optional[String] $ppa_repo = $redis::params::ppa_repo, Boolean $rdbcompression = true, String[1] $repl_backlog_size = '1mb', Integer[0] $repl_backlog_ttl = 3600, Boolean $repl_disable_tcp_nodelay = false, Integer[1] $repl_ping_slave_period = 10, Integer[1] $repl_timeout = 60, Optional[String] $requirepass = undef, Boolean $save_db_to_disk = true, Hash $save_db_to_disk_interval = { '900' => '1', '300' => '10', '60' => '10000' }, Boolean $service_enable = true, Stdlib::Ensure::Service $service_ensure = 'running', String[1] $service_group = 'redis', Boolean $service_hasrestart = true, Boolean $service_hasstatus = true, Boolean $service_manage = true, String[1] $service_name = $redis::params::service_name, - Optional[String] $service_provider = undef, String[1] $service_user = 'redis', Integer[0] $set_max_intset_entries = 512, Integer[0] $slave_priority = 100, Boolean $slave_read_only = true, Boolean $slave_serve_stale_data = true, Optional[String[1]] $slaveof = undef, Integer[0] $slowlog_log_slower_than = 10000, Integer[0] $slowlog_max_len = 1024, Boolean $stop_writes_on_bgsave_error = true, Boolean $syslog_enabled = false, Optional[String[1]] $syslog_facility = undef, Integer[0] $tcp_backlog = 511, Integer[0] $tcp_keepalive = 0, Integer[0] $timeout = 0, Variant[Stdlib::Absolutepath, Enum['']] $unixsocket = '/var/run/redis/redis.sock', Variant[Stdlib::Filemode, Enum['']] $unixsocketperm = '0755', Integer[0] $ulimit = 65536, Stdlib::Absolutepath $workdir = $redis::params::workdir, Stdlib::Filemode $workdir_mode = '0750', Integer[0] $zset_max_ziplist_entries = 128, Integer[0] $zset_max_ziplist_value = 64, Boolean $cluster_enabled = false, String[1] $cluster_config_file = 'nodes.conf', Integer[1] $cluster_node_timeout = 5000, Integer[0] $cluster_slave_validity_factor = 0, Boolean $cluster_require_full_coverage = true, Integer[0] $cluster_migration_barrier = 1, Hash[String[1], Hash] $instances = {}, ) inherits redis::params { if $package_ensure =~ /^([0-9]+:)?[0-9]+\.[0-9]/ { if ':' in $package_ensure { $_redis_version_real = split($package_ensure, ':') $redis_version_real = $_redis_version_real[1] } else { $redis_version_real = $package_ensure } } else { $redis_version_real = pick(getvar('redis_server_version'), $minimum_version) } $supports_protected_mode = !$redis_version_real or versioncmp($redis_version_real, '3.2.0') >= 0 contain redis::preinstall contain redis::install contain redis::config contain redis::service $instances.each | String $key, Hash $values | { redis::instance { $key: * => $values, } } Class['redis::preinstall'] -> Class['redis::install'] -> Class['redis::config'] if $redis::notify_service { Class['redis::config'] ~> Class['redis::service'] } } diff --git a/manifests/instance.pp b/manifests/instance.pp index de24610..616ed6e 100644 --- a/manifests/instance.pp +++ b/manifests/instance.pp @@ -1,392 +1,369 @@ # 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. # @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 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_hasrestart # Does the init script support restart? # @param service_hasstatus # Does the init script support status? # @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 ulimit # Limit the use of system-wide resources. # @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[String[1]] $masterauth = $redis::masterauth, Integer[1] $maxclients = $redis::maxclients, $maxmemory = $redis::maxmemory, $maxmemory_policy = $redis::maxmemory_policy, $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, 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[0] $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, Variant[Stdlib::Filemode , Enum['']] $unixsocketperm = $redis::unixsocketperm, Integer[0] $ulimit = $redis::ulimit, 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 $service_hasrestart = $redis::service_hasrestart, Boolean $service_hasstatus = $redis::service_hasstatus, Boolean $manage_service_file = true, Optional[Stdlib::Absolutepath] $log_file = undef, 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 $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, } } $_real_log_file = $log_file ? { undef => "${log_dir}/redis-server-${name}.log", default => $log_file, } if $workdir != $redis::workdir { file { $workdir: ensure => directory, group => $service_group, mode => $workdir_mode, owner => $service_user, } } if $manage_service_file { - $service_provider_lookup = pick(getvar('service_provider'), false) - - if $service_provider_lookup == 'systemd' { - file { "/etc/systemd/system/${service_name}.service": - ensure => file, - owner => 'root', - group => 'root', - mode => '0644', - content => template('redis/service_templates/redis.service.erb'), - } - - # Only necessary for Puppet < 6.1.0, - # See https://github.com/puppetlabs/puppet/commit/f8d5c60ddb130c6429ff12736bfdb4ae669a9fd4 - if versioncmp($facts['puppetversion'],'6.1.0') < 0 { - include systemd::systemctl::daemon_reload - File["/etc/systemd/system/${service_name}.service"] ~> Class['systemd::systemctl::daemon_reload'] - } + file { "/etc/systemd/system/${service_name}.service": + ensure => file, + owner => 'root', + group => 'root', + mode => '0644', + content => template('redis/service_templates/redis.service.erb'), + } - if $title != 'default' { - service { $service_name: - ensure => $service_ensure, - enable => $service_enable, - hasrestart => $service_hasrestart, - hasstatus => $service_hasstatus, - subscribe => [ - File["/etc/systemd/system/${service_name}.service"], - Exec["cp -p ${redis_file_name_orig} ${redis_file_name}"], - ], - } - } - } else { - file { "/etc/init.d/${service_name}": - ensure => file, - mode => '0755', - content => template("redis/service_templates/redis.${facts['os']['family']}.erb"), - } + # Only necessary for Puppet < 6.1.0, + # See https://github.com/puppetlabs/puppet/commit/f8d5c60ddb130c6429ff12736bfdb4ae669a9fd4 + if versioncmp($facts['puppetversion'],'6.1.0') < 0 { + include systemd::systemctl::daemon_reload + File["/etc/systemd/system/${service_name}.service"] ~> Class['systemd::systemctl::daemon_reload'] + } - if $title != 'default' { - service { $service_name: - ensure => $service_ensure, - enable => $service_enable, - hasrestart => $service_hasrestart, - hasstatus => $service_hasstatus, - subscribe => [ - File["/etc/init.d/${service_name}"], - Exec["cp -p ${redis_file_name_orig} ${redis_file_name}"], - ], - } + if $title != 'default' { + service { $service_name: + ensure => $service_ensure, + enable => $service_enable, + hasrestart => $service_hasrestart, + hasstatus => $service_hasstatus, + subscribe => [ + File["/etc/systemd/system/${service_name}.service"], + Exec["cp -p ${redis_file_name_orig} ${redis_file_name}"], + ], } } } File { owner => $config_owner, group => $config_group, mode => $config_file_mode, } file { $redis_file_name_orig: ensure => file, } exec { "cp -p ${redis_file_name_orig} ${redis_file_name}": path => '/usr/bin:/bin', subscribe => File[$redis_file_name_orig], refreshonly => true, } $bind_arr = [$bind].flatten $supports_protected_mode = $redis::supports_protected_mode File[$redis_file_name_orig] { content => template($conf_template) } } diff --git a/manifests/params.pp b/manifests/params.pp index 3cd0f54..c995360 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -1,208 +1,200 @@ # @summary This class provides a number of parameters. # @api private class redis::params inherits redis::globals { case $facts['os']['family'] { 'Debian': { $ppa_repo = 'ppa:chris-lea/redis-server' $config_dir = '/etc/redis' $config_dir_mode = '0755' $config_file = '/etc/redis/redis.conf' $config_file_orig = '/etc/redis/redis.conf.puppet' $config_owner = 'redis' $log_dir_mode = '0755' $package_name = 'redis-server' $pid_file = '/var/run/redis/redis-server.pid' $workdir = '/var/lib/redis' $daemonize = true $service_name = 'redis-server' $sentinel_config_file = '/etc/redis/sentinel.conf' $sentinel_config_file_orig = '/etc/redis/redis-sentinel.conf.puppet' $sentinel_service_name = 'redis-sentinel' $sentinel_daemonize = true - $sentinel_init_script = '/etc/init.d/redis-sentinel' $sentinel_package_name = 'redis-sentinel' $sentinel_log_file = '/var/log/redis/redis-sentinel.log' $sentinel_working_dir = '/var/lib/redis' $sentinel_protected_mode = true case $facts['os']['name'] { 'Ubuntu': { $config_group = 'redis' $minimum_version = $facts['os']['release']['major'] ? { '16.04' => '3.0.5', '18.04' => '4.0.9', default => '5.0.7', } $sentinel_pid_file = $facts['os']['release']['major'] ? { '16.04' => '/var/run/redis/redis-sentinel.pid', default => '/var/run/sentinel/redis-sentinel.pid', } } default: { $config_group = 'root' $minimum_version = '3.2.5' if versioncmp($facts['os']['release']['major'], '10') >= 0 { $sentinel_pid_file = '/run/sentinel/redis-sentinel.pid' } else { $sentinel_pid_file = '/var/run/redis/redis-sentinel.pid' } } } } 'RedHat': { $ppa_repo = undef $daemonize = false $config_owner = 'redis' $config_group = 'root' $config_dir_mode = '0755' $log_dir_mode = '0750' $sentinel_daemonize = false - $sentinel_init_script = undef $sentinel_working_dir = '/tmp' $sentinel_protected_mode = true $scl = $redis::globals::scl if $scl { $config_dir = "/etc/opt/rh/${scl}/redis" $config_file = "/etc/opt/rh/${scl}/redis.conf" $config_file_orig = "/etc/opt/rh/${scl}/redis.conf.puppet" $package_name = "${scl}-redis" $pid_file = "/var/opt/rh/${scl}/run/redis_6379.pid" $service_name = "${scl}-redis" $workdir = "/var/opt/rh/${scl}/lib/redis" $sentinel_config_file = "${config_dir}/redis-sentinel.conf" $sentinel_config_file_orig = "${config_dir}/redis-sentinel.conf.puppet" $sentinel_service_name = "${scl}-redis-sentinel" $sentinel_package_name = $package_name $sentinel_pid_file = "/var/opt/rh/${scl}/run/redis-sentinel.pid" $sentinel_log_file = "/var/opt/rh/${scl}/log/redis/sentinel.log" $minimum_version = $scl ? { 'rh-redis32' => '3.2.13', default => '5.0.5', } } else { $config_dir = '/etc/redis' $config_file = '/etc/redis.conf' $config_file_orig = '/etc/redis.conf.puppet' $package_name = 'redis' - $pid_file = $facts['os']['release']['major'] ? { - '6' => '/var/run/redis/redis.pid', - default => '/var/run/redis_6379.pid', - } + $pid_file = '/var/run/redis_6379.pid' $service_name = 'redis' $workdir = '/var/lib/redis' $sentinel_config_file = '/etc/redis-sentinel.conf' $sentinel_config_file_orig = '/etc/redis-sentinel.conf.puppet' $sentinel_service_name = 'redis-sentinel' $sentinel_package_name = 'redis' $sentinel_pid_file = '/var/run/redis/redis-sentinel.pid' $sentinel_log_file = '/var/log/redis/sentinel.log' - # EPEL 6 and newer have 3.2 so we can assume all EL is 3.2+ - $minimum_version = '3.2.10' + # EPEL 7 and newer have 3.2 so we can assume all EL is 3.2+ + $minimum_version = '3.2.12' } } 'FreeBSD': { $ppa_repo = undef $config_dir = '/usr/local/etc/redis' $config_dir_mode = '0755' $config_file = '/usr/local/etc/redis.conf' $config_file_orig = '/usr/local/etc/redis.conf.puppet' $config_group = 'wheel' $config_owner = 'redis' $log_dir_mode = '0755' $package_name = 'redis' $pid_file = '/var/run/redis/redis.pid' $daemonize = true $service_name = 'redis' $workdir = '/var/db/redis' $sentinel_config_file = '/usr/local/etc/redis-sentinel.conf' $sentinel_config_file_orig = '/usr/local/etc/redis-sentinel.conf.puppet' $sentinel_service_name = 'redis-sentinel' $sentinel_daemonize = true - $sentinel_init_script = undef $sentinel_package_name = 'redis' $sentinel_pid_file = '/var/run/redis/redis-sentinel.pid' $sentinel_log_file = '/var/log/redis/sentinel.log' $sentinel_working_dir = '/tmp' $sentinel_protected_mode = true # pkg version $minimum_version = '3.2.4' } 'Suse': { $ppa_repo = undef $config_dir = '/etc/redis' $config_dir_mode = '0750' $config_file = '/etc/redis/redis-server.conf' $config_group = 'redis' $config_owner = 'redis' $log_dir_mode = '0750' $package_name = 'redis' $pid_file = '/var/run/redis/redis-server.pid' $daemonize = true $service_name = 'redis' $workdir = '/var/lib/redis' $sentinel_config_file = '/etc/redis/redis-sentinel.conf' $sentinel_config_file_orig = '/etc/redis/redis-sentinel.conf.puppet' $sentinel_service_name = 'redis-sentinel' $sentinel_daemonize = true - $sentinel_init_script = undef $sentinel_package_name = 'redis' $sentinel_pid_file = '/var/run/redis/redis-sentinel.pid' $sentinel_log_file = '/var/log/redis/sentinel.log' $sentinel_working_dir = '/tmp' $sentinel_protected_mode = true # suse package version $minimum_version = '3.0.5' } 'Archlinux': { $ppa_repo = undef $config_dir = '/etc/redis' $config_dir_mode = '0755' $config_file = '/etc/redis/redis.conf' $config_file_orig = '/etc/redis/redis.conf.puppet' $config_group = 'root' $config_owner = 'root' $log_dir_mode = '0755' $package_name = 'redis' $pid_file = '/var/run/redis.pid' $daemonize = true $service_name = 'redis' $workdir = '/var/lib/redis' $sentinel_config_file = '/etc/redis/redis-sentinel.conf' $sentinel_config_file_orig = '/etc/redis/redis-sentinel.conf.puppet' $sentinel_service_name = 'redis-sentinel' $sentinel_daemonize = true - $sentinel_init_script = undef $sentinel_package_name = 'redis' $sentinel_pid_file = '/var/run/redis/redis-sentinel.pid' $sentinel_log_file = '/var/log/redis/sentinel.log' $sentinel_working_dir = '/tmp' $sentinel_protected_mode = true # pkg version $minimum_version = '3.2.4' } default: { fail "Operating system ${facts['os']['name']} is not supported yet." } } } diff --git a/manifests/sentinel.pp b/manifests/sentinel.pp index ad5b169..e29e364 100644 --- a/manifests/sentinel.pp +++ b/manifests/sentinel.pp @@ -1,194 +1,165 @@ # @summary Install redis-sentinel # # @param auth_pass # The password to use to authenticate with the master and slaves. # # @param config_file # The location and name of the sentinel config file. # # @param config_file_orig # The location and name of a config file that provides the source # of the sentinel config file. Two different files are needed # because sentinel itself writes to its own config file and we do # not want override that when puppet is run unless there are # changes from the manifests. # # @param config_file_mode # Permissions of config file. # # @param conf_template # Define which template to use. # # @param daemonize # Have Redis sentinel run as a daemon. # # @param down_after # Number of milliseconds the master (or any attached slave or sentinel) # should be unreachable (as in, not acceptable reply to PING, continuously, # for the specified period) in order to consider it in S_DOWN state. # # @param failover_timeout # Specify the failover timeout in milliseconds. # -# @param init_script -# Specifiy the init script that will be created for sentinel. -# # @param log_file # Specify where to write log entries. # # @param log_level # Specify how much we should log. # # @param master_name # Specify the name of the master redis server. # The valid charset is A-z 0-9 and the three characters ".-_". # # @param redis_host # Specify the bound host of the master redis server. # # @param redis_port # Specify the port of the master redis server. # # @param protected_mode # Whether protected mode is enabled or not. Only applicable when no bind is set. # # @param package_name # The name of the package that installs sentinel. # # @param package_ensure # Do we ensure this package. # # @param parallel_sync # How many slaves can be reconfigured at the same time to use a # new master after a failover. # # @param pid_file # If sentinel is daemonized it will write its pid at this location. # # @param quorum # Number of sentinels that must agree that a master is down to # signal sdown state. # # @param sentinel_bind # Allow optional sentinel server ip binding. Can help overcome # issues arising from protect-mode added Redis 3.2 # # @param sentinel_port # The port of sentinel server. # # @param service_group # The group of the config file. # # @param service_name # The name of the service (for puppet to manage). # # @param service_user # The owner of the config file. # # @param service_enable # Enable the service at boot time. # # @param working_dir # The directory into which sentinel will change to avoid mount # conflicts. # # @param notification_script # Path to the notification script # # @param client_reconfig_script # Path to the client-reconfig script # # @example Basic inclusion # include redis::sentinel # # @example Configuring options # class {'redis::sentinel': # down_after => 80000, # log_file => '/var/log/redis/sentinel.log', # } # class redis::sentinel ( Optional[String[1]] $auth_pass = undef, Stdlib::Absolutepath $config_file = $redis::params::sentinel_config_file, Stdlib::Absolutepath $config_file_orig = $redis::params::sentinel_config_file_orig, Stdlib::Filemode $config_file_mode = '0644', String[1] $conf_template = 'redis/redis-sentinel.conf.erb', Boolean $daemonize = $redis::params::sentinel_daemonize, Boolean $protected_mode = $redis::params::sentinel_protected_mode, Integer[1] $down_after = 30000, Integer[1] $failover_timeout = 180000, - Optional[Stdlib::Absolutepath] $init_script = $redis::params::sentinel_init_script, - String[1] $init_template = 'redis/redis-sentinel.init.erb', Redis::LogLevel $log_level = 'notice', Stdlib::Absolutepath $log_file = $redis::params::sentinel_log_file, String[1] $master_name = 'mymaster', Stdlib::Host $redis_host = '127.0.0.1', Stdlib::Port $redis_port = 6379, String[1] $package_name = $redis::params::sentinel_package_name, String[1] $package_ensure = 'present', Integer[0] $parallel_sync = 1, Stdlib::Absolutepath $pid_file = $redis::params::sentinel_pid_file, Integer[1] $quorum = 2, Variant[Undef, Stdlib::IP::Address, Array[Stdlib::IP::Address]] $sentinel_bind = undef, Stdlib::Port $sentinel_port = 26379, String[1] $service_group = 'redis', String[1] $service_name = $redis::params::sentinel_service_name, Stdlib::Ensure::Service $service_ensure = 'running', Boolean $service_enable = true, String[1] $service_user = 'redis', Stdlib::Absolutepath $working_dir = $redis::params::sentinel_working_dir, Optional[Stdlib::Absolutepath] $notification_script = undef, Optional[Stdlib::Absolutepath] $client_reconfig_script = undef, ) inherits redis::params { require 'redis' - if $facts['os']['family'] == 'Debian' { - package { $package_name: - ensure => $package_ensure, - before => File[$config_file_orig], - } - - if $init_script { - Package[$package_name] -> File[$init_script] - } - } + ensure_packages([$package_name]) + Package[$package_name] -> File[$config_file_orig] $sentinel_bind_arr = delete_undef_values([$sentinel_bind].flatten) $supports_protected_mode = $redis::supports_protected_mode file { $config_file_orig: ensure => file, owner => $service_user, group => $service_group, mode => $config_file_mode, content => template($conf_template), } exec { "cp -p ${config_file_orig} ${config_file}": path => '/usr/bin:/bin', subscribe => File[$config_file_orig], notify => Service[$service_name], refreshonly => true, } - if $init_script { - file { $init_script: - ensure => file, - owner => 'root', - group => 'root', - mode => '0755', - content => template($init_template), - } - - exec { '/usr/sbin/update-rc.d redis-sentinel defaults': - subscribe => File[$init_script], - refreshonly => true, - notify => Service[$service_name], - } - } - service { $service_name: ensure => $service_ensure, enable => $service_enable, } } diff --git a/manifests/service.pp b/manifests/service.pp index 62d1965..7e291aa 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -1,13 +1,12 @@ # @summary This class manages the Redis daemon. # @api private class redis::service { if $redis::service_manage { service { $redis::service_name: ensure => $redis::service_ensure, enable => $redis::service_enable, hasrestart => $redis::service_hasrestart, hasstatus => $redis::service_hasstatus, - provider => $redis::service_provider, } } } diff --git a/manifests/ulimit.pp b/manifests/ulimit.pp index f7fa88f..18498d9 100644 --- a/manifests/ulimit.pp +++ b/manifests/ulimit.pp @@ -1,78 +1,57 @@ # Redis class for configuring ulimit # Used to DRY up the config class, and # move the logic for ulimit changes all # into one place. # # Parameters are not required as it's a # private class only referencable from # the redis module, where the variables # would already be defined # # @example # contain redis::ulimit # # @author - Peter Souter # # @api private class redis::ulimit { assert_private('The redis::ulimit class is only to be called from the redis::config class') - $service_provider_lookup = pick(getvar('service_provider'), false) - if $redis::managed_by_cluster_manager { file { '/etc/security/limits.d/redis.conf': ensure => 'file', owner => 'root', group => 'root', mode => '0644', content => "redis soft nofile ${redis::ulimit}\nredis hard nofile ${redis::ulimit}\n", } } - if $service_provider_lookup == 'systemd' { - file { "/etc/systemd/system/${redis::service_name}.service.d/": - ensure => 'directory', - owner => 'root', - group => 'root', - selinux_ignore_defaults => true, - } - file { "/etc/systemd/system/${redis::service_name}.service.d/limit.conf": - ensure => file, - owner => 'root', - group => 'root', - mode => '0444', - } - augeas { 'Systemd redis ulimit' : - incl => "/etc/systemd/system/${redis::service_name}.service.d/limit.conf", - lens => 'Systemd.lns', - changes => [ - "defnode nofile Service/LimitNOFILE \"\"", - "set \$nofile/value \"${redis::ulimit}\"", - ], - } - # Only necessary for Puppet < 6.1.0, - # See https://github.com/puppetlabs/puppet/commit/f8d5c60ddb130c6429ff12736bfdb4ae669a9fd4 - if versioncmp($facts['puppetversion'],'6.1.0') < 0 { - include systemd::systemctl::daemon_reload - Augeas['Systemd redis ulimit'] ~> Class['systemd::systemctl::daemon_reload'] - } - } else { - case $facts['os']['family'] { - 'Debian': { - augeas { 'redis ulimit': - context => '/files/etc/default/redis-server', - changes => "set ULIMIT ${redis::ulimit}", - } - } - 'RedHat': { - augeas { 'redis ulimit': - context => '/files/etc/sysconfig/redis', - changes => "set ULIMIT ${redis::ulimit}", - } - } - default: { - warning("Not sure how to set ULIMIT on non-systemd OSFamily ${facts['os']['family']}, PR's welcome") - } - } + file { "/etc/systemd/system/${redis::service_name}.service.d/": + ensure => 'directory', + owner => 'root', + group => 'root', + selinux_ignore_defaults => true, + } + + file { "/etc/systemd/system/${redis::service_name}.service.d/limit.conf": + ensure => file, + owner => 'root', + group => 'root', + mode => '0444', + } + augeas { 'Systemd redis ulimit' : + incl => "/etc/systemd/system/${redis::service_name}.service.d/limit.conf", + lens => 'Systemd.lns', + changes => [ + "defnode nofile Service/LimitNOFILE \"\"", + "set \$nofile/value \"${redis::ulimit}\"", + ], + } + # Only necessary for Puppet < 6.1.0, + # See https://github.com/puppetlabs/puppet/commit/f8d5c60ddb130c6429ff12736bfdb4ae669a9fd4 + if versioncmp($facts['puppetversion'],'6.1.0') < 0 { + include systemd::systemctl::daemon_reload + Augeas['Systemd redis ulimit'] ~> Class['systemd::systemctl::daemon_reload'] } } diff --git a/metadata.json b/metadata.json index 3bc556d..6e4eb12 100644 --- a/metadata.json +++ b/metadata.json @@ -1,74 +1,72 @@ { "name": "puppet-redis", "version": "6.1.1-rc0", "author": "Vox Pupuli", "summary": "Redis module", "license": "Apache-2.0", "source": "https://github.com/voxpupuli/puppet-redis.git", "project_page": "http://github.com/voxpupuli/puppet-redis", "issues_url": "https://github.com/voxpupuli/puppet-redis/issues", "dependencies": [ { "name": "puppetlabs/stdlib", "version_requirement": ">= 4.25.0 < 7.0.0" }, { "name": "herculesteam/augeasproviders_sysctl", "version_requirement": ">= 2.1.0 < 3.0.0" }, { "name": "herculesteam/augeasproviders_core", "version_requirement": ">= 2.1.0 < 3.0.0" } ], "description": "Redis module with cluster support", "tags": [ "cluster", "failover", "loadbalancing", "redis", "sentinel" ], "requirements": [ { "name": "puppet", "version_requirement": ">= 5.5.8 < 7.0.0" } ], "operatingsystem_support": [ { "operatingsystem": "Debian", "operatingsystemrelease": [ "9", "10" ] }, { "operatingsystem": "Ubuntu", "operatingsystemrelease": [ "16.04", "18.04", "20.04" ] }, { "operatingsystem": "RedHat", "operatingsystemrelease": [ - "6", "7", "8" ] }, { "operatingsystem": "CentOS", "operatingsystemrelease": [ - "6", "7", "8" ] }, { "operatingsystem": "Archlinux" } ] } diff --git a/spec/acceptance/suites/default/redis_multi_instances_one_host_spec.rb b/spec/acceptance/suites/default/redis_multi_instances_one_host_spec.rb index 9d01b46..04fb523 100644 --- a/spec/acceptance/suites/default/redis_multi_instances_one_host_spec.rb +++ b/spec/acceptance/suites/default/redis_multi_instances_one_host_spec.rb @@ -1,77 +1,77 @@ require 'spec_helper_acceptance' describe 'redis::instance example' do instances = [6379, 6380, 6381, 6382] case fact('osfamily') when 'Debian' config_path = '/etc/redis' redis_name = 'redis-server' else config_path = '/etc' redis_name = 'redis' end it 'runs successfully' do pp = <<-EOS $listening_ports = #{instances} class { '::redis': default_install => false, service_enable => false, service_ensure => 'stopped', } $listening_ports.each |$port| { $port_string = sprintf('%d',$port) redis::instance { $port_string: service_enable => true, service_ensure => 'running', port => $port, bind => $facts['networking']['ip'], dbfilename => "${port}-dump.rdb", appendfilename => "${port}-appendonly.aof", appendfsync => 'always', require => Class['Redis'], } } EOS # Apply twice to ensure no errors the second time. apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) end describe package(redis_name) do it { is_expected.to be_installed } end describe service(redis_name) do it { is_expected.not_to be_enabled } it { is_expected.not_to be_running } end instances.each do |instance| - describe file("/etc/systemd/system/redis-server-#{instance}.service"), if: (fact('service_provider') == 'systemd') do + describe file("/etc/systemd/system/redis-server-#{instance}.service") do its(:content) { is_expected.to match %r{redis-server-#{instance}.conf} } end describe service("redis-server-#{instance}") do it { is_expected.to be_enabled } end describe service("redis-server-#{instance}") do it { is_expected.to be_running } end describe file("#{config_path}/redis-server-#{instance}.conf") do its(:content) { is_expected.to match %r{port #{instance}} } end context "redis instance #{instance} should respond to ping command" do describe command("redis-cli -h #{fact('networking.ip')} -p #{instance} ping") do its(:stdout) { is_expected.to match %r{PONG} } end end end end diff --git a/spec/classes/redis_spec.rb b/spec/classes/redis_spec.rb index f447978..55898f0 100644 --- a/spec/classes/redis_spec.rb +++ b/spec/classes/redis_spec.rb @@ -1,1409 +1,1378 @@ require 'spec_helper' describe 'redis' do - let(:service_file) do - if facts['service_provider'] == 'systemd' - "/etc/systemd/system/#{service_name}.service" - else - "/etc/init.d/#{service_name}" - end - end + let(:service_file) { "/etc/systemd/system/#{service_name}.service" } let(:package_name) { manifest_vars[:package_name] } let(:service_name) { manifest_vars[:service_name] } let(:config_file) { manifest_vars[:config_file] } let(:config_file_orig) { manifest_vars[:config_file_orig] } on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) { facts } if facts[:operatingsystem] == 'Ubuntu' && facts[:operatingsystemmajrelease] == '16.04' let(:systemd) { '' } let(:servicetype) { 'forking' } else let(:systemd) { ' --supervised systemd' } let(:servicetype) { 'notify' } end 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('present') } it do is_expected.to contain_file(config_file_orig). with_ensure('file'). 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 do is_expected.to contain_service(service_name).with( 'ensure' => 'running', 'enable' => 'true', 'hasrestart' => 'true', 'hasstatus' => 'true' ) end 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 context 'with ulimit' do let(:params) { { ulimit: 7777 } } it { is_expected.to compile.with_all_deps } it do - if facts['service_provider'] == 'systemd' - is_expected.to contain_file("/etc/systemd/system/#{service_name}.service.d/limit.conf"). - with_ensure('file'). - with_owner('root'). - with_group('root'). - with_mode('0444') - # Only necessary for Puppet < 6.1.0, - # See https://github.com/puppetlabs/puppet/commit/f8d5c60ddb130c6429ff12736bfdb4ae669a9fd4 - if Puppet.version < '6.1' - is_expected.to contain_augeas('Systemd redis ulimit'). - with_incl("/etc/systemd/system/#{service_name}.service.d/limit.conf"). - with_lens('Systemd.lns'). - with_changes(['defnode nofile Service/LimitNOFILE ""', 'set $nofile/value "7777"']). - that_notifies('Class[systemd::systemctl::daemon_reload]') - else - is_expected.to contain_augeas('Systemd redis ulimit'). - with_incl("/etc/systemd/system/#{service_name}.service.d/limit.conf"). - with_lens('Systemd.lns'). - with_changes(['defnode nofile Service/LimitNOFILE ""', 'set $nofile/value "7777"']) - end + is_expected.to contain_file("/etc/systemd/system/#{service_name}.service.d/limit.conf"). + with_ensure('file'). + with_owner('root'). + with_group('root'). + with_mode('0444') + # Only necessary for Puppet < 6.1.0, + # See https://github.com/puppetlabs/puppet/commit/f8d5c60ddb130c6429ff12736bfdb4ae669a9fd4 + if Puppet.version < '6.1' + is_expected.to contain_augeas('Systemd redis ulimit'). + with_incl("/etc/systemd/system/#{service_name}.service.d/limit.conf"). + with_lens('Systemd.lns'). + with_changes(['defnode nofile Service/LimitNOFILE ""', 'set $nofile/value "7777"']). + that_notifies('Class[systemd::systemctl::daemon_reload]') else - is_expected.not_to contain_file('/etc/systemd/system/redis-server.service.d/limit.conf') - is_expected.not_to contain_augeas('Systemd redis ulimit') - if %w[Debian RedHat].include?(facts[:osfamily]) - ulimit_context = case facts[:osfamily] - when 'Debian' - '/files/etc/default/redis-server' - when 'RedHat' - '/files/etc/sysconfig/redis' - end - - if ulimit_context - is_expected.to contain_augeas('redis ulimit'). - with_changes('set ULIMIT 7777'). - with_context(ulimit_context) - else - is_expected.not_to contain_augeas('redis ulimit') - end - end + is_expected.to contain_augeas('Systemd redis ulimit'). + with_incl("/etc/systemd/system/#{service_name}.service.d/limit.conf"). + with_lens('Systemd.lns'). + with_changes(['defnode nofile Service/LimitNOFILE ""', 'set $nofile/value "7777"']) 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 let(:params) do { log_file: '/var/log/redis/redis.log' } end it { is_expected.to contain_file(config_file_orig).with( 'content' => %r{^logfile /var/log/redis/redis\.log$} ) } 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 do if facts[:operatingsystem] == 'Ubuntu' && facts[:operatingsystemmajrelease] == '16.04' is_expected.not_to contain_file(config_file_orig).with_content(%r{protected-mode}) else is_expected.to contain_file(config_file_orig).with_content(%r{^protected-mode no$}) end end 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 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_hasrestart' do let(:params) { { service_hasrestart: true } } it { is_expected.to contain_service(package_name).with_hasrestart(true) } end describe 'with parameter: service_hasstatus' do let(:params) { { service_hasstatus: true } } it { is_expected.to contain_service(package_name).with_hasstatus(true) } 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 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 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 parameter manage_service_file' do let(:params) do { manage_service_file: true } end it { is_expected.to contain_file(service_file) } 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 |RuntimeDirectoryMode=2755 |Type=#{servicetype} |ExecStart=/usr/bin/redis-server #{config_file}#{systemd} |ExecStop=/usr/bin/redis-cli -p 6379 shutdown |Restart=always |User=redis |Group=redis |LimitNOFILE=65536 | |[Install] |WantedBy=multi-user.target END - if facts['service_provider'] == 'systemd' - is_expected.to contain_file(service_file).with_content(content) - else - is_expected.to contain_file(service_file).with_content(%r{Required-Start:}) - end + is_expected.to contain_file(service_file).with_content(content) end end describe 'with parameter manage_service_file' do let(:params) do { manage_service_file: false } end it { is_expected.not_to contain_file(service_file) } end context 'when $::redis_server_version fact is not present' do let(:facts) { super().merge(redis_server_version: nil) } context 'when package_ensure is version (3.2.1)' do let(:params) { { package_ensure: '3.2.1' } } it { is_expected.to contain_file(config_file_orig).with_content(%r{^protected-mode}) } end context 'when package_ensure is a newer version(4.0-rc3) (older features enabled)' do let(:params) { { package_ensure: '4.0-rc3' } } it { is_expected.to contain_file(config_file_orig).with_content(%r{^protected-mode}) } end end context 'when $::redis_server_version fact is present but a newer version (older features enabled)' do let(:facts) { super().merge(redis_server_version: '3.2.1') } it { is_expected.to contain_file(config_file_orig).with_content(%r{^protected-mode}) } end end end end diff --git a/spec/defines/instance_spec.rb b/spec/defines/instance_spec.rb index 03647ff..44e2764 100644 --- a/spec/defines/instance_spec.rb +++ b/spec/defines/instance_spec.rb @@ -1,63 +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}) end it { is_expected.to contain_file('/var/lib/redis/redis-server-app2') } it do - if facts['service_provider'] == 'systemd' - is_expected.to contain_file('/etc/systemd/system/redis-server-app2.service').with_content(%r{ExecStart=/usr/bin/redis-server #{config_file}}) - else - case facts[:os]['family'] - when 'Debian' - is_expected.to contain_file('/etc/init.d/redis-server-app2'). - with_content(%r{DAEMON_ARGS=#{config_file}}). - with_content(%r{PIDFILE=/var/run/redis/redis-server-app2\.pid}) - when 'RedHat' - is_expected.to contain_file('/etc/init.d/redis-server-app2'). - with_content(%r{REDIS_CONFIG="#{config_file}"}). - with_content(%r{pidfile="/var/run/redis/redis-server-app2\.pid"}) - else - is_expected.to contain_file('/etc/init.d/redis-server-app2') - end - end + 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').with_ensure('running').with_enable('true') } end end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8858124..8f57554 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,85 +1,60 @@ RSpec.configure do |c| c.mock_with :mocha end require 'puppetlabs_spec_helper/module_spec_helper' require 'rspec-puppet-facts' include RspecPuppetFacts def manifest_vars vars = {} case facts[:osfamily].to_s when 'RedHat' vars[:package_name] = 'redis' vars[:service_name] = 'redis' vars[:config_file] = '/etc/redis.conf' vars[:config_file_orig] = '/etc/redis.conf.puppet' when 'FreeBSD', vars[:package_name] = 'redis' vars[:service_name] = 'redis' vars[:config_file] = '/usr/local/etc/redis.conf' vars[:config_file_orig] = '/usr/local/etc/redis.conf.puppet' when 'Debian' vars[:package_name] = 'redis-server' vars[:service_name] = 'redis-server' vars[:config_file] = '/etc/redis/redis.conf' vars[:config_file_orig] = '/etc/redis/redis.conf.puppet' when 'Archlinux' vars[:package_name] = 'redis' vars[:service_name] = 'redis' vars[:config_file] = '/etc/redis/redis.conf' vars[:config_file_orig] = '/etc/redis/redis.conf.puppet' end vars end if ENV['DEBUG'] Puppet::Util::Log.level = :debug Puppet::Util::Log.newdestination(:console) end -add_custom_fact :service_provider, (lambda do |_os, facts| - case facts[:osfamily].downcase - when 'archlinux' - 'systemd' - when 'darwin' - 'launchd' - when 'debian' - 'systemd' - when 'freebsd' - 'freebsd' - when 'gentoo' - 'openrc' - when 'openbsd' - 'openbsd' - when 'redhat' - facts[:operatingsystemrelease].to_i >= 7 ? 'systemd' : 'redhat' - when 'suse' - facts[:operatingsystemmajrelease].to_i >= 12 ? 'systemd' : 'redhat' - when 'windows' - 'windows' - else - 'init' - end -end) - RSpec.configure do |c| # getting the correct facter version is tricky. We use facterdb as a source to mock facts # see https://github.com/camptocamp/facterdb # people might provide a specific facter version. In that case we use it. # Otherwise we need to match the correct facter version to the used puppet version. # as of 2019-10-31, puppet 5 ships facter 3.11 and puppet 6 ships facter 3.14 # https://puppet.com/docs/puppet/5.5/about_agent.html c.default_facter_version = if ENV['FACTERDB_FACTS_VERSION'] ENV['FACTERDB_FACTS_VERSION'] else Gem::Dependency.new('', ENV['PUPPET_VERSION']).match?('', '5') ? '3.11.0' : '3.14.0' end # Coverage generation c.after(:suite) do RSpec::Puppet::Coverage.report! end end diff --git a/templates/redis-sentinel.init.erb b/templates/redis-sentinel.init.erb deleted file mode 100644 index a4e1b39..0000000 --- a/templates/redis-sentinel.init.erb +++ /dev/null @@ -1,89 +0,0 @@ -#! /bin/sh -### BEGIN INIT INFO -# Provides: redis-sentinel -# Required-Start: $syslog $remote_fs -# Required-Stop: $syslog $remote_fs -# Should-Start: $local_fs -# Should-Stop: $local_fs -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: redis-sentinel - Monitor redis-server -# Description: redis-sentinel - Monitor redis-server -### END INIT INFO - - -PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin -DAEMON=/usr/bin/redis-sentinel -DAEMON_ARGS=<%= @config_file %> -NAME=redis-sentinel -DESC=redis-senitnel - -RUNDIR=/var/run/redis -PIDFILE=$RUNDIR/redis-sentinel.pid - -test -x $DAEMON || exit 0 - -if [ -r /etc/default/$NAME ] -then - . /etc/default/$NAME -fi - -. /lib/lsb/init-functions - -set -e - -case "$1" in - start) - echo -n "Starting $DESC: " - mkdir -p $RUNDIR - touch $PIDFILE - chown <%= @service_user %>:<%= @service_group %> $RUNDIR $PIDFILE - chmod 755 $RUNDIR - - if [ -n "$ULIMIT" ] - then - ulimit -n $ULIMIT - fi - - if start-stop-daemon --start --quiet --umask 007 --pidfile $PIDFILE --chuid <%= @service_user %>:<%= @service_group %> --exec $DAEMON -- $DAEMON_ARGS - then - echo "$NAME." - else - echo "failed" - fi - ;; - stop) - echo -n "Stopping $DESC: " - if start-stop-daemon --stop --retry forever/TERM/1 --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON - then - echo "$NAME." - else - echo "failed" - fi - rm -f $PIDFILE - sleep 1 - ;; - - restart|force-reload) - ${0} stop - ${0} start - ;; - - status) - echo -n "$DESC is " - if start-stop-daemon --stop --quiet --signal 0 --name ${NAME} --pidfile ${PIDFILE} - then - echo "running" - else - echo "not running" - exit 1 - fi - ;; - - *) - echo "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload|status}" >&2 - exit 1 - ;; -esac - -exit 0 diff --git a/templates/service_templates/redis.Debian.erb b/templates/service_templates/redis.Debian.erb deleted file mode 100644 index 118abf3..0000000 --- a/templates/service_templates/redis.Debian.erb +++ /dev/null @@ -1,101 +0,0 @@ -#! /bin/sh -### BEGIN INIT INFO -# Provides: redis-server -# Required-Start: $syslog $remote_fs -# Required-Stop: $syslog $remote_fs -# Should-Start: $local_fs -# Should-Stop: $local_fs -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: redis-server - Persistent key-value db -# Description: redis-server - Persistent key-value db -### END INIT INFO - -PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin -DAEMON=/usr/bin/redis-server -DAEMON_ARGS=<%= @redis_file_name %> -NAME=redis-server-<%= @name %> -DESC=redis-server-<%= @name %> - -RUNDIR=/var/run/redis -PIDFILE=/var/run/redis/redis-server-<%= @name %>.pid - -test -x $DAEMON || exit 0 - -if [ -r /etc/default/$NAME ] -then - . /etc/default/$NAME -fi - -. /lib/lsb/init-functions - -set -e - -if [ "$(id -u)" != "0" ] -then - log_failure_msg "Must be run as root." - exit 1 -fi - -Run_parts () { - if [ -d /etc/redis/${NAME}.${1}.d ] - then - su redis -s /bin/sh -c "run-parts --exit-on-error /etc/redis/${NAME}.${1}.d" - fi -} - -case "$1" in - start) - echo -n "Starting $DESC: " - mkdir -p $RUNDIR - touch $PIDFILE - chown redis:redis $RUNDIR $PIDFILE - chmod 755 $RUNDIR - - if [ -n "$ULIMIT" ] - then - ulimit -n $ULIMIT - fi - - Run_parts pre-up - - if start-stop-daemon --start --quiet --oknodo --umask 007 --pidfile $PIDFILE --chuid redis:redis --exec $DAEMON -- $DAEMON_ARGS - then - Run_parts post-up - echo "$NAME." - else - echo "failed" - fi - ;; - stop) - echo -n "Stopping $DESC: " - - Run_parts pre-down - - if start-stop-daemon --stop --retry forever/TERM/1 --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON - then - Run_parts post-down - echo "$NAME." - else - echo "failed" - fi - rm -f $PIDFILE - sleep 1 - ;; - - restart|force-reload) - ${0} stop - ${0} start - ;; - - status) - status_of_proc -p ${PIDFILE} ${DAEMON} ${NAME} - ;; - - *) - echo "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload|status}" >&2 - exit 1 - ;; -esac - -exit 0 diff --git a/templates/service_templates/redis.RedHat.erb b/templates/service_templates/redis.RedHat.erb deleted file mode 100644 index ab3dc8d..0000000 --- a/templates/service_templates/redis.RedHat.erb +++ /dev/null @@ -1,104 +0,0 @@ -#!/bin/sh -# -# redis init file for starting up the redis daemon -# -# chkconfig: - 20 80 -# description: Starts and stops the redis daemon. -# -### BEGIN INIT INFO -# Provides: redis-server-<%= @name %> -# Required-Start: $local_fs $remote_fs $network -# Required-Stop: $local_fs $remote_fs $network -# Short-Description: start and stop Redis server instance <%= @name %> -# Description: A persistent key-value database -### END INIT INFO - -# Source function library. -. /etc/rc.d/init.d/functions - -name="redis-server-<%= @name %>" -exec="/usr/bin/redis-server" -pidfile="/var/run/redis/redis-server-<%= @name %>.pid" -REDIS_CONFIG="<%= @redis_file_name %>" - -[ -e /etc/sysconfig/redis ] && . /etc/sysconfig/redis - -lockfile=/var/lock/subsys/redis-<%= @name %> - -start() { - [ -f $REDIS_CONFIG ] || exit 6 - [ -x $exec ] || exit 5 - echo -n $"Starting $name: " - daemon --user ${REDIS_USER-redis} "$exec $REDIS_CONFIG" - retval=$? - echo - [ $retval -eq 0 ] && touch $lockfile - return $retval -} - -stop() { - echo -n $"Stopping $name: " - [ -x $shut ] && $shut - retval=$? - if [ -f $pidfile ] - then - # shutdown haven't work, try old way - killproc -p $pidfile $name - retval=$? - else - success "$name shutdown" - fi - echo - [ $retval -eq 0 ] && rm -f $lockfile - return $retval -} - -restart() { - stop - start -} - -reload() { - false -} - -rh_status() { - status -p $pidfile $name -} - -rh_status_q() { - rh_status >/dev/null 2>&1 -} - - -case "$1" in - start) - rh_status_q && exit 0 - $1 - ;; - stop) - rh_status_q || exit 0 - $1 - ;; - restart) - $1 - ;; - reload) - rh_status_q || exit 7 - $1 - ;; - force-reload) - force_reload - ;; - status) - rh_status - ;; - condrestart|try-restart) - rh_status_q || exit 0 - restart - ;; - *) - echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart}" - exit 2 -esac -exit $?