Skip to content

Commit 0e45c9a

Browse files
committed
cleanup some multi instance things
1 parent b8375f9 commit 0e45c9a

2 files changed

Lines changed: 41 additions & 46 deletions

File tree

manifests/init.pp

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@
33
# Manage memcached
44
#
55
class memcached (
6-
$package_ensure = 'present',
7-
$manage_firewall = false,
8-
$max_memory = false,
9-
$item_size = false,
10-
$lock_memory = false,
11-
$listen_ip = '0.0.0.0',
12-
$tcp_port = 11211,
13-
$udp_port = 11211,
14-
$user = $::memcached::params::user,
15-
$max_connections = '8192',
16-
$verbosity = undef,
17-
$unix_socket = undef,
18-
$install_dev = false,
19-
$processorcount = $::processorcount,
20-
$service_restart = true,
21-
$auto_removal = false,
22-
$use_sasl = false,
23-
$use_registry = $::memcached::params::use_registry,
24-
$registry_key = 'HKLM\System\CurrentControlSet\services\memcached\ImagePath',
25-
$large_mem_pages = false,
26-
$default_instance = true,
27-
$instance_configs = hiera_hash('memcached::instance_configs', undef),
6+
$package_ensure = 'present',
7+
$manage_firewall = false,
8+
$max_memory = false,
9+
$item_size = false,
10+
$lock_memory = false,
11+
$listen_ip = '0.0.0.0',
12+
$tcp_port = 11211,
13+
$udp_port = 11211,
14+
$user = $::memcached::params::user,
15+
$max_connections = '8192',
16+
$verbosity = undef,
17+
$unix_socket = undef,
18+
$install_dev = false,
19+
$processorcount = $::processorcount,
20+
$service_restart = true,
21+
$auto_removal = false,
22+
$use_sasl = false,
23+
$use_registry = $::memcached::params::use_registry,
24+
$registry_key = 'HKLM\System\CurrentControlSet\services\memcached\ImagePath',
25+
$large_mem_pages = false,
26+
$default_instance = true,
27+
$instance_configs = hiera_hash('memcached::instance_configs', {})
2828
) inherits memcached::params {
2929

3030
if $package_ensure == 'absent' {
@@ -60,15 +60,11 @@
6060
},
6161
}
6262

63-
if $default_instance and is_hash($instance_configs) {
64-
validate_hash($instance_configs)
63+
validate_hash($instance_configs)
64+
65+
if $default_instance {
6566
$final_configs = merge($default_configs, $instance_configs)
66-
}
67-
elsif $default_instance {
68-
$final_configs = $default_configs
69-
}
70-
elsif is_hash($instance_configs) {
71-
validate_hash($instance_configs)
67+
} else {
7268
$final_configs = $instance_configs
7369
}
7470

@@ -86,5 +82,4 @@
8682
}
8783

8884
create_resources(memcached::instance, $final_configs)
89-
9085
}

manifests/instance.pp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,20 @@
2121
$use_sasl = false,
2222
$large_mem_pages = false,
2323
$service_ensure = 'running',
24-
$service_enable = true,
24+
$service_enable = true
2525
) {
2626

2727
include ::memcached::params
2828

29+
# validate type and convert string to boolean if necessary
30+
if is_string($manage_firewall) {
31+
$manage_firewall_bool = str2bool($manage_firewall)
32+
} else {
33+
$manage_firewall_bool = $manage_firewall
34+
}
35+
validate_bool($manage_firewall_bool)
36+
validate_bool($service_restart)
37+
2938
# This is needed only if instances are exclusively defined rather than using the base class
3039
if ! defined(Class['::memcached::package']) {
3140
class { '::memcached::package':
@@ -37,19 +46,6 @@
3746
$user = $memcached::params::user
3847
$pidfile = "/var/run/memcached_${tcp_port}.pid"
3948

40-
if $::osfamily != 'Windows' {
41-
$logfile = "/var/log/memcached_${tcp_port}.log"
42-
}
43-
44-
# validate type and convert string to boolean if necessary
45-
if is_string($manage_firewall) {
46-
$manage_firewall_bool = str2bool($manage_firewall)
47-
} else {
48-
$manage_firewall_bool = $manage_firewall
49-
}
50-
validate_bool($manage_firewall_bool)
51-
validate_bool($service_restart)
52-
5349
if $manage_firewall_bool == true {
5450
firewall { "100_tcp_${tcp_port}_for_memcached":
5551
port => $tcp_port,
@@ -67,15 +63,19 @@
6763
case $::osfamily {
6864
'Debian': {
6965
$config_file = "/etc/memcached_${tcp_port}.conf"
66+
$logfile = "/var/log/memcached_${tcp_port}.log"
7067
$service_name = 'memcached'
68+
$init_script = false
7169
# We don't manage the init script for Debian
7270
}
7371
'Windows': {
7472
$config_file = undef
7573
$service_name = 'memcached'
74+
$init_script = false
7675
}
7776
default: {
7877
$config_file = "/etc/sysconfig/memcached_${tcp_port}"
78+
$logfile = "/var/log/memcached_${tcp_port}.log"
7979
$service_name = "memcached_${tcp_port}"
8080
$init_script = "/etc/init.d/memcached_${tcp_port}"
8181
}
@@ -98,7 +98,7 @@
9898
}
9999
}
100100

101-
if $::osfamily != 'Debian' {
101+
if $init_script {
102102
file { $init_script:
103103
owner => 'root',
104104
group => 'root',

0 commit comments

Comments
 (0)