obs-recipes 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +11 -0
- data/VERSION.yml +4 -0
- data/lib/helpers.rb +22 -0
- data/lib/obs_recipes.rb +5 -0
- data/lib/recipes/monit.rb +72 -0
- data/lib/recipes/nginx.rb +10 -0
- data/lib/recipes/rails.rb +22 -0
- data/lib/templates/database.yml.erb +13 -0
- data/lib/templates/monit/global.erb +8 -0
- data/lib/templates/monit/mongrels.erb +12 -0
- data/lib/templates/monit/mysql.erb +8 -0
- data/lib/templates/monit/nginx.erb +7 -0
- data/lib/templates/monit/sshd.erb +5 -0
- data/lib/templates/nginx.erb +132 -0
- data/obs-recipes.gemspec +45 -0
- metadata +78 -0
data/Rakefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
Rake::RDocTask.new do |rdoc|
|
6
|
+
rdoc.rdoc_dir = 'rdoc'
|
7
|
+
rdoc.title = 'obs-recipes'
|
8
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
9
|
+
rdoc.rdoc_files.include('README*')
|
10
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
11
|
+
end
|
data/VERSION.yml
ADDED
data/lib/helpers.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
def environment
|
2
|
+
if exists?(:stage)
|
3
|
+
stage
|
4
|
+
elsif exists?(:rails_env)
|
5
|
+
rails_env
|
6
|
+
elsif(ENV['RAILS_ENV'])
|
7
|
+
ENV['RAILS_ENV']
|
8
|
+
else
|
9
|
+
"production"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def template_for(name)
|
14
|
+
name<<".erb" unless name.include?(".erb")
|
15
|
+
template = File.join(File.dirname(__FILE__),"templates",name)
|
16
|
+
ERB.new(File.read(template))
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
def run_rake(task)
|
21
|
+
run "cd #{current_path} && rake #{task} RAILS_ENV=#{environment}"
|
22
|
+
end
|
data/lib/obs_recipes.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
2
|
+
def upload_monit(name,content)
|
3
|
+
put(content,deploy_to+"/#{name}.monitrc")
|
4
|
+
sudo 'mkdir /etc/monit.d' rescue nil
|
5
|
+
run "mv #{deploy_to}/#{name}.monitrc /etc/monit.d/"
|
6
|
+
end
|
7
|
+
|
8
|
+
def monit_reload
|
9
|
+
sudo("monit reload")
|
10
|
+
end
|
11
|
+
|
12
|
+
if defined?(USE_MONIT)
|
13
|
+
namespace :deploy do
|
14
|
+
task :restart do
|
15
|
+
sudo "monit -g #{application} stop all"
|
16
|
+
sleep 10
|
17
|
+
sudo "monit -g #{application} start all"
|
18
|
+
end
|
19
|
+
|
20
|
+
task :start do |t|
|
21
|
+
sudo "monit -g #{application} start all"
|
22
|
+
end
|
23
|
+
|
24
|
+
task :stop do |t|
|
25
|
+
sudo "monit -g #{application} stop all"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
namespace :monit do
|
31
|
+
task :setup do
|
32
|
+
end
|
33
|
+
|
34
|
+
task :reload do
|
35
|
+
sudo "monit reload"
|
36
|
+
end
|
37
|
+
|
38
|
+
task :mysql,:only=>[:db] do
|
39
|
+
upload_monit("mysql",template_for("monit/mysql").result(binding))
|
40
|
+
end
|
41
|
+
|
42
|
+
task :nginx,:only=>[:web] do
|
43
|
+
upload_monit("nginx",template_for("monit/nginx").result(binding))
|
44
|
+
end
|
45
|
+
|
46
|
+
task :mongrels,:only=>[:web] do
|
47
|
+
upload_monit("mongrels",template_for("monit/mongrels").result(binding))
|
48
|
+
end
|
49
|
+
|
50
|
+
task :sshd,:only=>[:web] do
|
51
|
+
upload_monit("sshd",template_for("monit/sshd").result(binding))
|
52
|
+
end
|
53
|
+
|
54
|
+
task :global do
|
55
|
+
conf = template_for("monit/global").result(binding)
|
56
|
+
put(conf,deploy_to+"/monitrc")
|
57
|
+
sudo("mv #{deploy_to}/monitrc /etc/monit/monitrc")
|
58
|
+
sudo("chmod 0700 /etc/monit/monitrc")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def config_path
|
63
|
+
"#{current_release}/config/"
|
64
|
+
end
|
65
|
+
|
66
|
+
def shared_config_path
|
67
|
+
"#{shared_path}/config/"
|
68
|
+
end
|
69
|
+
|
70
|
+
before "monit:setup","monit:global"
|
71
|
+
after "monit:setup","monit:reload"
|
72
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
2
|
+
namespace :nginx do
|
3
|
+
task :setup, :roles=>:web do
|
4
|
+
config = template_for("nginx").result(binding)
|
5
|
+
put config,"#{deploy_to}/nginx.conf"
|
6
|
+
sudo "mv #{deploy_to}/nginx.conf /etc/nginx/"
|
7
|
+
sudo "/etc/init.d/nginx restart"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
2
|
+
set :dbhost, 'localhost' unless exists?(:dbhost)
|
3
|
+
set :dbadaptor, 'mysql' unless exists?(:dbadaptor)
|
4
|
+
|
5
|
+
|
6
|
+
namespace :rails do
|
7
|
+
task :database, :roles=>[:app,:web] do
|
8
|
+
config = template_for("database.yml").result(binding)
|
9
|
+
put config,"#{deploy_to}/shared/database.yml"
|
10
|
+
end
|
11
|
+
|
12
|
+
task :database_link,:roles=>[:app,:web] do
|
13
|
+
run "ln #{deploy_to}/shared/database.yml #{release_path}/config/database.yml"
|
14
|
+
end
|
15
|
+
|
16
|
+
task :log_link,:roles=>[:app,:web] do
|
17
|
+
run "mkdir #{deploy_to}/shared/log" rescue nil
|
18
|
+
run "ln -nfs #{deploy_to}/shared/log #{release_path}/log"
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<% mongrels_in_cluster.times do |i| %>
|
2
|
+
<% id = (8000+i).to_s %>
|
3
|
+
<% pid = "#{deploy_to}/current/log/mongrel.#{id}.pid" %>
|
4
|
+
check process mongrel_<%= id %>
|
5
|
+
with pidfile <%= pid %>
|
6
|
+
start program = "/usr/bin/mongrel_rails start -d -e production -c <%= deploy_to %>/current --port=<%= id %> --pid=<%= pid %> " as uid <%= user %> and gid <%= group %>
|
7
|
+
stop program = "/usr/bin/mongrel_rails stop -c <%= deploy_to %>/current --pid=<%= pid %>" as uid <%= user %> and gid <%= group %>
|
8
|
+
if totalmem is greater than 200 MB for 2 cycles then restart
|
9
|
+
if cpu > 80% for 5 cycles then restart
|
10
|
+
if failed host 127.0.0.1 port <%=id %> then restart
|
11
|
+
group <%= application %>
|
12
|
+
<% end %>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
check process mysql with pidfile /var/run/mysqld/mysqld.pid
|
2
|
+
start program = "/etc/init.d/mysql start"
|
3
|
+
stop program = "/etc/init.d/mysql stop"
|
4
|
+
if failed host 127.0.0.1 port 3306 then restart
|
5
|
+
if 5 restarts within 5 cycles then timeout
|
6
|
+
if cpu > 99% for 5 cycles then restart
|
7
|
+
if cpu > 80% for 30 cycles then restart
|
8
|
+
group database
|
@@ -0,0 +1,132 @@
|
|
1
|
+
# user and group to run as
|
2
|
+
user www-data;
|
3
|
+
|
4
|
+
# number of nginx workers
|
5
|
+
worker_processes 2;
|
6
|
+
|
7
|
+
# pid of nginx master process
|
8
|
+
pid /var/run/nginx.pid;
|
9
|
+
|
10
|
+
# Number of worker connections. 1024 is a good default
|
11
|
+
events {
|
12
|
+
worker_connections 1024;
|
13
|
+
}
|
14
|
+
|
15
|
+
# start the http module where we config http access.
|
16
|
+
http {
|
17
|
+
# pull in mime-types. You can break out your config
|
18
|
+
# into as many include's as you want to make it cleaner
|
19
|
+
include /etc/nginx/mime.types;
|
20
|
+
|
21
|
+
# set a default type for the rare situation that
|
22
|
+
# nothing matches from the mimie-type include
|
23
|
+
default_type application/octet-stream;
|
24
|
+
|
25
|
+
# configure log format
|
26
|
+
log_format main '$remote_addr - $remote_user [$time_local] '
|
27
|
+
'"$request" $status $body_bytes_sent "$http_referer" '
|
28
|
+
'"$http_user_agent" "$http_x_forwarded_for"';
|
29
|
+
|
30
|
+
# main access log
|
31
|
+
access_log /var/log/nginx_access.log main;
|
32
|
+
|
33
|
+
# main error log
|
34
|
+
error_log /var/log/nginx_error.log debug;
|
35
|
+
|
36
|
+
# no sendfile on OSX
|
37
|
+
sendfile on;
|
38
|
+
|
39
|
+
# These are good default values.
|
40
|
+
tcp_nopush on;
|
41
|
+
tcp_nodelay off;
|
42
|
+
# output compression saves bandwidth
|
43
|
+
gzip on;
|
44
|
+
gzip_http_version 1.0;
|
45
|
+
gzip_comp_level 2;
|
46
|
+
gzip_proxied any;
|
47
|
+
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml
|
48
|
+
application/xml+rss text/javascript;
|
49
|
+
|
50
|
+
|
51
|
+
# this is where you define your mongrel clusters.
|
52
|
+
# you need one of these blocks for each cluster
|
53
|
+
# and each one needs its own name to refer to it later.
|
54
|
+
upstream mongrel {
|
55
|
+
<% mongrels_in_cluster.times do |i| %>
|
56
|
+
server 127.0.0.1:800<%= i %>;
|
57
|
+
<% end %>
|
58
|
+
}
|
59
|
+
|
60
|
+
|
61
|
+
# the server directive is nginx's virtual host directive.
|
62
|
+
server {
|
63
|
+
# port to listen on. Can also be set to an IP:PORT
|
64
|
+
listen 80;
|
65
|
+
|
66
|
+
# Set the max size for file uploads to 50Mb
|
67
|
+
client_max_body_size 50M;
|
68
|
+
|
69
|
+
# sets the domain[s] that this vhost server requests for
|
70
|
+
# server_name www.[engineyard].com [engineyard].com;
|
71
|
+
|
72
|
+
# doc root
|
73
|
+
root <%= deploy_to %>/current/public;
|
74
|
+
|
75
|
+
# vhost specific access log
|
76
|
+
access_log /var/log/nginx.vhost.access.log main;
|
77
|
+
|
78
|
+
# this rewrites all the requests to the maintenance.html
|
79
|
+
# page if it exists in the doc root. This is for capistrano's
|
80
|
+
# disable web task
|
81
|
+
if (-f $document_root/system/maintenance.html) {
|
82
|
+
rewrite ^(.*)$ /system/maintenance.html last;
|
83
|
+
break;
|
84
|
+
}
|
85
|
+
|
86
|
+
location / {
|
87
|
+
# needed to forward user's IP address to rails
|
88
|
+
proxy_set_header X-Real-IP $remote_addr;
|
89
|
+
|
90
|
+
# needed for HTTPS
|
91
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
92
|
+
proxy_set_header Host $http_host;
|
93
|
+
proxy_redirect off;
|
94
|
+
proxy_max_temp_file_size 0;
|
95
|
+
|
96
|
+
# If the file exists as a static file serve it directly without
|
97
|
+
# running all the other rewite tests on it
|
98
|
+
if (-f $request_filename) {
|
99
|
+
break;
|
100
|
+
}
|
101
|
+
|
102
|
+
# check for index.html for directory index
|
103
|
+
# if its there on the filesystem then rewite
|
104
|
+
# the url to add /index.html to the end of it
|
105
|
+
# and then break to send it to the next config rules.
|
106
|
+
if (-f $request_filename/index.html) {
|
107
|
+
rewrite (.*) $1/index.html break;
|
108
|
+
}
|
109
|
+
|
110
|
+
# this is the meat of the rails page caching config
|
111
|
+
# it adds .html to the end of the url and then checks
|
112
|
+
# the filesystem for that file. If it exists, then we
|
113
|
+
# rewite the url to have explicit .html on the end
|
114
|
+
# and then send it on its way to the next config rule.
|
115
|
+
# if there is no file on the fs then it sets all the
|
116
|
+
# necessary headers and proxies to our upstream mongrels
|
117
|
+
if (-f $request_filename.html) {
|
118
|
+
rewrite (.*) $1.html break;
|
119
|
+
}
|
120
|
+
|
121
|
+
if (!-f $request_filename) {
|
122
|
+
proxy_pass http://mongrel;
|
123
|
+
break;
|
124
|
+
}
|
125
|
+
}
|
126
|
+
|
127
|
+
error_page 500 502 503 504 /500.html;
|
128
|
+
location = /500.html {
|
129
|
+
root <%= deploy_to %>/current/public;
|
130
|
+
}
|
131
|
+
}
|
132
|
+
}
|
data/obs-recipes.gemspec
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = %q{obs-recipes}
|
3
|
+
s.version = "0.5.0"
|
4
|
+
|
5
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
6
|
+
s.authors = ["Alexander Petrov"]
|
7
|
+
s.date = %q{2009-10-01}
|
8
|
+
s.description = %q{Extend the Capistrano gem with these useful recipes}
|
9
|
+
s.email = %q{apetrov@obsgroup.biz}
|
10
|
+
s.extra_rdoc_files = []
|
11
|
+
s.files = [
|
12
|
+
"Rakefile",
|
13
|
+
"VERSION.yml",
|
14
|
+
"obs-recipes.gemspec",
|
15
|
+
"lib/obs_recipes.rb",
|
16
|
+
"lib/helpers.rb",
|
17
|
+
"lib/recipes/monit.rb",
|
18
|
+
"lib/recipes/nginx.rb",
|
19
|
+
"lib/recipes/rails.rb",
|
20
|
+
"lib/templates/monit/global.erb",
|
21
|
+
"lib/templates/monit/mongrels.erb",
|
22
|
+
"lib/templates/monit/mysql.erb",
|
23
|
+
"lib/templates/monit/nginx.erb",
|
24
|
+
"lib/templates/monit/sshd.erb",
|
25
|
+
"lib/templates/nginx.erb",
|
26
|
+
"lib/templates/database.yml.erb"
|
27
|
+
]
|
28
|
+
s.homepage = %q{http://github.com/apetrov/obs-recipes}
|
29
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
30
|
+
s.require_paths = ["lib"]
|
31
|
+
s.rubygems_version = %q{1.3.1}
|
32
|
+
s.summary = %q{OBS Capistrano recipes}
|
33
|
+
|
34
|
+
if s.respond_to? :specification_version then
|
35
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
36
|
+
s.specification_version = 3
|
37
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
38
|
+
s.add_runtime_dependency(%q<capistrano>, [">= 2.5.5"])
|
39
|
+
else
|
40
|
+
s.add_dependency(%q<capistrano>, [">= 2.5.5"])
|
41
|
+
end
|
42
|
+
else
|
43
|
+
s.add_dependency(%q<capistrano>, [">= 2.5.5"])
|
44
|
+
end
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: obs-recipes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexander Petrov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-01 00:00:00 +04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: capistrano
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.5.5
|
24
|
+
version:
|
25
|
+
description: Extend the Capistrano gem with these useful recipes
|
26
|
+
email: apetrov@obsgroup.biz
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files: []
|
32
|
+
|
33
|
+
files:
|
34
|
+
- Rakefile
|
35
|
+
- VERSION.yml
|
36
|
+
- obs-recipes.gemspec
|
37
|
+
- lib/obs_recipes.rb
|
38
|
+
- lib/helpers.rb
|
39
|
+
- lib/recipes/monit.rb
|
40
|
+
- lib/recipes/nginx.rb
|
41
|
+
- lib/recipes/rails.rb
|
42
|
+
- lib/templates/monit/global.erb
|
43
|
+
- lib/templates/monit/mongrels.erb
|
44
|
+
- lib/templates/monit/mysql.erb
|
45
|
+
- lib/templates/monit/nginx.erb
|
46
|
+
- lib/templates/monit/sshd.erb
|
47
|
+
- lib/templates/nginx.erb
|
48
|
+
- lib/templates/database.yml.erb
|
49
|
+
has_rdoc: true
|
50
|
+
homepage: http://github.com/apetrov/obs-recipes
|
51
|
+
licenses: []
|
52
|
+
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options:
|
55
|
+
- --charset=UTF-8
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
version:
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
version:
|
70
|
+
requirements: []
|
71
|
+
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 1.3.5
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: OBS Capistrano recipes
|
77
|
+
test_files: []
|
78
|
+
|