Initial commit
This commit is contained in:
commit
7d45dfd343
|
@ -0,0 +1,2 @@
|
|||
pkg/
|
||||
*.swp
|
|
@ -0,0 +1,8 @@
|
|||
name 'saz-memcached'
|
||||
version '2.0.2'
|
||||
source 'git://github.com/saz/puppet-memcached.git'
|
||||
author 'saz'
|
||||
license 'Apache License, Version 2.0'
|
||||
summary 'UNKNOWN'
|
||||
description 'Manage memcached via Puppet'
|
||||
project_page 'https://github.com/saz/puppet-memcached'
|
|
@ -0,0 +1,9 @@
|
|||
In order to run tests:
|
||||
- puppet and facter must be installed and available in Ruby's LOADPATH
|
||||
- the latest revision of rspec-puppet must be installed
|
||||
- rake, and rspec2 must be install
|
||||
|
||||
- the name of the module directory needs to be memcached
|
||||
|
||||
to run all tests:
|
||||
rake spec
|
|
@ -0,0 +1,29 @@
|
|||
|
||||
# puppet-memcached
|
||||
|
||||
Manage memcached via Puppet
|
||||
|
||||
## How to use
|
||||
|
||||
### Use roughly 90% of memory
|
||||
|
||||
```
|
||||
class { 'memcached': }
|
||||
```
|
||||
|
||||
### Set a fixed memory limit in MB
|
||||
|
||||
```
|
||||
class { 'memcached':
|
||||
max_memory => 2048
|
||||
}
|
||||
```
|
||||
|
||||
### Other class parameters
|
||||
|
||||
* $logfile = '/var/log/memcached.log'
|
||||
* $listen_ip = '0.0.0.0'
|
||||
* $tcp_port = 11211
|
||||
* $udp_port = 11211
|
||||
* $user = '' (OS specific setting, see params.pp)
|
||||
* $max_connections = 8192
|
|
@ -0,0 +1,18 @@
|
|||
require 'rubygems'
|
||||
require 'rake'
|
||||
require 'rspec/core/rake_task'
|
||||
|
||||
task :default => [:spec]
|
||||
|
||||
desc "Run all module spec tests (Requires rspec-puppet gem)"
|
||||
RSpec::Core::RakeTask.new(:spec) do |t|
|
||||
t.rspec_opts = ['--color']
|
||||
# ignores fixtures directory.
|
||||
t.pattern = 'spec/{classes,defines,unit}/**/*_spec.rb'
|
||||
end
|
||||
|
||||
desc "Build package"
|
||||
task :build do
|
||||
system("puppet-module build")
|
||||
end
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
class memcached(
|
||||
$package_ensure = 'present',
|
||||
$logfile = '/var/log/memcached.log',
|
||||
$max_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
|
||||
) inherits memcached::params {
|
||||
|
||||
package { $memcached::params::package_name:
|
||||
ensure => $package_ensure,
|
||||
}
|
||||
|
||||
file { $memcached::params::config_file:
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0644',
|
||||
content => template($memcached::params::config_tmpl),
|
||||
require => Package[$memcached::params::package_name],
|
||||
}
|
||||
|
||||
service { $memcached::params::service_name:
|
||||
ensure => running,
|
||||
enable => true,
|
||||
hasrestart => true,
|
||||
hasstatus => false,
|
||||
subscribe => File[$memcached::params::config_file],
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
class memcached::params {
|
||||
case $::osfamily {
|
||||
'Debian': {
|
||||
$package_name = 'memcached'
|
||||
$service_name = 'memcached'
|
||||
$config_file = '/etc/memcached.conf'
|
||||
$config_tmpl = "${module_name}/memcached.conf.erb"
|
||||
$user = 'nobody'
|
||||
}
|
||||
'RedHat': {
|
||||
$package_name = 'memcached'
|
||||
$service_name = 'memcached'
|
||||
$config_file = '/etc/sysconfig/memcached'
|
||||
$config_tmpl = "${module_name}/memcached_sysconfig.erb"
|
||||
$user = 'memcached'
|
||||
}
|
||||
default: {
|
||||
fail("Unsupported platform: ${::osfamily}")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
require 'spec_helper'
|
||||
describe 'memcached' do
|
||||
|
||||
let :default_params do
|
||||
{
|
||||
:package_ensure => 'present',
|
||||
:logfile => '/var/log/memcached.log',
|
||||
:max_memory => false,
|
||||
:listen_ip => '0.0.0.0',
|
||||
:tcp_port => '11211',
|
||||
:udp_port => '11211',
|
||||
:user => 'nobody',
|
||||
:max_connections => '8192'
|
||||
}
|
||||
end
|
||||
|
||||
[ {},
|
||||
{
|
||||
:package_ensure => 'latest',
|
||||
:logfile => '/var/log/memcached.log',
|
||||
:max_memory => '2',
|
||||
:listen_ip => '127.0.0.1',
|
||||
:tcp_port => '11212',
|
||||
:udp_port => '11213',
|
||||
:user => 'somebdy',
|
||||
:max_connections => '8193'
|
||||
}
|
||||
].each do |param_set|
|
||||
describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
|
||||
|
||||
let :param_hash do
|
||||
default_params.merge(param_set)
|
||||
end
|
||||
|
||||
let :params do
|
||||
param_set
|
||||
end
|
||||
|
||||
['Debian'].each do |osfamily|
|
||||
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => osfamily,
|
||||
:memorysize => '1',
|
||||
:processorcount => '1',
|
||||
}
|
||||
end
|
||||
|
||||
describe "on supported osfamily: #{osfamily}" do
|
||||
|
||||
it { should contain_class('memcached::params') }
|
||||
|
||||
it { should contain_package('memcached').with_ensure(param_hash[:package_ensure]) }
|
||||
|
||||
it { should contain_file('/etc/memcached.conf').with(
|
||||
'owner' => 'root',
|
||||
'group' => 'root'
|
||||
)}
|
||||
|
||||
it { should contain_service('memcached').with(
|
||||
'ensure' => 'running',
|
||||
'enable' => true,
|
||||
'hasrestart' => true,
|
||||
'hasstatus' => false
|
||||
)}
|
||||
|
||||
it 'should compile the template based on the class parameters' do
|
||||
content = param_value(
|
||||
subject,
|
||||
'file',
|
||||
'/etc/memcached.conf',
|
||||
'content'
|
||||
)
|
||||
expected_lines = [
|
||||
"logfile #{param_hash[:logfile]}",
|
||||
"-l #{param_hash[:listen_ip]}",
|
||||
"-p #{param_hash[:tcp_port]}",
|
||||
"-U #{param_hash[:udp_port]}",
|
||||
"-u #{param_hash[:user]}",
|
||||
"-c #{param_hash[:max_connections]}",
|
||||
"-t #{facts[:processorcount]}"
|
||||
]
|
||||
if(param_hash[:max_memory])
|
||||
expected_lines.push("-m #{param_hash[:max_memory]}")
|
||||
else
|
||||
expected_lines.push("-m #{((facts[:memorysize].to_f*1024)*0.95).floor}")
|
||||
end
|
||||
(content.split("\n") & expected_lines).should =~ expected_lines
|
||||
end
|
||||
end
|
||||
end
|
||||
['Redhat'].each do |osfamily|
|
||||
describe 'on supported platform' do
|
||||
it 'should fail' do
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,6 @@
|
|||
--format
|
||||
s
|
||||
--colour
|
||||
--loadby
|
||||
mtime
|
||||
--backtrace
|
|
@ -0,0 +1,13 @@
|
|||
require 'puppet'
|
||||
require 'rubygems'
|
||||
require 'rspec-puppet'
|
||||
|
||||
# get the value of a certain parameter
|
||||
def param_value(subject, type, title, param)
|
||||
subject.resource(type, title).send(:parameters)[param.to_sym]
|
||||
end
|
||||
|
||||
RSpec.configure do |c|
|
||||
c.module_path = File.join(File.dirname(__FILE__), '../../')
|
||||
c.manifest_dir = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures/manifests'))
|
||||
end
|
|
@ -0,0 +1,46 @@
|
|||
# File managed by puppet
|
||||
|
||||
# Run memcached as a daemon.
|
||||
-d
|
||||
|
||||
# pidfile
|
||||
-P /var/run/memcached.pid
|
||||
|
||||
# Log memcached's output
|
||||
logfile <%= logfile %>
|
||||
|
||||
<% if @verbosity -%>
|
||||
# Verbosity
|
||||
-<%= verbosity %>
|
||||
<% end -%>
|
||||
|
||||
# Use <num> MB memory max to use for object storage.
|
||||
<% if max_memory -%>
|
||||
-m <%= max_memory %>
|
||||
<% else -%>
|
||||
-m <%= ((memorysize.to_f*1024)*0.95).floor %>
|
||||
<% end -%>
|
||||
|
||||
<% if @unix_socket -%>
|
||||
# UNIX socket path to listen on
|
||||
-s <%= unix_socket %>
|
||||
<% else -%>
|
||||
|
||||
# IP to listen on
|
||||
-l <%= listen_ip %>
|
||||
|
||||
# TCP port to listen on
|
||||
-p <%= tcp_port %>
|
||||
|
||||
# UDP port to listen on
|
||||
-U <%= udp_port %>
|
||||
<% end -%>
|
||||
|
||||
# Run daemon as user
|
||||
-u <%= user %>
|
||||
|
||||
# Limit the number of simultaneous incoming connections.
|
||||
-c <%= max_connections %>
|
||||
|
||||
# Number of threads to use to process incoming requests.
|
||||
-t <%= processorcount %>
|
|
@ -0,0 +1,5 @@
|
|||
PORT="<%= udp_port %>"
|
||||
USER="<%= user %>"
|
||||
MAXCONN="<%= max_connections %>"
|
||||
CACHESIZE="<%= max_memory %>"
|
||||
OPTIONS=""
|
|
@ -0,0 +1 @@
|
|||
include memcached
|
Loading…
Reference in New Issue