Skip to content

Commit

Permalink
cleanup some multi instance things
Browse files Browse the repository at this point in the history
  • Loading branch information
saz committed May 25, 2015
1 parent b8375f9 commit 0e45c9a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 46 deletions.
57 changes: 26 additions & 31 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
# Manage memcached
#
class memcached (
$package_ensure = 'present',
$manage_firewall = false,
$max_memory = false,
$item_size = false,
$lock_memory = false,
$listen_ip = '0.0.0.0',
$tcp_port = 11211,
$udp_port = 11211,
$user = $::memcached::params::user,
$max_connections = '8192',
$verbosity = undef,
$unix_socket = undef,
$install_dev = false,
$processorcount = $::processorcount,
$service_restart = true,
$auto_removal = false,
$use_sasl = false,
$use_registry = $::memcached::params::use_registry,
$registry_key = 'HKLM\System\CurrentControlSet\services\memcached\ImagePath',
$large_mem_pages = false,
$default_instance = true,
$instance_configs = hiera_hash('memcached::instance_configs', undef),
$package_ensure = 'present',
$manage_firewall = false,
$max_memory = false,
$item_size = false,
$lock_memory = false,
$listen_ip = '0.0.0.0',
$tcp_port = 11211,
$udp_port = 11211,
$user = $::memcached::params::user,
$max_connections = '8192',
$verbosity = undef,
$unix_socket = undef,
$install_dev = false,
$processorcount = $::processorcount,
$service_restart = true,
$auto_removal = false,
$use_sasl = false,
$use_registry = $::memcached::params::use_registry,
$registry_key = 'HKLM\System\CurrentControlSet\services\memcached\ImagePath',
$large_mem_pages = false,
$default_instance = true,
$instance_configs = hiera_hash('memcached::instance_configs', {})
) inherits memcached::params {

if $package_ensure == 'absent' {
Expand Down Expand Up @@ -60,15 +60,11 @@
},
}

if $default_instance and is_hash($instance_configs) {
validate_hash($instance_configs)
validate_hash($instance_configs)

if $default_instance {
$final_configs = merge($default_configs, $instance_configs)
}
elsif $default_instance {
$final_configs = $default_configs
}
elsif is_hash($instance_configs) {
validate_hash($instance_configs)
} else {
$final_configs = $instance_configs
}

Expand All @@ -86,5 +82,4 @@
}

create_resources(memcached::instance, $final_configs)

}
30 changes: 15 additions & 15 deletions manifests/instance.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,20 @@
$use_sasl = false,
$large_mem_pages = false,
$service_ensure = 'running',
$service_enable = true,
$service_enable = true
) {

include ::memcached::params

# validate type and convert string to boolean if necessary
if is_string($manage_firewall) {
$manage_firewall_bool = str2bool($manage_firewall)
} else {
$manage_firewall_bool = $manage_firewall
}
validate_bool($manage_firewall_bool)
validate_bool($service_restart)

# This is needed only if instances are exclusively defined rather than using the base class
if ! defined(Class['::memcached::package']) {
class { '::memcached::package':
Expand All @@ -37,19 +46,6 @@
$user = $memcached::params::user
$pidfile = "/var/run/memcached_${tcp_port}.pid"

if $::osfamily != 'Windows' {
$logfile = "/var/log/memcached_${tcp_port}.log"
}

# validate type and convert string to boolean if necessary
if is_string($manage_firewall) {
$manage_firewall_bool = str2bool($manage_firewall)
} else {
$manage_firewall_bool = $manage_firewall
}
validate_bool($manage_firewall_bool)
validate_bool($service_restart)

if $manage_firewall_bool == true {
firewall { "100_tcp_${tcp_port}_for_memcached":
port => $tcp_port,
Expand All @@ -67,15 +63,19 @@
case $::osfamily {
'Debian': {
$config_file = "/etc/memcached_${tcp_port}.conf"
$logfile = "/var/log/memcached_${tcp_port}.log"
$service_name = 'memcached'
$init_script = false
# We don't manage the init script for Debian
}
'Windows': {
$config_file = undef
$service_name = 'memcached'
$init_script = false
}
default: {
$config_file = "/etc/sysconfig/memcached_${tcp_port}"
$logfile = "/var/log/memcached_${tcp_port}.log"
$service_name = "memcached_${tcp_port}"
$init_script = "/etc/init.d/memcached_${tcp_port}"
}
Expand All @@ -98,7 +98,7 @@
}
}

if $::osfamily != 'Debian' {
if $init_script {
file { $init_script:
owner => 'root',
group => 'root',
Expand Down

0 comments on commit 0e45c9a

Please sign in to comment.