Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
490 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,6 @@ | |||
default.bluepill[:bin] = languages[:ruby][:bin_dir] + "/bluepill" | |||
default.bluepill[:config_dir] = "/etc/bluepill" | |||
default.bluepill[:log_dir] = "/var/log/bluepill" | |||
default.bluepill[:pid_dir] = "/var/run/bluepill" | |||
|
|||
bluepill[:version] = "0.0.51" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,21 @@ | |||
define :bluepill_monitor, :enable => true, :rack_config_path => false do | |||
include_recipe "bluepill" | |||
config_path = "#{node[:bluepill][:config_dir]}/#{params[:name]}.conf.rb" | |||
|
|||
execute "load-bluepill-#{params[:name]}" do | |||
command "bluepill load #{node[:bluepill][:config_dir]}/#{params[:name]}.conf.rb" | |||
action :nothing | |||
end | |||
|
|||
execute "restart-bluepill-#{params[:name]}" do | |||
command "bluepill restart #{params[:name]}" | |||
action :nothing | |||
end | |||
|
|||
template config_path do | |||
source params[:source] || "bluepill_#{params[:name]}.conf.erb" | |||
cookbook params[:cookbook] | |||
variables params[:variables] || params | |||
notifies :run, resources("execute[load-bluepill-#{params[:name]}]") | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,22 @@ | |||
define :bluepill_service, :enable => true, :rack_config_path => false do | |||
include_recipe "bluepill" | |||
config_path = "#{node[:bluepill][:config_dir]}/#{params[:name]}.conf.rb" | |||
|
|||
service params[:name] | |||
|
|||
link "/etc/init.d/#{params[:name]}" do | |||
to node[:bluepill][:bin] | |||
end | |||
|
|||
service params[:name] do | |||
supports :restart => true, :status => true, :load => true | |||
action :nothing | |||
end | |||
|
|||
template config_path do | |||
source params[:source] || "bluepill_#{params[:name]}.conf.erb" | |||
cookbook params[:cookbook] | |||
variables params | |||
notifies :load, resources(:service => params[:name]) | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
maintainer "Joshua Sierles" | |||
maintainer_email "joshua@diluvia.net" | |||
description "Installs bluepill and provides definitions and templates for monitoring" | |||
version "0.8" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,27 @@ | |||
gem_package "bluepill" do | |||
version node[:bluepill][:version] | |||
end | |||
|
|||
directory node[:bluepill][:config_dir] do | |||
owner "root" | |||
group "root" | |||
end | |||
|
|||
directory node[:bluepill][:log_dir] do | |||
owner "root" | |||
group "root" | |||
end | |||
|
|||
directory node[:bluepill][:pid_dir] do | |||
owner "root" | |||
group "root" | |||
end | |||
|
|||
template "/etc/init.d/bluepill" do | |||
source "init.sh.erb" | |||
mode 0755 | |||
end | |||
|
|||
service "bluepill" do | |||
action [:enable, :start] | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,35 @@ | |||
#!/bin/sh | |||
|
|||
### BEGIN INIT INFO | |||
# Provides: bluepill | |||
# Required-Start: | |||
# Required-Stop: | |||
# Default-Start: 2 3 4 5 | |||
# Default-Stop: 1 | |||
# Short-Description: Bluepill initializer | |||
### END INIT INFO | |||
|
|||
. /lib/lsb/init-functions | |||
|
|||
case "$1" in | |||
start) | |||
log_daemon_msg "Starting bluepill services" | |||
for i in <%= @node[:bluepill][:config_dir] %>/*conf.rb; do | |||
<%= @node[:languages][:ruby][:bin_dir] %>/bluepill load $i | |||
done | |||
log_end_msg 0 | |||
;; | |||
stop) | |||
echo "Stop is not implemented, since bluepill processes are run independently." | |||
;; | |||
restart) | |||
for i in <%= @node[:bluepill][:config_dir] %>/*conf.rb; do | |||
<%= @node[:languages][:ruby][:bin_dir] %>/bluepill load $i | |||
done | |||
;; | |||
*) | |||
log_action_msg "Usage: /etc/init.d/bluepill start" | |||
exit | |||
esac | |||
|
|||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,9 @@ | |||
define :logrotate, :frequency => "daily", :rotate_count => 5, :rotate_if_empty => false, :missing_ok => true, :compress => true, :enable => true do | |||
template "/etc/logrotate.d/#{params[:name]}" do | |||
action :delete unless params[:enable] | |||
cookbook "logrotate" | |||
source "logrotate.conf.erb" | |||
variables(:p => params) | |||
backup 0 | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
maintainer "Joshua Sierles" | |||
maintainer_email "joshua@diluvia.net" | |||
description "Configures logrotate" | |||
version "0.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
package "logrotate" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,23 @@ | |||
<%= @p[:files].to_a.join("\n") %> { | |||
<% if @p[:size_limit] %> | |||
size <%= @p[:size_limit] %> | |||
<% else %> | |||
<%= @p[:frequency] %> | |||
<% end %> | |||
rotate <%= @p[:rotate_count] %> | |||
<% if @p[:compress] %> | |||
dateext | |||
compress | |||
<% end %> | |||
<% if @p[:missing_ok] %> | |||
missingok | |||
<% end %> | |||
<% %> | |||
<% if !@p[:rotate_if_empty] %> | |||
notifempty | |||
<% end %> | |||
sharedscripts | |||
postrotate | |||
<%= @p[:restart_command] %> | |||
endscript | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
rails Mash.new unless attribute?("rails") | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,6 @@ | |||
default[:rails][:asset_environment] = "production" | |||
default[:rails][:worker_count] = 8 | |||
default[:rails][:app_server] = "unicorn" | |||
default[:rails][:memory_limit] = '400' # megabytes | |||
default[:rails][:monitor_interval] = '30' # seconds | |||
default[:rails][:cpu_limit] = '50' # percent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,35 @@ | |||
require 'fileutils' | |||
|
|||
verbose = false | |||
|
|||
from = ARGV.shift or abort "need source directory" | |||
to = ARGV.shift or abort "need target directory" | |||
|
|||
exclude = ARGV | |||
|
|||
from = File.expand_path(from) | |||
to = File.expand_path(to) | |||
|
|||
Dir.chdir(from) do | |||
FileUtils.mkdir_p(to) | |||
queue = Dir.glob("*", File::FNM_DOTMATCH) | |||
while queue.any? | |||
item = queue.shift | |||
name = File.basename(item) | |||
|
|||
next if name == "." || name == ".." | |||
next if exclude.any? { |pattern| File.fnmatch(pattern, item) } | |||
|
|||
source = File.join(from, item) | |||
target = File.join(to, item) | |||
|
|||
if File.symlink?(item) | |||
FileUtils.ln_s(File.readlink(source), target) | |||
elsif File.directory?(item) | |||
queue += Dir.glob("#{item}/*", File::FNM_DOTMATCH) | |||
FileUtils.mkdir_p(target, :mode => File.stat(item).mode) | |||
else | |||
FileUtils.ln(source, target) | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
#!/bin/bash | |||
exec ssh -oStrictHostKeyChecking=no -i /local/app/.ssh/id_rsa $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,10 @@ | |||
maintainer "Joshua Sierles" | |||
maintainer_email "joshua@diluvia.net" | |||
description "Configures rails apps" | |||
version "0.2" | |||
depends "users" | |||
depends "unicorn" | |||
depends "logrotate" | |||
depends "bluepill" | |||
depends "ssl_certificates" | |||
depends "bundler" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,54 @@ | |||
if node[:active_applications] | |||
|
|||
directory "/u/apps" do | |||
owner "app" | |||
group "app" | |||
mode 0755 | |||
end | |||
|
|||
node[:active_applications].each do |name, conf| | |||
|
|||
app = search(:apps, "id:#{conf[:app_name] || name}").first | |||
app_name = name | |||
app_root = "/u/apps/#{app_name}" | |||
|
|||
%w(config tmp sockets log pids system bin).each do |dir| | |||
directory "/u/apps/#{app_name}/shared/#{dir}" do | |||
recursive true | |||
owner "app" | |||
group "app" | |||
end | |||
end | |||
|
|||
if app | |||
|
|||
if app[:packages] | |||
app[:packages].each do |package_name| | |||
package package_name | |||
end | |||
end | |||
|
|||
if app[:gems] | |||
app[:gems].each do |g| | |||
if g.is_a? Array | |||
gem_package g.first do | |||
version g.last | |||
end | |||
else | |||
gem_package g | |||
end | |||
end | |||
end | |||
|
|||
if app[:symlinks] | |||
app[:symlinks].each do |target, source| | |||
link target do | |||
to source | |||
end | |||
end | |||
end | |||
end | |||
end | |||
else | |||
Chef::Log.info "Add an :active_applications attribute to configure this node's Rails apps" | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,45 @@ | |||
require_recipe "nginx" | |||
require_recipe "rails::app_dependencies" | |||
require_recipe "unicorn" | |||
require_recipe "bluepill" | |||
require_recipe "users" | |||
|
|||
node[:active_applications].each do |name, conf| | |||
|
|||
app = search(:apps, "id:#{conf[:app_name] || name}").first | |||
|
|||
app_name = name | |||
app_root = "/u/apps/#{name}" | |||
|
|||
full_name = "#{app_name}_#{conf[:env]}" | |||
filename = "#{filename}_#{conf[:env]}.conf" | |||
|
|||
template "/etc/nginx/sites-available/#{full_name}" do | |||
source "app_nginx.conf.erb" | |||
variables :full_name => full_name, :app => app, :conf => conf, :app_name => app_name | |||
notifies :reload, resources(:service => "nginx") | |||
end | |||
|
|||
bluepill_monitor full_name do | |||
source "bluepill_unicorn.conf.erb" | |||
app_root "#{app_root}/current" | |||
preload app[:preload] || true | |||
env conf[:env] | |||
interval node[:rails][:monitor_interval] | |||
user "app" | |||
group "app" | |||
memory_limit app[:memory_limit] || node[:rails][:memory_limit] | |||
cpu_limit app[:cpu_limit] || node[:rails][:cpu_limit] | |||
end | |||
|
|||
nginx_site full_name | |||
|
|||
logrotate full_name do | |||
files "/u/apps/#{app_name}/current/log/*.log" | |||
frequency "daily" | |||
rotate_count 14 | |||
compress true | |||
restart_command "/etc/init.d/nginx reload > /dev/null" | |||
end | |||
|
|||
end |
Oops, something went wrong.