capistrano-memcached 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/Gemfile +4 -0
- data/LICENSE.md +19 -0
- data/README.md +131 -0
- data/Rakefile +1 -0
- data/capistrano-memcached.gemspec +33 -0
- data/lib/capistrano/dsl/memcached_paths.rb +14 -0
- data/lib/capistrano/memcached/helpers.rb +34 -0
- data/lib/capistrano/memcached/version.rb +5 -0
- data/lib/capistrano/memcached.rb +2 -0
- data/lib/capistrano/tasks/memcached.rake +67 -0
- data/lib/capistrano-memcached.rb +0 -0
- data/lib/generators/capistrano/memcached/USAGE.md +9 -0
- data/lib/generators/capistrano/memcached/config_generator.rb +17 -0
- data/lib/generators/capistrano/memcached/templates/memcached.erb +15 -0
- data/lib/generators/capistrano/memcached/templates/memcached.yml.erb +2 -0
- metadata +119 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2014 Ruben Stranders
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the "Software"),
|
5
|
+
to deal in the Software without restriction, including without limitation
|
6
|
+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
7
|
+
and/or sell copies of the Software, and to permit persons to whom the
|
8
|
+
Software is furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included
|
11
|
+
in all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
14
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
15
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
16
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
17
|
+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
18
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
19
|
+
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
# Capistrano::Memcached
|
2
|
+
|
3
|
+
Capistrano tasks for automatic memcached configuration.
|
4
|
+
|
5
|
+
Goals of this plugin:
|
6
|
+
|
7
|
+
* automatic memcached configuration for Rails apps
|
8
|
+
* **no manual ssh** to the server required
|
9
|
+
|
10
|
+
Specifics:
|
11
|
+
|
12
|
+
* generates config file on the server (default in /etc/memcached.conf)
|
13
|
+
* generates a memcached.yml config file in shared/config for easy consumption by a RoR app
|
14
|
+
* capistrano tasks for management, example: `memcached:restart`<br/>
|
15
|
+
see below for all available tasks
|
16
|
+
|
17
|
+
`capistrano-memcached` works only with Capistrano 3!
|
18
|
+
|
19
|
+
This project was heavily inspired (i.e. copied and reworked) by
|
20
|
+
[capistrano-nginx-unicorn](https://github.com/bruno-/capistrano-nginx-unicorn).
|
21
|
+
|
22
|
+
### Installation
|
23
|
+
|
24
|
+
Add this to `Gemfile`:
|
25
|
+
|
26
|
+
group :development do
|
27
|
+
gem 'capistrano', '~> 3.1'
|
28
|
+
gem 'capistrano-memcached', '~> 1.0'
|
29
|
+
end
|
30
|
+
|
31
|
+
And then:
|
32
|
+
|
33
|
+
$ bundle install
|
34
|
+
|
35
|
+
### Setup and usage
|
36
|
+
|
37
|
+
Add this line to `Capfile`
|
38
|
+
|
39
|
+
require 'capistrano/memcached'
|
40
|
+
|
41
|
+
**Setup task**
|
42
|
+
|
43
|
+
Make sure the `deploy_to` path exists and has the right privileges on the
|
44
|
+
server (i.e. `/var/www/myapp`).<br/>
|
45
|
+
Or just install
|
46
|
+
[capistrano-safe-deploy-to](https://github.com/bruno-/capistrano-safe-deploy-to)
|
47
|
+
plugin and don't think about it.
|
48
|
+
|
49
|
+
To setup the memcached server run:
|
50
|
+
|
51
|
+
$ bundle exec cap production setup
|
52
|
+
|
53
|
+
This will generate the memcached.conf and a memcached.yml file with the hostname + port
|
54
|
+
where memcached is running. This can be used to configure Dalli, for example.
|
55
|
+
|
56
|
+
### Configuration
|
57
|
+
|
58
|
+
As described in the Usage section, this plugin works with minimal setup.
|
59
|
+
However, configuration is possible.
|
60
|
+
|
61
|
+
You'll find the options and their defaults below.
|
62
|
+
|
63
|
+
In order to override the default, put the option in the stage file, for example:
|
64
|
+
|
65
|
+
# in config/deploy/production.rb
|
66
|
+
set :memcached_listen_port, 11212
|
67
|
+
|
68
|
+
Defaults are listed near option name in the first line.
|
69
|
+
|
70
|
+
* `set :memcached_memory_limit` # defaults to 128<br/>
|
71
|
+
The memory limit of memcached in MB.
|
72
|
+
|
73
|
+
* `set :memcached_log_file, "/var/log/memcached.log"`<br/>
|
74
|
+
Location of memcached log file.
|
75
|
+
|
76
|
+
* `set :memcached_port, "11211"`<br/>
|
77
|
+
The port memcached listens on.
|
78
|
+
|
79
|
+
* `set :memcached_ip, "127.0.0.1" # default listen only on localhost (for security) `<br/>
|
80
|
+
The IP memcached listens on.
|
81
|
+
|
82
|
+
* `set :memcached_roles, [:app]`<br/>
|
83
|
+
The roles on which memcached will be installed. `memcached.yml` will be available to all :app roles.
|
84
|
+
|
85
|
+
* `set :memcached_user, "memcache"`<br/>
|
86
|
+
The user account used by memcached.
|
87
|
+
|
88
|
+
|
89
|
+
### Template customization
|
90
|
+
|
91
|
+
If you want to change default templates, you can generate them using
|
92
|
+
`rails generator`:
|
93
|
+
|
94
|
+
$ bundle exec rails g capistrano:memcached:config
|
95
|
+
|
96
|
+
This will copy default templates to `config/deploy/templates` directory, so you
|
97
|
+
can customize them as you like, and capistrano tasks will use this templates
|
98
|
+
instead of default.
|
99
|
+
|
100
|
+
You can also provide path, where to generate templates:
|
101
|
+
|
102
|
+
$ bundle exec rails g capistrano:memcached:config config/templates
|
103
|
+
|
104
|
+
|
105
|
+
### TODO
|
106
|
+
* SASL authentication setup for memcached when running on multiple servers.
|
107
|
+
|
108
|
+
### More Capistrano automation?
|
109
|
+
|
110
|
+
If you'd like to streamline your Capistrano deploys, you might want to check
|
111
|
+
these zero-configuration, plug-n-play plugins:
|
112
|
+
|
113
|
+
- [capistrano-unicorn-nginx](https://github.com/bruno-/capistrano-unicorn-nginx)<br/>
|
114
|
+
no-configuration unicorn and nginx setup with sensible defaults
|
115
|
+
- [capistrano-postgresql](https://github.com/bruno-/capistrano-postgresql)<br/>
|
116
|
+
plugin that automates postgresql configuration and setup
|
117
|
+
- [capistrano-rbenv-install](https://github.com/bruno-/capistrano-rbenv-install)<br/>
|
118
|
+
would you like Capistrano to install rubies for you?
|
119
|
+
- [capistrano-safe-deploy-to](https://github.com/bruno-/capistrano-safe-deploy-to)<br/>
|
120
|
+
if you're annoyed that Capistrano does **not** create a deployment path for the
|
121
|
+
app on the server (default `/var/www/myapp`), this is what you need!
|
122
|
+
|
123
|
+
### Bug reports and pull requests
|
124
|
+
|
125
|
+
...are very welcome!
|
126
|
+
|
127
|
+
### Thanks
|
128
|
+
|
129
|
+
[@bruno-](https://github.com/bruno-) - for his
|
130
|
+
[capistrano-unicorn-nginx](https://github.com/bruno-/capistrano-unicorn-nginx) plugin on which this
|
131
|
+
one is heavily based.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'capistrano/memcached/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "capistrano-memcached"
|
8
|
+
gem.version = Capistrano::Memcached::VERSION
|
9
|
+
gem.authors = ["Ruben Stranders"]
|
10
|
+
gem.email = ["r.stranders@gmail.com"]
|
11
|
+
gem.description = <<-EOF.gsub(/^\s+/, '')
|
12
|
+
Capistrano tasks for automatic and sensible memcached configuration.
|
13
|
+
|
14
|
+
Enables zero downtime deployments of Rails applications. Configs can be
|
15
|
+
copied to the application using generators and easily customized.
|
16
|
+
|
17
|
+
Works *only* with Capistrano 3+.
|
18
|
+
|
19
|
+
Heavily inspired (i.e. copied and reworked) by https://github.com/bruno-/capistrano-unicorn-nginx
|
20
|
+
EOF
|
21
|
+
gem.summary = "Capistrano tasks for automatic and sensible memcached configuration."
|
22
|
+
gem.homepage = "https://github.com/rhomeister/capistrano-memcached"
|
23
|
+
|
24
|
+
gem.files = `git ls-files`.split($/)
|
25
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
26
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
27
|
+
gem.require_paths = ["lib"]
|
28
|
+
|
29
|
+
gem.add_dependency "capistrano", ">= 3.1"
|
30
|
+
gem.add_dependency "sshkit", ">= 1.2.0"
|
31
|
+
|
32
|
+
gem.add_development_dependency "rake"
|
33
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
module Capistrano
|
4
|
+
module Memcached
|
5
|
+
module Helpers
|
6
|
+
|
7
|
+
def mem_template(template_name)
|
8
|
+
config_file = "#{fetch(:templates_path)}/#{template_name}"
|
9
|
+
# if no customized file, proceed with default
|
10
|
+
unless File.exists?(config_file)
|
11
|
+
config_file = File.join(File.dirname(__FILE__), "../../generators/capistrano/memcached/templates/#{template_name}")
|
12
|
+
end
|
13
|
+
StringIO.new(ERB.new(File.read(config_file)).result(binding))
|
14
|
+
end
|
15
|
+
|
16
|
+
def file_exists?(path)
|
17
|
+
test "[ -e #{path} ]"
|
18
|
+
end
|
19
|
+
|
20
|
+
def deploy_user
|
21
|
+
capture :id, '-un'
|
22
|
+
end
|
23
|
+
|
24
|
+
def sudo_upload!(from, to)
|
25
|
+
filename = File.basename(to)
|
26
|
+
to_dir = File.dirname(to)
|
27
|
+
tmp_file = "#{fetch(:tmp_dir)}/#{filename}"
|
28
|
+
upload! from, tmp_file
|
29
|
+
sudo :mv, tmp_file, to_dir
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'capistrano/dsl/memcached_paths'
|
2
|
+
require 'capistrano/memcached/helpers'
|
3
|
+
|
4
|
+
include Capistrano::Memcached::Helpers
|
5
|
+
include Capistrano::DSL::MemcachedPaths
|
6
|
+
|
7
|
+
namespace :load do
|
8
|
+
task :defaults do
|
9
|
+
set :memcached_memory_limit, 128
|
10
|
+
set :memcached_log_file, "/var/log/memcached.log"
|
11
|
+
set :memcached_port, 11211
|
12
|
+
set :memcached_ip, "127.0.0.1" # listen only on localhost (for security)
|
13
|
+
|
14
|
+
# this is where memcached will be installed. A handy memcached.yml file will be created on all :app roles in
|
15
|
+
# shared/config
|
16
|
+
set :memcached_roles, [:app]
|
17
|
+
set :memcached_user, "memcache"
|
18
|
+
|
19
|
+
set :memcached_app_config, -> { memcached_default_app_config_file }
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
namespace :memcached do
|
25
|
+
|
26
|
+
desc "Setup Memcached config file"
|
27
|
+
task :setup do
|
28
|
+
on roles fetch(:memcached_roles) do
|
29
|
+
sudo "useradd #{fetch(:memcached_user)}; true" # create user, but don't fail if it already exists
|
30
|
+
sudo "apt-get", "-y install memcached"
|
31
|
+
|
32
|
+
sudo_upload! mem_template("memcached.erb"), memcached_config_file
|
33
|
+
invoke "memcached:restart"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
desc 'Setup Memcached app configuration'
|
38
|
+
task :setup_app_config do
|
39
|
+
on roles :app do
|
40
|
+
execute :mkdir, '-pv', File.dirname(fetch(:memcached_app_config))
|
41
|
+
upload! mem_template('memcached.yml.erb'), fetch(:memcached_app_config)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
task :memcached_yml_symlink do
|
46
|
+
on roles :app do
|
47
|
+
set :linked_files, fetch(:linked_files, []).push("config/memcached.yml")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
before 'deploy:symlink:linked_files', 'memcached:memcached_yml_symlink'
|
52
|
+
|
53
|
+
%w[start stop restart].each do |command|
|
54
|
+
desc "#{command} Memcached"
|
55
|
+
task command do
|
56
|
+
on roles fetch(:memcached_roles) do
|
57
|
+
sudo :service, "memcached #{command}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
desc 'Server setup tasks'
|
64
|
+
task :setup do
|
65
|
+
invoke 'memcached:setup'
|
66
|
+
invoke 'memcached:setup_app_config'
|
67
|
+
end
|
File without changes
|
@@ -0,0 +1,9 @@
|
|
1
|
+
To create local memcached configuration files call
|
2
|
+
|
3
|
+
bundle exec rails generate capistrano:memcached:config [path]
|
4
|
+
|
5
|
+
The default path is "config/deploy/templates". You can override it like so:
|
6
|
+
|
7
|
+
bundle rails generate capistrano:memcached:config "config/templates"
|
8
|
+
|
9
|
+
If you override templates path, don't forget to set "templates_path" variable in your deploy.rb
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Capistrano
|
2
|
+
module Memcached
|
3
|
+
module Generators
|
4
|
+
class ConfigGenerator < Rails::Generators::Base
|
5
|
+
desc "Create local memcached configuration files for customization"
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
argument :templates_path, type: :string,
|
8
|
+
default: "config/deploy/templates",
|
9
|
+
banner: "path to templates"
|
10
|
+
|
11
|
+
def copy_template
|
12
|
+
copy_file "memcached.erb", "#{templates_path}/memcached.erb"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# run as a daemon
|
2
|
+
-d
|
3
|
+
|
4
|
+
logfile <%= fetch(:memcached_log_file) %>
|
5
|
+
|
6
|
+
# memory limit
|
7
|
+
-m <%= fetch(:memcached_memory_limit) %>
|
8
|
+
|
9
|
+
# port
|
10
|
+
-p <%= fetch(:memcached_port) %>
|
11
|
+
|
12
|
+
# user
|
13
|
+
-u <%= fetch(:memcached_user) %>
|
14
|
+
|
15
|
+
-l <%= fetch(:memcached_ip) %>
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-memcached
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ruben Stranders
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-09-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: capistrano
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.1'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.1'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: sshkit
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.2.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.2.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: ! 'Capistrano tasks for automatic and sensible memcached configuration.
|
63
|
+
|
64
|
+
Enables zero downtime deployments of Rails applications. Configs can be
|
65
|
+
|
66
|
+
copied to the application using generators and easily customized.
|
67
|
+
|
68
|
+
Works *only* with Capistrano 3+.
|
69
|
+
|
70
|
+
Heavily inspired (i.e. copied and reworked) by https://github.com/bruno-/capistrano-unicorn-nginx
|
71
|
+
|
72
|
+
'
|
73
|
+
email:
|
74
|
+
- r.stranders@gmail.com
|
75
|
+
executables: []
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- .gitignore
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.md
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- capistrano-memcached.gemspec
|
85
|
+
- lib/capistrano-memcached.rb
|
86
|
+
- lib/capistrano/dsl/memcached_paths.rb
|
87
|
+
- lib/capistrano/memcached.rb
|
88
|
+
- lib/capistrano/memcached/helpers.rb
|
89
|
+
- lib/capistrano/memcached/version.rb
|
90
|
+
- lib/capistrano/tasks/memcached.rake
|
91
|
+
- lib/generators/capistrano/memcached/USAGE.md
|
92
|
+
- lib/generators/capistrano/memcached/config_generator.rb
|
93
|
+
- lib/generators/capistrano/memcached/templates/memcached.erb
|
94
|
+
- lib/generators/capistrano/memcached/templates/memcached.yml.erb
|
95
|
+
homepage: https://github.com/rhomeister/capistrano-memcached
|
96
|
+
licenses: []
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ! '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 1.8.23
|
116
|
+
signing_key:
|
117
|
+
specification_version: 3
|
118
|
+
summary: Capistrano tasks for automatic and sensible memcached configuration.
|
119
|
+
test_files: []
|