diff --git a/.gitignore b/.gitignore index 37e8aed56..1bccb81ed 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ pkg/ *.swp -/metadata.json \ No newline at end of file +/metadata.json +.forge-releng/ diff --git a/.travis.yml b/.travis.yml index b318a859d..df12da98a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,38 @@ -language: ruby -rvm: - - 1.8.7 -before_script: -after_script: -script: "rake spec" +--- branches: only: - master +language: ruby +bundler_args: --without development +script: bundle exec rake spec SPEC_OPTS='--format documentation' +after_success: + - git clone -q git://github.com/puppetlabs/ghpublisher.git .forge-releng + - .forge-releng/publish +rvm: + - 1.8.7 + - 1.9.3 env: - - PUPPET_VERSION=2.7.13 - - PUPPET_VERSION=2.7.6 - - PUPPET_VERSION=2.6.9 - - PUPPET_VERSION=3.0.0 - - PUPPET_VERSION=3.4.2 + matrix: + - PUPPET_GEM_VERSION="~> 2.7.0" + - PUPPET_GEM_VERSION="~> 3.0.0" + - PUPPET_GEM_VERSION="~> 3.1.0" + - PUPPET_GEM_VERSION="~> 3.2.0" + - PUPPET_GEM_VERSION="~> 3.3.0" + - PUPPET_GEM_VERSION="~> 3.4.0" + global: + - PUBLISHER_LOGIN=saz + - secure: |- + KHycFEf0ALVjITczYG0pcfk912muQkbJiGzKa5yyC8C9ppDW+dTYgDQu8AO1KXFHzds + NUASY2XNjrJNv27w7A2eMp88qU1ID1s8CWALph4fuxGcM/HoPw9q8sldJ9/sHGlY9Ye + DEeIvgt9qkwKtG/kb7dN7la42nv5fffWE95OU= +matrix: + include: + - rvm: 2.0.0 + env: PUPPET_GEM_VERSION="~> 3.2.0" + - rvm: 2.0.0 + env: PUPPET_GEM_VERSION="~> 3.3.0" + - rvm: 1.8.7 + env: PUPPET_GEM_VERSION="~> 2.6.0" notifications: email: false gemfile: Gemfile diff --git a/Modulefile b/Modulefile index cbc63c96c..9d1a8e99a 100644 --- a/Modulefile +++ b/Modulefile @@ -1,5 +1,5 @@ name 'saz-memcached' -version '2.1.0' +version '2.2.4' source 'git://github.com/saz/puppet-memcached.git' author 'saz' license 'Apache License, Version 2.0' diff --git a/README.md b/README.md index 8c212ef4d..fda97f5d9 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,10 @@ -# puppet-memcached - -[![Build Status](https://secure.travis-ci.org/saz/puppet-memcached.png)](http://travis-ci.org/saz/puppet-memcached) +# puppet-memcached [![Build Status](https://secure.travis-ci.org/saz/puppet-memcached.png)](http://travis-ci.org/saz/puppet-memcached) Manage memcached via Puppet +## Show some love +If you find this module useful, send some bitcoins to 1Na3YFUmdxKxJLiuRXQYJU2kiNqA3KY2j9 + ## How to use ### Use roughly 90% of memory @@ -30,12 +31,18 @@ Manage memcached via Puppet ### Other class parameters +* $package_ensure = 'present' * $logfile = '/var/log/memcached.log' +* $max_memory = false +* $item_size = false +* $lock_memory = false (WARNING: good if used intelligently, google for -k key) * $listen_ip = '0.0.0.0' * $tcp_port = 11211 * $udp_port = 11211 * $manage_firewall = false * $user = '' (OS specific setting, see params.pp) * $max_connections = 8192 -* $lock_memory = false (WARNING: good if used intelligently, google for -k key) +* $verbosity = undef +* $unix_socket = undef * $install_dev = false (TRUE if 'libmemcached-dev' package should be installed) +* $processorcount = $::processorcount diff --git a/manifests/init.pp b/manifests/init.pp index 495f3a5cd..ad2f1a3c6 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -3,6 +3,7 @@ $logfile = '/var/log/memcached.log', $manage_firewall = false, $max_memory = false, + $item_size = false, $lock_memory = false, $listen_ip = '0.0.0.0', $tcp_port = 11211, @@ -11,7 +12,8 @@ $max_connections = '8192', $verbosity = undef, $unix_socket = undef, - $install_dev = false + $install_dev = false, + $processorcount = $::processorcount ) inherits memcached::params { # validate type and convert string to boolean if necessary @@ -22,6 +24,12 @@ } validate_bool($manage_firewall_bool) + if $package_ensure == 'absent' { + $service_ensure = 'stopped' + } else { + $service_ensure = 'running' + } + package { $memcached::params::package_name: ensure => $package_ensure, } @@ -56,10 +64,10 @@ } service { $memcached::params::service_name: - ensure => running, + ensure => $service_ensure, enable => true, hasrestart => true, - hasstatus => false, + hasstatus => $memcached::params::service_hasstatus, subscribe => File[$memcached::params::config_file], } } diff --git a/manifests/params.pp b/manifests/params.pp index 5022293c5..ee77e1e1e 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -1,20 +1,22 @@ class memcached::params { case $::osfamily { 'Debian': { - $package_name = 'memcached' - $service_name = 'memcached' - $dev_package_name = 'libmemcached-dev' - $config_file = '/etc/memcached.conf' - $config_tmpl = "$module_name/memcached.conf.erb" - $user = 'nobody' + $package_name = 'memcached' + $service_name = 'memcached' + $service_hasstatus = false + $dev_package_name = 'libmemcached-dev' + $config_file = '/etc/memcached.conf' + $config_tmpl = "${module_name}/memcached.conf.erb" + $user = 'nobody' } 'RedHat': { - $package_name = 'memcached' - $service_name = 'memcached' - $dev_package_name = 'libmemcached-devel' - $config_file = '/etc/sysconfig/memcached' - $config_tmpl = "$module_name/memcached_sysconfig.erb" - $user = 'memcached' + $package_name = 'memcached' + $service_name = 'memcached' + $service_hasstatus = true + $dev_package_name = 'libmemcached-devel' + $config_file = '/etc/sysconfig/memcached' + $config_tmpl = "${module_name}/memcached_sysconfig.erb" + $user = 'memcached' } default: { fail("Unsupported platform: ${::osfamily}") diff --git a/spec/classes/memcached_spec.rb b/spec/classes/memcached_spec.rb index 6bd2a7643..3ab780b1b 100644 --- a/spec/classes/memcached_spec.rb +++ b/spec/classes/memcached_spec.rb @@ -51,12 +51,15 @@ :package_ensure => 'present', :logfile => '/var/log/memcached.log', :max_memory => false, + :item_size => false, :lock_memory => false, :listen_ip => '0.0.0.0', :tcp_port => '11211', :udp_port => '11211', :user => 'nobody', - :max_connections => '8192' + :max_connections => '8192', + :install_dev => false, + :processorcount => 1 } end @@ -65,13 +68,15 @@ :package_ensure => 'latest', :logfile => '/var/log/memcached.log', :max_memory => '2', + :item_size => false, :lock_memory => true, :listen_ip => '127.0.0.1', :tcp_port => '11212', :udp_port => '11213', :user => 'somebdy', :max_connections => '8193', - :verbosity => 'vvv' + :verbosity => 'vvv', + :processorcount => 3 }, { :package_ensure => 'present', @@ -83,7 +88,9 @@ :udp_port => '11213', :user => 'somebdy', :max_connections => '8193', - :verbosity => 'vvv' + :verbosity => 'vvv', + :install_dev => true, + :processorcount => 1 } ].each do |param_set| describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do @@ -108,19 +115,25 @@ describe "on supported osfamily: #{osfamily}" do - it { should contain_class('memcached::params') } + it { should contain_class("memcached::params") } - it { should contain_package('memcached').with_ensure(param_hash[:package_ensure]) } + it { should contain_package("memcached").with_ensure(param_hash[:package_ensure]) } it { should_not contain_firewall('100_tcp_11211_for_memcached') } it { should_not contain_firewall('100_udp_11211_for_memcached') } - it { should contain_file('/etc/memcached.conf').with( + it { + if param_hash[:install_dev] + should contain_package("libmemcached-dev").with_ensure(param_hash[:package_ensure]) + end + } + + it { should contain_file("/etc/memcached.conf").with( 'owner' => 'root', 'group' => 'root' )} - it { should contain_service('memcached').with( + it { should contain_service("memcached").with( 'ensure' => 'running', 'enable' => true, 'hasrestart' => true, @@ -141,7 +154,7 @@ "-U #{param_hash[:udp_port]}", "-u #{param_hash[:user]}", "-c #{param_hash[:max_connections]}", - "-t #{facts[:processorcount]}" + "-t #{param_hash[:processorcount]}" ] if(param_hash[:max_memory]) if(param_hash[:max_memory].end_with?('%')) diff --git a/templates/memcached.conf.erb b/templates/memcached.conf.erb index 03344d5da..9b48ce9e4 100644 --- a/templates/memcached.conf.erb +++ b/templates/memcached.conf.erb @@ -7,16 +7,16 @@ -P /var/run/memcached.pid # Log memcached's output -logfile <%= logfile -%> +logfile <%= @logfile -%> <% if @verbosity -%> # Verbosity --<%= verbosity %> +-<%= @verbosity %> <% end -%> # Use MB memory max to use for object storage. <% Puppet::Parser::Functions.function('memcached_max_memory') -%> --m <%= scope.function_memcached_max_memory([max_memory]) %> +-m <%= scope.function_memcached_max_memory([@max_memory]) %> <% if @lock_memory -%> # Lock down all paged memory. There is a limit on how much memory you may lock. @@ -25,23 +25,29 @@ logfile <%= logfile -%> <% if @unix_socket -%> # UNIX socket path to listen on --s <%= unix_socket %> +-s <%= @unix_socket %> <% else -%> # IP to listen on --l <%= listen_ip %> +-l <%= @listen_ip %> # TCP port to listen on --p <%= tcp_port %> +-p <%= @tcp_port %> # UDP port to listen on --U <%= udp_port %> +-U <%= @udp_port %> <% end -%> # Run daemon as user --u <%= user %> +-u <%= @user %> # Limit the number of simultaneous incoming connections. --c <%= max_connections %> +-c <%= @max_connections %> # Number of threads to use to process incoming requests. --t <%= processorcount %> +-t <%= @processorcount %> + +<% if @item_size -%> +# Override the default size of each slab page +-I <%= @item_size %> +<% end -%> + diff --git a/templates/memcached_sysconfig.erb b/templates/memcached_sysconfig.erb index 3c980309b..9f20c5895 100644 --- a/templates/memcached_sysconfig.erb +++ b/templates/memcached_sysconfig.erb @@ -1,21 +1,24 @@ -PORT="<%= tcp_port %>" -USER="<%= user %>" -MAXCONN="<%= max_connections %>" +PORT="<%= @tcp_port %>" +USER="<%= @user %>" +MAXCONN="<%= @max_connections %>" <% Puppet::Parser::Functions.function('memcached_max_memory') -%> -CACHESIZE="<%= scope.function_memcached_max_memory([max_memory]) %>" +CACHESIZE="<%= scope.function_memcached_max_memory([@max_memory]) %>" OPTIONS="<% result = [] if @verbosity - result << '-' + verbosity + result << '-' + @verbosity end if @lock_memory result << '-k' end if @listen_ip - result << '-l ' + listen_ip + result << '-l ' + @listen_ip end if @udp_port - result << '-U ' + udp_port + result << '-U ' + @udp_port end -result << '-t ' + processorcount +if @item_size + result << '-I ' + @item_size +end +result << '-t ' + @processorcount -%><%= result.join(' ') -%>"