Defined Type: redis::instance

Defined in:
modules/redis/manifests/instance.pp

Overview

Define: redis::instance

Provisions a Redis instance.

Parameters

title

Instance name. To avoid collisions, this value must either be a TCP port number or the absolute path to a UNIX socket. Defaults to the resource title.

settings

A map of Redis configuration directives to their desired value. See <redis.io/topics/config> for documentation.

map

A value can be a hash of settings for the various instances we are defining at the same time, in the form of instance_name => settings. Only overrides to what is the default in settings needs to be defined.

Examples

# Configure a Redis instance on TCP port 6379:
redis::instance { '6379':
  settings => { maxmemory => '2mb' },
}

# Configure a Redis instance on UNIX socket:
redis::instance { '/var/run/redis-primary.sock':
  settings => { maxmemory => '2mb' },
}

# Configure two instances, with 6380 being a slave
redis::instance { ['6379', '6380']:
  settings => { maxmemory => '2mb', slaveof => undef},
  map      => {
    '6380'    => { 'slaveof' => '127.0.0.1 6379'}
  }
}

Parameters:

  • ensure (Wmflib::Ensure) (defaults to: present)
  • settings (Hash) (defaults to: {})
  • map (Hash) (defaults to: {})


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'modules/redis/manifests/instance.pp', line 41

define redis::instance(
    Wmflib::Ensure $ensure   = present,
    Hash           $settings = {},
    Hash           $map = {}
) {

    require redis

    if $title =~ /^[1-9]\d*/ {
        # Listen on TCP port
        $instance_name = "tcp_${title}"
        $port          = $title
        $unixsocket    = ''
    } elsif $title =~ /^\/.*\.sock/ {
        # Listen on UNIX domain socket
        $instance_name = sprintf('unix_%s', basename($title, '.sock'))
        $port          = 0
        $unixsocket    = $title
    } else {
        fail('redis::instance title must be a TCP port or absolute path to UNIX socket.')
    }

    $dbname = "${::hostname}-${title}"
    $defaults = {
        pidfile        => "/var/lib/redis/${instance_name}.pid",
        logfile        => "/var/log/redis/${instance_name}.log",
        port           => $port,
        unixsocket     => $unixsocket,
        daemonize      => true,
        appendfilename => "${dbname}.aof",
        dbfilename     => "${dbname}.rdb",
    }


    file { "/etc/redis/${instance_name}.conf":
        ensure  => $ensure,
        content => template('redis/instance.conf.erb'),
        owner   => 'root',
        group   => 'redis',
        mode    => '0440',
    }

    base::service_unit { "redis-instance-${instance_name}":
        ensure    => $ensure,
        systemd   => systemd_template('redis-instance'),
        subscribe => File["/etc/redis/${instance_name}.conf"],
    }
}